git-gui: Add more integration options to citool.
- Make citool return nonzero exit code if it did not commit. - Add a mode where it does not actually commit and simply exits with zero code. Commit message is either disabled, or simply dumped to GITGUI_EDITMSG before exiting. - Add an option to immediately start it in amend mode. Rationale: 1) Use 'git citool --nocommit' instead of mergetool in scripts. 2) Use 'git citool --amend' to edit commits while rebasing. Signed-off-by: Alexander Gavrilov <angavrilov@gmail.com> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Alexander Gavrilov committed
Sep 12, 2008 at 22:43 UTC
1e65c6225dea2e15df81f6c91927cb0b8fab443c
2 files changed
+83
-6
git-gui.sh
+77
-4
@@ -948,10 +948,32 @@ blame {
948
}
949
citool {
950
enable_option singlecommit
951
+ enable_option retcode
952
953
disable_option multicommit
954
disable_option branch
955
disable_option transport
956
+
957
+ while {[llength $argv] > 0} {
958
+ set a [lindex $argv 0]
959
+ switch -- $a {
960
+ --amend {
961
+ enable_option initialamend
962
+ }
963
+ --nocommit {
964
+ enable_option nocommit
965
+ enable_option nocommitmsg
966
+ }
967
+ --commitmsg {
968
+ disable_option nocommitmsg
969
+ }
970
+ default {
971
+ break
972
+ }
973
+ }
974
+
975
+ set argv [lrange $argv 1 end]
976
+ }
977
}
978
}
979
@@ -1108,6 +1130,20 @@ proc PARENT {} {
1130
return $empty_tree
1131
}
1132
1133
+proc force_amend {} {
1134
+ global selected_commit_type
1135
+ global HEAD PARENT MERGE_HEAD commit_type
1136
+
1137
+ repository_state newType newHEAD newMERGE_HEAD
1138
+ set HEAD $newHEAD
1139
+ set PARENT $newHEAD
1140
+ set MERGE_HEAD $newMERGE_HEAD
1141
+ set commit_type $newType
1142
+
1143
+ set selected_commit_type amend
1144
+ do_select_commit_type
1145
+}
1146
+
1147
proc rescan {after {honor_trustmtime 1}} {
1148
global HEAD PARENT MERGE_HEAD commit_type
1149
global ui_index ui_workdir ui_comm
@@ -1754,11 +1790,19 @@ proc do_gitk {revs} {
1790
}
1791
1792
set is_quitting 0
1793
+set ret_code 1
1794
1758
-proc do_quit {} {
1795
+proc terminate_me {win} {
1796
+ global ret_code
1797
+ if {$win ne {.}} return
1798
+ exit $ret_code
1799
+}
1800
+
1801
+proc do_quit {{rc {1}}} {
1802
global ui_comm is_quitting repo_config commit_type
1803
global GITGUI_BCK_exists GITGUI_BCK_i
1804
global ui_comm_spell
1805
+ global ret_code
1806
1807
if {$is_quitting} return
1808
set is_quitting 1
@@ -1813,6 +1857,7 @@ proc do_quit {} {
1857
}
1858
}
1859
1860
+ set ret_code $rc
1861
destroy .
1862
}
1863
@@ -2215,6 +2260,14 @@ if {[is_enabled branch]} {
2260
2261
# -- Commit Menu
2262
#
2263
+proc commit_btn_caption {} {
2264
+ if {[is_enabled nocommit]} {
2265
+ return [mc "Done"]
2266
+ } else {
2267
+ return [mc Commit@@verb]
2268
+ }
2269
+}
2270
+
2271
if {[is_enabled multicommit] || [is_enabled singlecommit]} {
2272
menu .mbar.commit
2273
@@ -2280,7 +2333,7 @@ if {[is_enabled multicommit] || [is_enabled singlecommit]} {
2333
-command do_signoff \
2334
-accelerator $M1T-S
2335
2283
- .mbar.commit add command -label [mc Commit@@verb] \
2336
+ .mbar.commit add command -label [commit_btn_caption] \
2337
-command do_commit \
2338
-accelerator $M1T-Return
2339
lappend disable_on_lock \
@@ -2608,7 +2661,7 @@ button .vpane.lower.commarea.buttons.signoff -text [mc "Sign Off"] \
2661
-command do_signoff
2662
pack .vpane.lower.commarea.buttons.signoff -side top -fill x
2663
2611
-button .vpane.lower.commarea.buttons.commit -text [mc Commit@@verb] \
2664
+button .vpane.lower.commarea.buttons.commit -text [commit_btn_caption] \
2665
-command do_commit
2666
pack .vpane.lower.commarea.buttons.commit -side top -fill x
2667
lappend disable_on_lock \
@@ -2618,6 +2671,13 @@ button .vpane.lower.commarea.buttons.push -text [mc Push] \
2671
-command do_push_anywhere
2672
pack .vpane.lower.commarea.buttons.push -side top -fill x
2673
2674
+if {[is_enabled nocommitmsg]} {
2675
+ .vpane.lower.commarea.buttons.signoff configure -state disabled
2676
+}
2677
+if {[is_enabled nocommit]} {
2678
+ .vpane.lower.commarea.buttons.push configure -state disabled
2679
+}
2680
+
2681
# -- Commit Message Buffer
2682
#
2683
frame .vpane.lower.commarea.buffer
@@ -3199,7 +3259,20 @@ lock_index begin-read
3259
if {![winfo ismapped .]} {
3260
wm deiconify .
3261
}
3202
-after 1 do_rescan
3262
+after 1 {
3263
+ if {[is_enabled initialamend]} {
3264
+ force_amend
3265
+ } else {
3266
+ do_rescan
3267
+ }
3268
+
3269
+ if {[is_enabled nocommitmsg]} {
3270
+ $ui_comm configure -state disabled -background gray
3271
+ }
3272
+}
3273
if {[is_enabled multicommit]} {
3274
after 1000 hint_gc
3275
}
3276
+if {[is_enabled retcode]} {
3277
+ bind . <Destroy> {+terminate_me %W}
3278
+}
lib/commit.tcl
+6
-2
@@ -168,7 +168,7 @@ File %s cannot be committed by this program.
168
}
169
}
170
}
171
- if {!$files_ready && ![string match *merge $curType]} {
171
+ if {!$files_ready && ![string match *merge $curType] && ![is_enabled nocommit]} {
172
info_popup [mc "No changes to commit.
173
174
You must stage at least 1 file before you can commit.
@@ -177,6 +177,8 @@ You must stage at least 1 file before you can commit.
177
return
178
}
179
180
+ if {[is_enabled nocommitmsg]} { do_quit 0 }
181
+
182
# -- A message is required.
183
#
184
set msg [string trim [$ui_comm get 1.0 end]]
@@ -212,6 +214,8 @@ A good commit message has the following format:
214
puts $msg_wt $msg
215
close $msg_wt
216
217
+ if {[is_enabled nocommit]} { do_quit 0 }
218
+
219
# -- Run the pre-commit hook.
220
#
221
set fd_ph [githook_read pre-commit]
@@ -410,7 +414,7 @@ A rescan will be automatically started now.
414
set ::GITGUI_BCK_exists 0
415
}
416
413
- if {[is_enabled singlecommit]} do_quit
417
+ if {[is_enabled singlecommit]} { do_quit 0 }
418
419
# -- Update in memory status
420
#