Skip to content

Commit 7e1976e

Browse files
committed
* 'master' of https://github.com/prati0100/git-gui: git-gui: add hotkey to toggle "Amend Last Commit" git-gui: add horizontal scrollbar to commit buffer git-gui: convert new/amend commit radiobutton to checkbutton git-gui: add hotkeys to set widget focus git-gui: allow undoing last revert git-gui: return early when patch fails to apply git-gui: allow reverting selected hunk git-gui: allow reverting selected lines
2 parents 8a3a681 + f7a8834 commit 7e1976e

File tree

5 files changed

+199
-55
lines changed

5 files changed

+199
-55
lines changed

git-gui/git-gui.sh

Lines changed: 109 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,15 +1340,17 @@ set HEAD {}
13401340
set PARENT {}
13411341
set MERGE_HEAD [list]
13421342
set commit_type {}
1343+
set commit_type_is_amend 0
13431344
set empty_tree {}
13441345
set current_branch {}
13451346
set is_detached 0
13461347
set current_diff_path {}
13471348
set is_3way_diff 0
13481349
set is_submodule_diff 0
13491350
set is_conflict_diff 0
1350-
set selected_commit_type new
13511351
set diff_empty_count 0
1352+
set last_revert {}
1353+
set last_revert_enc {}
13521354
13531355
set nullid "0000000000000000000000000000000000000000"
13541356
set nullid2 "0000000000000000000000000000000000000001"
@@ -1434,7 +1436,7 @@ proc PARENT {} {
14341436
}
14351437
14361438
proc force_amend {} {
1437-
global selected_commit_type
1439+
global commit_type_is_amend
14381440
global HEAD PARENT MERGE_HEAD commit_type
14391441
14401442
repository_state newType newHEAD newMERGE_HEAD
@@ -1443,7 +1445,7 @@ proc force_amend {} {
14431445
set MERGE_HEAD $newMERGE_HEAD
14441446
set commit_type $newType
14451447
1446-
set selected_commit_type amend
1448+
set commit_type_is_amend 1
14471449
do_select_commit_type
14481450
}
14491451
@@ -2494,7 +2496,7 @@ proc force_first_diff {after} {
24942496
24952497
proc toggle_or_diff {mode w args} {
24962498
global file_states file_lists current_diff_path ui_index ui_workdir
2497-
global last_clicked selected_paths
2499+
global last_clicked selected_paths file_lists_last_clicked
24982500
24992501
if {$mode eq "click"} {
25002502
foreach {x y} $args break
@@ -2551,6 +2553,8 @@ proc toggle_or_diff {mode w args} {
25512553
$ui_index tag remove in_sel 0.0 end
25522554
$ui_workdir tag remove in_sel 0.0 end
25532555
2556+
set file_lists_last_clicked($w) $path
2557+
25542558
# Determine the state of the file
25552559
if {[info exists file_states($path)]} {
25562560
set state [lindex $file_states($path) 0]
@@ -2664,6 +2668,32 @@ proc show_less_context {} {
26642668
}
26652669
}
26662670
2671+
proc focus_widget {widget} {
2672+
global file_lists last_clicked selected_paths
2673+
global file_lists_last_clicked
2674+
2675+
if {[llength $file_lists($widget)] > 0} {
2676+
set path $file_lists_last_clicked($widget)
2677+
set index [lsearch -sorted -exact $file_lists($widget) $path]
2678+
if {$index < 0} {
2679+
set index 0
2680+
set path [lindex $file_lists($widget) $index]
2681+
}
2682+
2683+
focus $widget
2684+
set last_clicked [list $widget [expr $index + 1]]
2685+
array unset selected_paths
2686+
set selected_paths($path) 1
2687+
show_diff $path $widget
2688+
}
2689+
}
2690+
2691+
proc toggle_commit_type {} {
2692+
global commit_type_is_amend
2693+
set commit_type_is_amend [expr !$commit_type_is_amend]
2694+
do_select_commit_type
2695+
}
2696+
26672697
######################################################################
26682698
##
26692699
## ui construction
@@ -2852,19 +2882,11 @@ if {[is_enabled multicommit] || [is_enabled singlecommit]} {
28522882
menu .mbar.commit
28532883
28542884
if {![is_enabled nocommit]} {
2855-
.mbar.commit add radiobutton \
2856-
-label [mc "New Commit"] \
2857-
-command do_select_commit_type \
2858-
-variable selected_commit_type \
2859-
-value new
2860-
lappend disable_on_lock \
2861-
[list .mbar.commit entryconf [.mbar.commit index last] -state]
2862-
2863-
.mbar.commit add radiobutton \
2885+
.mbar.commit add checkbutton \
28642886
-label [mc "Amend Last Commit"] \
2865-
-command do_select_commit_type \
2866-
-variable selected_commit_type \
2867-
-value amend
2887+
-accelerator $M1T-E \
2888+
-variable commit_type_is_amend \
2889+
-command do_select_commit_type
28682890
lappend disable_on_lock \
28692891
[list .mbar.commit entryconf [.mbar.commit index last] -state]
28702892
@@ -3352,18 +3374,10 @@ set ui_comm .vpane.lower.commarea.buffer.frame.t
33523374
set ui_coml .vpane.lower.commarea.buffer.header.l
33533375
33543376
if {![is_enabled nocommit]} {
3355-
${NS}::radiobutton .vpane.lower.commarea.buffer.header.new \
3356-
-text [mc "New Commit"] \
3357-
-command do_select_commit_type \
3358-
-variable selected_commit_type \
3359-
-value new
3360-
lappend disable_on_lock \
3361-
[list .vpane.lower.commarea.buffer.header.new conf -state]
3362-
${NS}::radiobutton .vpane.lower.commarea.buffer.header.amend \
3377+
${NS}::checkbutton .vpane.lower.commarea.buffer.header.amend \
33633378
-text [mc "Amend Last Commit"] \
3364-
-command do_select_commit_type \
3365-
-variable selected_commit_type \
3366-
-value amend
3379+
-variable commit_type_is_amend \
3380+
-command do_select_commit_type
33673381
lappend disable_on_lock \
33683382
[list .vpane.lower.commarea.buffer.header.amend conf -state]
33693383
}
@@ -3388,7 +3402,6 @@ pack $ui_coml -side left -fill x
33883402
33893403
if {![is_enabled nocommit]} {
33903404
pack .vpane.lower.commarea.buffer.header.amend -side right
3391-
pack .vpane.lower.commarea.buffer.header.new -side right
33923405
}
33933406
33943407
textframe .vpane.lower.commarea.buffer.frame
@@ -3402,10 +3415,16 @@ ttext $ui_comm -background white -foreground black \
34023415
-relief sunken \
34033416
-width $repo_config(gui.commitmsgwidth) -height 9 -wrap none \
34043417
-font font_diff \
3418+
-xscrollcommand {.vpane.lower.commarea.buffer.frame.sbx set} \
34053419
-yscrollcommand {.vpane.lower.commarea.buffer.frame.sby set}
3420+
${NS}::scrollbar .vpane.lower.commarea.buffer.frame.sbx \
3421+
-orient horizontal \
3422+
-command [list $ui_comm xview]
34063423
${NS}::scrollbar .vpane.lower.commarea.buffer.frame.sby \
3424+
-orient vertical \
34073425
-command [list $ui_comm yview]
34083426
3427+
pack .vpane.lower.commarea.buffer.frame.sbx -side bottom -fill x
34093428
pack .vpane.lower.commarea.buffer.frame.sby -side right -fill y
34103429
pack $ui_comm -side left -fill y
34113430
pack .vpane.lower.commarea.buffer.header -side top -fill x
@@ -3621,15 +3640,31 @@ set ctxm .vpane.lower.diff.body.ctxm
36213640
menu $ctxm -tearoff 0
36223641
$ctxm add command \
36233642
-label [mc "Apply/Reverse Hunk"] \
3624-
-command {apply_hunk $cursorX $cursorY}
3643+
-command {apply_or_revert_hunk $cursorX $cursorY 0}
36253644
set ui_diff_applyhunk [$ctxm index last]
36263645
lappend diff_actions [list $ctxm entryconf $ui_diff_applyhunk -state]
36273646
$ctxm add command \
36283647
-label [mc "Apply/Reverse Line"] \
3629-
-command {apply_range_or_line $cursorX $cursorY; do_rescan}
3648+
-command {apply_or_revert_range_or_line $cursorX $cursorY 0; do_rescan}
36303649
set ui_diff_applyline [$ctxm index last]
36313650
lappend diff_actions [list $ctxm entryconf $ui_diff_applyline -state]
36323651
$ctxm add separator
3652+
$ctxm add command \
3653+
-label [mc "Revert Hunk"] \
3654+
-command {apply_or_revert_hunk $cursorX $cursorY 1}
3655+
set ui_diff_reverthunk [$ctxm index last]
3656+
lappend diff_actions [list $ctxm entryconf $ui_diff_reverthunk -state]
3657+
$ctxm add command \
3658+
-label [mc "Revert Line"] \
3659+
-command {apply_or_revert_range_or_line $cursorX $cursorY 1; do_rescan}
3660+
set ui_diff_revertline [$ctxm index last]
3661+
lappend diff_actions [list $ctxm entryconf $ui_diff_revertline -state]
3662+
$ctxm add command \
3663+
-label [mc "Undo Last Revert"] \
3664+
-command {undo_last_revert; do_rescan}
3665+
set ui_diff_undorevert [$ctxm index last]
3666+
lappend diff_actions [list $ctxm entryconf $ui_diff_undorevert -state]
3667+
$ctxm add separator
36333668
$ctxm add command \
36343669
-label [mc "Show Less Context"] \
36353670
-command show_less_context
@@ -3708,7 +3743,7 @@ proc has_textconv {path} {
37083743
}
37093744
37103745
proc popup_diff_menu {ctxm ctxmmg ctxmsm x y X Y} {
3711-
global current_diff_path file_states
3746+
global current_diff_path file_states last_revert
37123747
set ::cursorX $x
37133748
set ::cursorY $y
37143749
if {[info exists file_states($current_diff_path)]} {
@@ -3722,19 +3757,28 @@ proc popup_diff_menu {ctxm ctxmmg ctxmsm x y X Y} {
37223757
tk_popup $ctxmsm $X $Y
37233758
} else {
37243759
set has_range [expr {[$::ui_diff tag nextrange sel 0.0] != {}}]
3760+
set u [mc "Undo Last Revert"]
37253761
if {$::ui_index eq $::current_diff_side} {
37263762
set l [mc "Unstage Hunk From Commit"]
3763+
set h [mc "Revert Hunk"]
3764+
37273765
if {$has_range} {
37283766
set t [mc "Unstage Lines From Commit"]
3767+
set r [mc "Revert Lines"]
37293768
} else {
37303769
set t [mc "Unstage Line From Commit"]
3770+
set r [mc "Revert Line"]
37313771
}
37323772
} else {
37333773
set l [mc "Stage Hunk For Commit"]
3774+
set h [mc "Revert Hunk"]
3775+
37343776
if {$has_range} {
37353777
set t [mc "Stage Lines For Commit"]
3778+
set r [mc "Revert Lines"]
37363779
} else {
37373780
set t [mc "Stage Line For Commit"]
3781+
set r [mc "Revert Line"]
37383782
}
37393783
}
37403784
if {$::is_3way_diff
@@ -3745,11 +3789,35 @@ proc popup_diff_menu {ctxm ctxmmg ctxmsm x y X Y} {
37453789
|| [string match {T?} $state]
37463790
|| [has_textconv $current_diff_path]} {
37473791
set s disabled
3792+
set revert_state disabled
37483793
} else {
37493794
set s normal
3795+
3796+
# Only allow reverting changes in the working tree. If
3797+
# the user wants to revert changes in the index, they
3798+
# need to unstage those first.
3799+
if {$::ui_workdir eq $::current_diff_side} {
3800+
set revert_state normal
3801+
} else {
3802+
set revert_state disabled
3803+
}
3804+
}
3805+
3806+
if {$last_revert eq {}} {
3807+
set undo_state disabled
3808+
} else {
3809+
set undo_state normal
37503810
}
3811+
37513812
$ctxm entryconf $::ui_diff_applyhunk -state $s -label $l
37523813
$ctxm entryconf $::ui_diff_applyline -state $s -label $t
3814+
$ctxm entryconf $::ui_diff_revertline -state $revert_state \
3815+
-label $r
3816+
$ctxm entryconf $::ui_diff_reverthunk -state $revert_state \
3817+
-label $h
3818+
$ctxm entryconf $::ui_diff_undorevert -state $undo_state \
3819+
-label $u
3820+
37533821
tk_popup $ctxm $X $Y
37543822
}
37553823
}
@@ -3876,6 +3944,8 @@ bind . <$M1B-Key-j> do_revert_selection
38763944
bind . <$M1B-Key-J> do_revert_selection
38773945
bind . <$M1B-Key-i> do_add_all
38783946
bind . <$M1B-Key-I> do_add_all
3947+
bind . <$M1B-Key-e> toggle_commit_type
3948+
bind . <$M1B-Key-E> toggle_commit_type
38793949
bind . <$M1B-Key-minus> {show_less_context;break}
38803950
bind . <$M1B-Key-KP_Subtract> {show_less_context;break}
38813951
bind . <$M1B-Key-equal> {show_more_context;break}
@@ -3892,6 +3962,14 @@ foreach i [list $ui_index $ui_workdir] {
38923962
}
38933963
unset i
38943964
3965+
bind . <Alt-Key-1> {focus_widget $::ui_workdir}
3966+
bind . <Alt-Key-2> {focus_widget $::ui_index}
3967+
bind . <Alt-Key-3> {focus $::ui_diff}
3968+
bind . <Alt-Key-4> {focus $::ui_comm}
3969+
3970+
set file_lists_last_clicked($ui_index) {}
3971+
set file_lists_last_clicked($ui_workdir) {}
3972+
38953973
set file_lists($ui_index) [list]
38963974
set file_lists($ui_workdir) [list]
38973975

git-gui/lib/checkout_op.tcl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ $err
389389
}
390390

391391
method _after_readtree {} {
392-
global selected_commit_type commit_type HEAD MERGE_HEAD PARENT
392+
global commit_type HEAD MERGE_HEAD PARENT
393393
global current_branch is_detached
394394
global ui_comm
395395

@@ -490,12 +490,12 @@ method _update_repo_state {} {
490490
# amend mode our file lists are accurate and we can avoid
491491
# the rescan.
492492
#
493-
global selected_commit_type commit_type HEAD MERGE_HEAD PARENT
493+
global commit_type_is_amend commit_type HEAD MERGE_HEAD PARENT
494494
global ui_comm
495495

496496
unlock_index
497497
set name [_name $this]
498-
set selected_commit_type new
498+
set commit_type_is_amend 0
499499
if {[string match amend* $commit_type]} {
500500
$ui_comm delete 0.0 end
501501
$ui_comm edit reset

git-gui/lib/commit.tcl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ proc commit_writetree {curHEAD msg_p} {
333333
proc commit_committree {fd_wt curHEAD msg_p} {
334334
global HEAD PARENT MERGE_HEAD commit_type commit_author
335335
global current_branch
336-
global ui_comm selected_commit_type
336+
global ui_comm commit_type_is_amend
337337
global file_states selected_paths rescan_active
338338
global repo_config
339339
global env
@@ -467,8 +467,8 @@ A rescan will be automatically started now.
467467

468468
# -- Update in memory status
469469
#
470-
set selected_commit_type new
471470
set commit_type normal
471+
set commit_type_is_amend 0
472472
set HEAD $cmt_id
473473
set PARENT $cmt_id
474474
set MERGE_HEAD [list]

0 commit comments

Comments
 (0)