Skip to content

Commit 6fb735a

Browse files
committed
gitk: Add a "reset branch to here" row context-menu operation
This adds an entry to the menu that comes up when the user does a right-click on a row. The new entry allows the user to reset the currently checked-out head to the commit for the row that they did the right-click on. The user has to select what type of reset to do, and confirm the reset, via a dialog box that pops up. Signed-off-by: Paul Mackerras <[email protected]>
1 parent 6a90bff commit 6fb735a

File tree

1 file changed

+57
-5
lines changed

1 file changed

+57
-5
lines changed

gitk

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,8 @@ proc makewindow {} {
873873
$rowctxmenu add command -label "Create new branch" -command mkbranch
874874
$rowctxmenu add command -label "Cherry-pick this commit" \
875875
-command cherrypick
876+
$rowctxmenu add command -label "Reset HEAD branch to here" \
877+
-command resethead
876878

877879
set fakerowmenu .fakerowmenu
878880
menu $fakerowmenu -tearoff 0
@@ -5377,8 +5379,8 @@ proc mstime {} {
53775379
}
53785380

53795381
proc rowmenu {x y id} {
5380-
global rowctxmenu commitrow selectedline rowmenuid curview nullid
5381-
global fakerowmenu
5382+
global rowctxmenu commitrow selectedline rowmenuid curview
5383+
global nullid fakerowmenu mainhead
53825384

53835385
set rowmenuid $id
53845386
if {![info exists selectedline]
@@ -5389,6 +5391,7 @@ proc rowmenu {x y id} {
53895391
}
53905392
if {$id ne $nullid} {
53915393
set menu $rowctxmenu
5394+
$menu entryconfigure 7 -label "Reset $mainhead branch to here"
53925395
} else {
53935396
set menu $fakerowmenu
53945397
}
@@ -5775,6 +5778,55 @@ proc cherrypick {} {
57755778
notbusy cherrypick
57765779
}
57775780

5781+
proc resethead {} {
5782+
global mainheadid mainhead rowmenuid confirm_ok resettype
5783+
global showlocalchanges
5784+
5785+
set confirm_ok 0
5786+
set w ".confirmreset"
5787+
toplevel $w
5788+
wm transient $w .
5789+
wm title $w "Confirm reset"
5790+
message $w.m -text \
5791+
"Reset branch $mainhead to [string range $rowmenuid 0 7]?" \
5792+
-justify center -aspect 1000
5793+
pack $w.m -side top -fill x -padx 20 -pady 20
5794+
frame $w.f -relief sunken -border 2
5795+
message $w.f.rt -text "Reset type:" -aspect 1000
5796+
grid $w.f.rt -sticky w
5797+
set resettype mixed
5798+
radiobutton $w.f.soft -value soft -variable resettype -justify left \
5799+
-text "Soft: Leave working tree and index untouched"
5800+
grid $w.f.soft -sticky w
5801+
radiobutton $w.f.mixed -value mixed -variable resettype -justify left \
5802+
-text "Mixed: Leave working tree untouched, reset index"
5803+
grid $w.f.mixed -sticky w
5804+
radiobutton $w.f.hard -value hard -variable resettype -justify left \
5805+
-text "Hard: Reset working tree and index\n(discard ALL local changes)"
5806+
grid $w.f.hard -sticky w
5807+
pack $w.f -side top -fill x
5808+
button $w.ok -text OK -command "set confirm_ok 1; destroy $w"
5809+
pack $w.ok -side left -fill x -padx 20 -pady 20
5810+
button $w.cancel -text Cancel -command "destroy $w"
5811+
pack $w.cancel -side right -fill x -padx 20 -pady 20
5812+
bind $w <Visibility> "grab $w; focus $w"
5813+
tkwait window $w
5814+
if {!$confirm_ok} return
5815+
dohidelocalchanges
5816+
if {[catch {exec git reset --$resettype $rowmenuid} err]} {
5817+
error_popup $err
5818+
} else {
5819+
set oldhead $mainheadid
5820+
movedhead $rowmenuid $mainhead
5821+
set mainheadid $rowmenuid
5822+
redrawtags $oldhead
5823+
redrawtags $rowmenuid
5824+
}
5825+
if {$showlocalchanges} {
5826+
doshowlocalchanges
5827+
}
5828+
}
5829+
57785830
# context menu for a head
57795831
proc headmenu {x y id head} {
57805832
global headmenuid headmenuhead headctxmenu mainhead
@@ -5812,9 +5864,9 @@ proc cobranch {} {
58125864
redrawtags $headids($oldmainhead)
58135865
}
58145866
redrawtags $headmenuid
5815-
if {$showlocalchanges} {
5816-
dodiffindex
5817-
}
5867+
}
5868+
if {$showlocalchanges} {
5869+
dodiffindex
58185870
}
58195871
}
58205872

0 commit comments

Comments
 (0)