git-gui: Toggle between new commit and amend commit modes.
I was starting to find it annoying that once you entered the 'Amend Last' mode there was no way to go back to the 'New Commit' mode without quitting and restarting git-gui. Its just confusing for the end-user. Now we can flip back and forth between a new commit and an amend commit through a pair of radio buttons on the header of the commit buffer area and through a pair of radio menu buttons in the Commit menu. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce committed
Nov 18, 2006 at 20:59 UTC
24ac9b752d6df7ab309826d487fbeaae53806025
1 file changed
+79
-18
git-gui
+79
-18
@@ -722,6 +722,16 @@ proc load_last_commit {} {
722
rescan {set ui_status_value {Ready.}}
723
}
724
725
+proc create_new_commit {} {
726
+ global commit_type ui_comm
727
+
728
+ set commit_type normal
729
+ $ui_comm delete 0.0 end
730
+ $ui_comm edit modified false
731
+ $ui_comm edit reset
732
+ rescan {set ui_status_value {Ready.}}
733
+}
734
+
735
proc commit_tree {} {
736
global HEAD commit_type file_states ui_comm repo_config
737
@@ -880,7 +890,7 @@ proc commit_writetree {curHEAD msg} {
890
891
proc commit_committree {fd_wt curHEAD msg} {
892
global single_commit gitdir HEAD PARENT commit_type tcl_platform
883
- global ui_status_value ui_comm
893
+ global ui_status_value ui_comm selected_commit_type
894
global file_states selected_paths
895
896
gets $fd_wt tree_id
@@ -980,6 +990,7 @@ proc commit_committree {fd_wt curHEAD msg} {
990
# -- Update status without invoking any git commands.
991
#
992
set commit_type normal
993
+ set selected_commit_type new
994
set HEAD $cmt_id
995
set PARENT $cmt_id
996
@@ -1065,13 +1076,14 @@ Commit or throw away all changes before starting a pull operation.
1076
}
1077
1078
proc post_pull_remote {remote branch success} {
1068
- global HEAD PARENT commit_type
1079
+ global HEAD PARENT commit_type selected_commit_type
1080
global ui_status_value
1081
1082
unlock_index
1083
if {$success} {
1084
repository_state HEAD commit_type
1085
set PARENT $HEAD
1086
+ set selected_commit_type new
1087
set $ui_status_value "Pulling $branch from $remote complete."
1088
} else {
1089
set m "Conflicts detected while pulling $branch from $remote."
@@ -1930,8 +1942,22 @@ proc do_signoff {} {
1942
}
1943
}
1944
1933
-proc do_amend_last {} {
1934
- load_last_commit
1945
+proc do_select_commit_type {} {
1946
+ global commit_type selected_commit_type
1947
+
1948
+ if {$selected_commit_type eq {new}
1949
+ && [string match amend* $commit_type]} {
1950
+ create_new_commit
1951
+ } elseif {$selected_commit_type eq {amend}
1952
+ && ![string match amend* $commit_type]} {
1953
+ load_last_commit
1954
+
1955
+ # The amend request was rejected...
1956
+ #
1957
+ if {![string match amend* $commit_type]} {
1958
+ set commit_type new
1959
+ }
1960
+ }
1961
}
1962
1963
proc do_commit {} {
@@ -2450,32 +2476,52 @@ menu .mbar.edit
2476
# -- Commit Menu
2477
#
2478
menu .mbar.commit
2453
-.mbar.commit add command -label Rescan \
2454
- -command do_rescan \
2455
- -accelerator F5 \
2479
+
2480
+.mbar.commit add radiobutton \
2481
+ -label {New Commit} \
2482
+ -command do_select_commit_type \
2483
+ -variable selected_commit_type \
2484
+ -value new \
2485
+ -font font_ui
2486
+lappend disable_on_lock \
2487
+ [list .mbar.commit entryconf [.mbar.commit index last] -state]
2488
+
2489
+.mbar.commit add radiobutton \
2490
+ -label {Amend Last Commit} \
2491
+ -command do_select_commit_type \
2492
+ -variable selected_commit_type \
2493
+ -value amend \
2494
-font font_ui
2495
lappend disable_on_lock \
2496
[list .mbar.commit entryconf [.mbar.commit index last] -state]
2459
-.mbar.commit add command -label {Amend Last Commit} \
2460
- -command do_amend_last \
2497
+
2498
+.mbar.commit add separator
2499
+
2500
+.mbar.commit add command -label Rescan \
2501
+ -command do_rescan \
2502
+ -accelerator F5 \
2503
-font font_ui
2504
lappend disable_on_lock \
2505
[list .mbar.commit entryconf [.mbar.commit index last] -state]
2506
+
2507
.mbar.commit add command -label {Include Selected Files} \
2508
-command do_include_selection \
2509
-font font_ui
2510
lappend disable_on_lock \
2511
[list .mbar.commit entryconf [.mbar.commit index last] -state]
2512
+
2513
.mbar.commit add command -label {Include All Files} \
2514
-command do_include_all \
2515
-accelerator $M1T-I \
2516
-font font_ui
2517
lappend disable_on_lock \
2518
[list .mbar.commit entryconf [.mbar.commit index last] -state]
2519
+
2520
.mbar.commit add command -label {Sign Off} \
2521
-command do_signoff \
2522
-accelerator $M1T-S \
2523
-font font_ui
2524
+
2525
.mbar.commit add command -label Commit \
2526
-command do_commit \
2527
-accelerator $M1T-Return \
@@ -2568,13 +2614,6 @@ pack .vpane.lower.commarea.buttons.rescan -side top -fill x
2614
lappend disable_on_lock \
2615
{.vpane.lower.commarea.buttons.rescan conf -state}
2616
2571
-button .vpane.lower.commarea.buttons.amend -text {Amend Last} \
2572
- -command do_amend_last \
2573
- -font font_ui
2574
-pack .vpane.lower.commarea.buttons.amend -side top -fill x
2575
-lappend disable_on_lock \
2576
- {.vpane.lower.commarea.buttons.amend conf -state}
2577
-
2617
button .vpane.lower.commarea.buttons.incall -text {Include All} \
2618
-command do_include_all \
2619
-font font_ui
@@ -2597,8 +2636,25 @@ lappend disable_on_lock \
2636
# -- Commit Message Buffer
2637
#
2638
frame .vpane.lower.commarea.buffer
2639
+frame .vpane.lower.commarea.buffer.header
2640
set ui_comm .vpane.lower.commarea.buffer.t
2601
-set ui_coml .vpane.lower.commarea.buffer.l
2641
+set ui_coml .vpane.lower.commarea.buffer.header.l
2642
+radiobutton .vpane.lower.commarea.buffer.header.new \
2643
+ -text {New Commit} \
2644
+ -command do_select_commit_type \
2645
+ -variable selected_commit_type \
2646
+ -value new \
2647
+ -font font_ui
2648
+lappend disable_on_lock \
2649
+ [list .vpane.lower.commarea.buffer.header.new conf -state]
2650
+radiobutton .vpane.lower.commarea.buffer.header.amend \
2651
+ -text {Amend Last Commit} \
2652
+ -command do_select_commit_type \
2653
+ -variable selected_commit_type \
2654
+ -value amend \
2655
+ -font font_ui
2656
+lappend disable_on_lock \
2657
+ [list .vpane.lower.commarea.buffer.header.amend conf -state]
2658
label $ui_coml \
2659
-anchor w \
2660
-justify left \
@@ -2615,6 +2671,10 @@ proc trace_commit_type {varname args} {
2671
$ui_coml conf -text $txt
2672
}
2673
trace add variable commit_type write trace_commit_type
2674
+pack $ui_coml -side left -fill x
2675
+pack .vpane.lower.commarea.buffer.header.amend -side right
2676
+pack .vpane.lower.commarea.buffer.header.new -side right
2677
+
2678
text $ui_comm -background white -borderwidth 1 \
2679
-undo true \
2680
-maxundo 20 \
@@ -2625,7 +2685,7 @@ text $ui_comm -background white -borderwidth 1 \
2685
-yscrollcommand {.vpane.lower.commarea.buffer.sby set}
2686
scrollbar .vpane.lower.commarea.buffer.sby \
2687
-command [list $ui_comm yview]
2628
-pack $ui_coml -side top -fill x
2688
+pack .vpane.lower.commarea.buffer.header -side top -fill x
2689
pack .vpane.lower.commarea.buffer.sby -side right -fill y
2690
pack $ui_comm -side left -fill y
2691
pack .vpane.lower.commarea.buffer -side left -fill y
@@ -2897,6 +2957,7 @@ set PARENT {}
2957
set commit_type {}
2958
set empty_tree {}
2959
set current_diff {}
2960
+set selected_commit_type new
2961
2962
wm title . "$appname ([file normalize [file dirname $gitdir]])"
2963
focus -force $ui_comm