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 <paulus@samba.org>
Paul Mackerras committed
Oct 19, 2006 at 10:09 UTC
6fb735aedb25eade3d523053cb05c030a1cc06b3
1 file changed
+57
-5
gitk
+57
-5
@@ -873,6 +873,8 @@ proc makewindow {} {
873
$rowctxmenu add command -label "Create new branch" -command mkbranch
874
$rowctxmenu add command -label "Cherry-pick this commit" \
875
-command cherrypick
876
+ $rowctxmenu add command -label "Reset HEAD branch to here" \
877
+ -command resethead
878
879
set fakerowmenu .fakerowmenu
880
menu $fakerowmenu -tearoff 0
@@ -5377,8 +5379,8 @@ proc mstime {} {
5379
}
5380
5381
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
5384
5385
set rowmenuid $id
5386
if {![info exists selectedline]
@@ -5389,6 +5391,7 @@ proc rowmenu {x y id} {
5391
}
5392
if {$id ne $nullid} {
5393
set menu $rowctxmenu
5394
+ $menu entryconfigure 7 -label "Reset $mainhead branch to here"
5395
} else {
5396
set menu $fakerowmenu
5397
}
@@ -5775,6 +5778,55 @@ proc cherrypick {} {
5778
notbusy cherrypick
5779
}
5780
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
+
5830
# context menu for a head
5831
proc headmenu {x y id head} {
5832
global headmenuid headmenuhead headctxmenu mainhead
@@ -5812,9 +5864,9 @@ proc cobranch {} {
5864
redrawtags $headids($oldmainhead)
5865
}
5866
redrawtags $headmenuid
5815
- if {$showlocalchanges} {
5816
- dodiffindex
5817
- }
5867
+ }
5868
+ if {$showlocalchanges} {
5869
+ dodiffindex
5870
}
5871
}
5872