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>
This commit is contained in:

committed by
Shawn O. Pearce

parent
146ed90f02
commit
1e65c6225d
81
git-gui.sh
81
git-gui.sh
@ -948,10 +948,32 @@ blame {
|
|||||||
}
|
}
|
||||||
citool {
|
citool {
|
||||||
enable_option singlecommit
|
enable_option singlecommit
|
||||||
|
enable_option retcode
|
||||||
|
|
||||||
disable_option multicommit
|
disable_option multicommit
|
||||||
disable_option branch
|
disable_option branch
|
||||||
disable_option transport
|
disable_option transport
|
||||||
|
|
||||||
|
while {[llength $argv] > 0} {
|
||||||
|
set a [lindex $argv 0]
|
||||||
|
switch -- $a {
|
||||||
|
--amend {
|
||||||
|
enable_option initialamend
|
||||||
|
}
|
||||||
|
--nocommit {
|
||||||
|
enable_option nocommit
|
||||||
|
enable_option nocommitmsg
|
||||||
|
}
|
||||||
|
--commitmsg {
|
||||||
|
disable_option nocommitmsg
|
||||||
|
}
|
||||||
|
default {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
set argv [lrange $argv 1 end]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1108,6 +1130,20 @@ proc PARENT {} {
|
|||||||
return $empty_tree
|
return $empty_tree
|
||||||
}
|
}
|
||||||
|
|
||||||
|
proc force_amend {} {
|
||||||
|
global selected_commit_type
|
||||||
|
global HEAD PARENT MERGE_HEAD commit_type
|
||||||
|
|
||||||
|
repository_state newType newHEAD newMERGE_HEAD
|
||||||
|
set HEAD $newHEAD
|
||||||
|
set PARENT $newHEAD
|
||||||
|
set MERGE_HEAD $newMERGE_HEAD
|
||||||
|
set commit_type $newType
|
||||||
|
|
||||||
|
set selected_commit_type amend
|
||||||
|
do_select_commit_type
|
||||||
|
}
|
||||||
|
|
||||||
proc rescan {after {honor_trustmtime 1}} {
|
proc rescan {after {honor_trustmtime 1}} {
|
||||||
global HEAD PARENT MERGE_HEAD commit_type
|
global HEAD PARENT MERGE_HEAD commit_type
|
||||||
global ui_index ui_workdir ui_comm
|
global ui_index ui_workdir ui_comm
|
||||||
@ -1754,11 +1790,19 @@ proc do_gitk {revs} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
set is_quitting 0
|
set is_quitting 0
|
||||||
|
set ret_code 1
|
||||||
|
|
||||||
proc do_quit {} {
|
proc terminate_me {win} {
|
||||||
|
global ret_code
|
||||||
|
if {$win ne {.}} return
|
||||||
|
exit $ret_code
|
||||||
|
}
|
||||||
|
|
||||||
|
proc do_quit {{rc {1}}} {
|
||||||
global ui_comm is_quitting repo_config commit_type
|
global ui_comm is_quitting repo_config commit_type
|
||||||
global GITGUI_BCK_exists GITGUI_BCK_i
|
global GITGUI_BCK_exists GITGUI_BCK_i
|
||||||
global ui_comm_spell
|
global ui_comm_spell
|
||||||
|
global ret_code
|
||||||
|
|
||||||
if {$is_quitting} return
|
if {$is_quitting} return
|
||||||
set is_quitting 1
|
set is_quitting 1
|
||||||
@ -1813,6 +1857,7 @@ proc do_quit {} {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set ret_code $rc
|
||||||
destroy .
|
destroy .
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2215,6 +2260,14 @@ if {[is_enabled branch]} {
|
|||||||
|
|
||||||
# -- Commit Menu
|
# -- Commit Menu
|
||||||
#
|
#
|
||||||
|
proc commit_btn_caption {} {
|
||||||
|
if {[is_enabled nocommit]} {
|
||||||
|
return [mc "Done"]
|
||||||
|
} else {
|
||||||
|
return [mc Commit@@verb]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if {[is_enabled multicommit] || [is_enabled singlecommit]} {
|
if {[is_enabled multicommit] || [is_enabled singlecommit]} {
|
||||||
menu .mbar.commit
|
menu .mbar.commit
|
||||||
|
|
||||||
@ -2280,7 +2333,7 @@ if {[is_enabled multicommit] || [is_enabled singlecommit]} {
|
|||||||
-command do_signoff \
|
-command do_signoff \
|
||||||
-accelerator $M1T-S
|
-accelerator $M1T-S
|
||||||
|
|
||||||
.mbar.commit add command -label [mc Commit@@verb] \
|
.mbar.commit add command -label [commit_btn_caption] \
|
||||||
-command do_commit \
|
-command do_commit \
|
||||||
-accelerator $M1T-Return
|
-accelerator $M1T-Return
|
||||||
lappend disable_on_lock \
|
lappend disable_on_lock \
|
||||||
@ -2608,7 +2661,7 @@ button .vpane.lower.commarea.buttons.signoff -text [mc "Sign Off"] \
|
|||||||
-command do_signoff
|
-command do_signoff
|
||||||
pack .vpane.lower.commarea.buttons.signoff -side top -fill x
|
pack .vpane.lower.commarea.buttons.signoff -side top -fill x
|
||||||
|
|
||||||
button .vpane.lower.commarea.buttons.commit -text [mc Commit@@verb] \
|
button .vpane.lower.commarea.buttons.commit -text [commit_btn_caption] \
|
||||||
-command do_commit
|
-command do_commit
|
||||||
pack .vpane.lower.commarea.buttons.commit -side top -fill x
|
pack .vpane.lower.commarea.buttons.commit -side top -fill x
|
||||||
lappend disable_on_lock \
|
lappend disable_on_lock \
|
||||||
@ -2618,6 +2671,13 @@ button .vpane.lower.commarea.buttons.push -text [mc Push] \
|
|||||||
-command do_push_anywhere
|
-command do_push_anywhere
|
||||||
pack .vpane.lower.commarea.buttons.push -side top -fill x
|
pack .vpane.lower.commarea.buttons.push -side top -fill x
|
||||||
|
|
||||||
|
if {[is_enabled nocommitmsg]} {
|
||||||
|
.vpane.lower.commarea.buttons.signoff configure -state disabled
|
||||||
|
}
|
||||||
|
if {[is_enabled nocommit]} {
|
||||||
|
.vpane.lower.commarea.buttons.push configure -state disabled
|
||||||
|
}
|
||||||
|
|
||||||
# -- Commit Message Buffer
|
# -- Commit Message Buffer
|
||||||
#
|
#
|
||||||
frame .vpane.lower.commarea.buffer
|
frame .vpane.lower.commarea.buffer
|
||||||
@ -3199,7 +3259,20 @@ lock_index begin-read
|
|||||||
if {![winfo ismapped .]} {
|
if {![winfo ismapped .]} {
|
||||||
wm deiconify .
|
wm deiconify .
|
||||||
}
|
}
|
||||||
after 1 do_rescan
|
after 1 {
|
||||||
|
if {[is_enabled initialamend]} {
|
||||||
|
force_amend
|
||||||
|
} else {
|
||||||
|
do_rescan
|
||||||
|
}
|
||||||
|
|
||||||
|
if {[is_enabled nocommitmsg]} {
|
||||||
|
$ui_comm configure -state disabled -background gray
|
||||||
|
}
|
||||||
|
}
|
||||||
if {[is_enabled multicommit]} {
|
if {[is_enabled multicommit]} {
|
||||||
after 1000 hint_gc
|
after 1000 hint_gc
|
||||||
}
|
}
|
||||||
|
if {[is_enabled retcode]} {
|
||||||
|
bind . <Destroy> {+terminate_me %W}
|
||||||
|
}
|
||||||
|
@ -168,7 +168,7 @@ File %s cannot be committed by this program.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if {!$files_ready && ![string match *merge $curType]} {
|
if {!$files_ready && ![string match *merge $curType] && ![is_enabled nocommit]} {
|
||||||
info_popup [mc "No changes to commit.
|
info_popup [mc "No changes to commit.
|
||||||
|
|
||||||
You must stage at least 1 file before you can commit.
|
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.
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if {[is_enabled nocommitmsg]} { do_quit 0 }
|
||||||
|
|
||||||
# -- A message is required.
|
# -- A message is required.
|
||||||
#
|
#
|
||||||
set msg [string trim [$ui_comm get 1.0 end]]
|
set msg [string trim [$ui_comm get 1.0 end]]
|
||||||
@ -212,6 +214,8 @@ A good commit message has the following format:
|
|||||||
puts $msg_wt $msg
|
puts $msg_wt $msg
|
||||||
close $msg_wt
|
close $msg_wt
|
||||||
|
|
||||||
|
if {[is_enabled nocommit]} { do_quit 0 }
|
||||||
|
|
||||||
# -- Run the pre-commit hook.
|
# -- Run the pre-commit hook.
|
||||||
#
|
#
|
||||||
set fd_ph [githook_read pre-commit]
|
set fd_ph [githook_read pre-commit]
|
||||||
@ -410,7 +414,7 @@ A rescan will be automatically started now.
|
|||||||
set ::GITGUI_BCK_exists 0
|
set ::GITGUI_BCK_exists 0
|
||||||
}
|
}
|
||||||
|
|
||||||
if {[is_enabled singlecommit]} do_quit
|
if {[is_enabled singlecommit]} { do_quit 0 }
|
||||||
|
|
||||||
# -- Update in memory status
|
# -- Update in memory status
|
||||||
#
|
#
|
||||||
|
Reference in New Issue
Block a user