git-gui: Add more integration options to citool.
RFC PATCH 1/1 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.
---
I think this functionality might be useful, in particular for some of my own scripts. But I'm not sure if this is the best way to do it.
-- Alexander
git-gui.sh | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- lib/commit.tcl | 8 ++++- 2 files changed, 83 insertions(+), 6 deletions(-)
git-gui.sh +77 -4
@@ -961,10 +961,32 @@ blame { } citool { enable_option singlecommit + enable_option retcode disable_option multicommit disable_option branch 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] + } } }
@@ -1121,6 +1143,20 @@ proc PARENT {} { 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}} { global HEAD PARENT MERGE_HEAD commit_type global ui_index ui_workdir ui_comm
@@ -1767,11 +1803,19 @@ proc do_gitk {revs} { } 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 GITGUI_BCK_exists GITGUI_BCK_i global ui_comm_spell + global ret_code if {$is_quitting} return set is_quitting 1
@@ -1826,6 +1870,7 @@ proc do_quit {} { } } + set ret_code $rc destroy . }
@@ -2228,6 +2273,14 @@ if {[is_enabled branch]} { # -- 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]} { menu .mbar.commit
@@ -2293,7 +2346,7 @@ if {[is_enabled multicommit] || [is_enabled singlecommit]} { -command do_signoff \ -accelerator $M1T-S - .mbar.commit add command -label [mc Commit@@verb] \ + .mbar.commit add command -label [commit_btn_caption] \ -command do_commit \ -accelerator $M1T-Return lappend disable_on_lock \
@@ -2621,7 +2674,7 @@ button .vpane.lower.commarea.buttons.signoff -text [mc "Sign Off"] \ -command do_signoff 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 pack .vpane.lower.commarea.buttons.commit -side top -fill x lappend disable_on_lock \
@@ -2631,6 +2684,13 @@ button .vpane.lower.commarea.buttons.push -text [mc Push] \ -command do_push_anywhere 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 # frame .vpane.lower.commarea.buffer
@@ -3212,7 +3272,20 @@ lock_index begin-read if {![winfo ismapped .]} { 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]} { after 1000 hint_gc } +if {[is_enabled retcode]} { + bind . <Destroy> {+terminate_me %W} +}
lib/commit.tcl +6 -2
@@ -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. 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 } + if {[is_enabled nocommitmsg]} { do_quit 0 } + # -- A message is required. # 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 close $msg_wt + if {[is_enabled nocommit]} { do_quit 0 } + # -- Run the pre-commit hook. # set fd_ph [githook_read pre-commit]
@@ -410,7 +414,7 @@ A rescan will be automatically started now. set ::GITGUI_BCK_exists 0 } - if {[is_enabled singlecommit]} do_quit + if {[is_enabled singlecommit]} { do_quit 0 } # -- Update in memory status #
Signature · 1 line
1.6.0.20.g6148bc
Quoted 5 lines · Alexander Gavrilov
- 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 toGITGUI_EDITMSGbefore exiting.
- Add an option to immediately start it in amend mode.
...
Quoted 2 lines
I think this functionality might be useful, in particular for some of my own scripts. But I'm not sure if this is the best way to do it.
This looks good to me, but I think we may want to add this as a follow-up patch. Thoughts?
--8<--
git-gui: Hide commit related UI during citool --nocommit
If the user started git-gui as "git citool --nocommit" then they don't need the new commit / amend commit radio buttons, or the sign off button in the UI. Rather than use up space with options the user cannot activate they are simply not installed into the UI.
--- git-gui.sh | 104 ++++++++++++++++++++++++++++++++--------------------------- 1 files changed, 56 insertions(+), 48 deletions(-)
git-gui.sh +56 -48
@@ -2271,23 +2271,25 @@ proc commit_btn_caption {} { if {[is_enabled multicommit] || [is_enabled singlecommit]} { menu .mbar.commit - .mbar.commit add radiobutton \ - -label [mc "New Commit"] \ - -command do_select_commit_type \ - -variable selected_commit_type \ - -value new - lappend disable_on_lock \ - [list .mbar.commit entryconf [.mbar.commit index last] -state] - - .mbar.commit add radiobutton \ - -label [mc "Amend Last Commit"] \ - -command do_select_commit_type \ - -variable selected_commit_type \ - -value amend - lappend disable_on_lock \ - [list .mbar.commit entryconf [.mbar.commit index last] -state] - - .mbar.commit add separator + if {![is_enabled nocommit]} { + .mbar.commit add radiobutton \ + -label [mc "New Commit"] \ + -command do_select_commit_type \ + -variable selected_commit_type \ + -value new + lappend disable_on_lock \ + [list .mbar.commit entryconf [.mbar.commit index last] -state] + + .mbar.commit add radiobutton \ + -label [mc "Amend Last Commit"] \ + -command do_select_commit_type \ + -variable selected_commit_type \ + -value amend + lappend disable_on_lock \ + [list .mbar.commit entryconf [.mbar.commit index last] -state] + + .mbar.commit add separator + } .mbar.commit add command -label [mc Rescan] \ -command ui_do_rescan \
@@ -2329,9 +2331,11 @@ if {[is_enabled multicommit] || [is_enabled singlecommit]} { .mbar.commit add separator - .mbar.commit add command -label [mc "Sign Off"] \ - -command do_signoff \ - -accelerator $M1T-S + if {![is_enabled nocommit]} { + .mbar.commit add command -label [mc "Sign Off"] \ + -command do_signoff \ + -accelerator $M1T-S + } .mbar.commit add command -label [commit_btn_caption] \ -command do_commit \
@@ -2657,9 +2661,11 @@ pack .vpane.lower.commarea.buttons.incall -side top -fill x lappend disable_on_lock \ {.vpane.lower.commarea.buttons.incall conf -state} -button .vpane.lower.commarea.buttons.signoff -text [mc "Sign Off"] \ - -command do_signoff -pack .vpane.lower.commarea.buttons.signoff -side top -fill x +if {![is_enabled nocommit]} { + button .vpane.lower.commarea.buttons.signoff -text [mc "Sign Off"] \ + -command do_signoff + pack .vpane.lower.commarea.buttons.signoff -side top -fill x +} button .vpane.lower.commarea.buttons.commit -text [commit_btn_caption] \ -command do_commit
@@ -2667,15 +2673,10 @@ pack .vpane.lower.commarea.buttons.commit -side top -fill x lappend disable_on_lock \ {.vpane.lower.commarea.buttons.commit conf -state} -button .vpane.lower.commarea.buttons.push -text [mc Push] \ - -command do_push_anywhere -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 +if {![is_enabled nocommit]} { + button .vpane.lower.commarea.buttons.push -text [mc Push] \ + -command do_push_anywhere + pack .vpane.lower.commarea.buttons.push -side top -fill x } # -- Commit Message Buffer
@@ -2684,20 +2685,24 @@ frame .vpane.lower.commarea.buffer frame .vpane.lower.commarea.buffer.header set ui_comm .vpane.lower.commarea.buffer.t set ui_coml .vpane.lower.commarea.buffer.header.l -radiobutton .vpane.lower.commarea.buffer.header.new \ - -text [mc "New Commit"] \ - -command do_select_commit_type \ - -variable selected_commit_type \ - -value new -lappend disable_on_lock \ - [list .vpane.lower.commarea.buffer.header.new conf -state] -radiobutton .vpane.lower.commarea.buffer.header.amend \ - -text [mc "Amend Last Commit"] \ - -command do_select_commit_type \ - -variable selected_commit_type \ - -value amend -lappend disable_on_lock \ - [list .vpane.lower.commarea.buffer.header.amend conf -state] + +if {![is_enabled nocommit]} { + radiobutton .vpane.lower.commarea.buffer.header.new \ + -text [mc "New Commit"] \ + -command do_select_commit_type \ + -variable selected_commit_type \ + -value new + lappend disable_on_lock \ + [list .vpane.lower.commarea.buffer.header.new conf -state] + radiobutton .vpane.lower.commarea.buffer.header.amend \ + -text [mc "Amend Last Commit"] \ + -command do_select_commit_type \ + -variable selected_commit_type \ + -value amend + lappend disable_on_lock \ + [list .vpane.lower.commarea.buffer.header.amend conf -state] +} + label $ui_coml \ -anchor w \ -justify left
@@ -2715,8 +2720,11 @@ proc trace_commit_type {varname args} { } trace add variable commit_type write trace_commit_type pack $ui_coml -side left -fill x -pack .vpane.lower.commarea.buffer.header.amend -side right -pack .vpane.lower.commarea.buffer.header.new -side right + +if {![is_enabled nocommit]} { + pack .vpane.lower.commarea.buffer.header.amend -side right + pack .vpane.lower.commarea.buffer.header.new -side right +} text $ui_comm -background white -foreground black \ -borderwidth 1 \
Signature · 6 lines
1.6.0.2.471.g47a76 -- Shawn.
Quoted 16 lines · On Wednesday 24 September 2008 20:52:01 Shawn O. Pearce wrote:
Quoted 5 lines · Alexander Gavrilov
- 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 toGITGUI_EDITMSGbefore exiting.
- Add an option to immediately start it in amend mode....
Quoted 2 lines
I think this functionality might be useful, in particular for some of my own scripts. But I'm not sure if this is the best way to do it.
This looks good to me, but I think we may want to add this as a follow-up patch. Thoughts?
--8<--
git-gui: Hide commit related UI during citool --nocommit
Quoted 7 lines
If the user started git-gui as "git citool --nocommit" then they don't need the new commit / amend commit radio buttons, or the sign off button in the UI. Rather than use up space with options the user cannot activate they are simply not installed into the UI.
Signed-off-by Shawn O. Pearce <[email protected]>---
I believe that the 'Sign Off' button should better be controlled by the nocommitmsg option; otherwise this looks good to me. But I'm not the best thinker at the moment (had a cold).
Alexander
Quoted 8 lines · Alexander Gavrilov
Quoted 3 lines · On Wednesday 24 September 2008 20:52:01 Shawn O. Pearce wrote:
--8<--
git-gui: Hide commit related UI during citool --nocommitI believe that the 'Sign Off' button should better be controlled by the nocommitmsg option; otherwise this looks good to me. But I'm not the best thinker at the moment (had a cold).
Since I've already pushed that patch in both git-gui.git and git.git how is this as a followup?
--8<--
git-gui: Show/hide "Sign Off" based on nocommitmsg option
If citool --nocommit is invoked we hide the Sign Off features, as the commit message area is not editable. But we really want the selection tied to the message area's editing ability.
--- git-gui.sh | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
git-gui.sh +2 -2
@@ -2413,7 +2413,7 @@ if {[is_enabled multicommit] || [is_enabled singlecommit]} { .mbar.commit add separator - if {![is_enabled nocommit]} { + if {![is_enabled nocommitmsg]} { .mbar.commit add command -label [mc "Sign Off"] \ -command do_signoff \ -accelerator $M1T-S
@@ -2743,7 +2743,7 @@ pack .vpane.lower.commarea.buttons.incall -side top -fill x lappend disable_on_lock \ {.vpane.lower.commarea.buttons.incall conf -state} -if {![is_enabled nocommit]} { +if {![is_enabled nocommitmsg]} { button .vpane.lower.commarea.buttons.signoff -text [mc "Sign Off"] \ -command do_signoff pack .vpane.lower.commarea.buttons.signoff -side top -fill x
Signature · 5 lines
1.6.0.2.508.g2bf53a -- Shawn.
Quoted 6 lines · On Friday 26 September 2008 18:45:36 Shawn O. Pearce wrote:
Quoted 5 lines · Alexander Gavrilov
Quoted 3 lines · On Wednesday 24 September 2008 20:52:01 Shawn O. Pearce wrote:
--8<--
git-gui: Hide commit related UI during citool --nocommit
Quoted 6 lines
Quoted 3 lines
I believe that the 'Sign Off' button should better be controlled by the nocommitmsg option; otherwise this looks good to me. But I'm not the best thinker at the moment (had a cold).
Since I've already pushed that patch in both git-gui.git and git.git how is this as a followup?
Yes, it does what I was thinking of.
Quoted 39 lines
--8<--
git-gui: Show/hide "Sign Off" based on nocommitmsg optionIf citool --nocommit is invoked we hide the Sign Off features, as the commit message area is not editable. But we really want the selection tied to the message area's editing ability.
Suggested-by Alexander Gavrilov <[email protected]>Signed-off-by Shawn O. Pearce <[email protected]>--- git-gui.sh | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)git-gui.sh +2
-2@@ -2413,7 +2413,7 @@ if {[is_enabled multicommit] || [is_enabled singlecommit]} { .mbar.commit add separator - if {![is_enabled nocommit]} { + if {![is_enabled nocommitmsg]} { .mbar.commit add command -label [mc "Sign Off"] \ -command do_signoff \ -accelerator $M1T-S@@ -2743,7 +2743,7 @@ pack .vpane.lower.commarea.buttons.incall -side top -fill x lappend disable_on_lock \ {.vpane.lower.commarea.buttons.incall conf -state} -if {![is_enabled nocommit]} { +if {![is_enabled nocommitmsg]} { button .vpane.lower.commarea.buttons.signoff -text [mc "Sign Off"] \ -command do_signoff pack .vpane.lower.commarea.buttons.signoff -side top -fill xSignature · 1 line
1.6.0.2.508.g2bf53a