@@ -2567,6 +2567,7 @@ proc makewindow {} {
25672567{mc " Compare with marked commit" command compare_commits}
25682568{mc " Diff this -> marked commit" command {diffvsmark 0}}
25692569{mc " Diff marked commit -> this" command {diffvsmark 1}}
2570+ {mc " Revert this commit" command revert}
25702571 }
25712572 $rowctxmenu configure -tearoff 0
25722573
@@ -9346,6 +9347,67 @@ proc cherrypick {} {
93469347 notbusy cherrypick
93479348}
93489349
9350+ proc revert {} {
9351+ global rowmenuid curview
9352+ global mainhead mainheadid
9353+ global gitdir
9354+
9355+ set oldhead [exec git rev-parse HEAD]
9356+ set dheads [descheads $rowmenuid ]
9357+ if { $dheads eq {} || [lsearch -exact $dheads $oldhead ] == -1 } {
9358+ set ok [confirm_popup [mc " Commit %s is not\
9359+ included in branch %s -- really revert it?" \
9360+ [string range $rowmenuid 0 7] $mainhead ]]
9361+ if {!$ok } return
9362+ }
9363+ nowbusy revert [mc " Reverting" ]
9364+ update
9365+
9366+ if [catch {exec git revert --no-edit $rowmenuid } err] {
9367+ notbusy revert
9368+ if [regexp {files would be overwritten by merge:(\n(( |\t)+[^\n]+\n)+)}\
9369+ $err match files] {
9370+ regsub {\n( |\t)+} $files "\n " files
9371+ error_popup [mc " Revert failed because of local changes to\
9372+ the following files:%s Please commit, reset or stash \
9373+ your changes and try again." $files ]
9374+ } elseif [regexp {error: could not revert} $err ] {
9375+ if [confirm_popup [mc " Revert failed because of merge conflict.\n\
9376+ Do you wish to run git citool to resolve it?" ]] {
9377+ # Force citool to read MERGE_MSG
9378+ file delete [file join $gitdir " GITGUI_MSG" ]
9379+ exec_citool {} $rowmenuid
9380+ }
9381+ } else { error_popup $err }
9382+ run updatecommits
9383+ return
9384+ }
9385+
9386+ set newhead [exec git rev-parse HEAD]
9387+ if { $newhead eq $oldhead } {
9388+ notbusy revert
9389+ error_popup [mc " No changes committed" ]
9390+ return
9391+ }
9392+
9393+ addnewchild $newhead $oldhead
9394+
9395+ if [commitinview $oldhead $curview ] {
9396+ # XXX this isn't right if we have a path limit...
9397+ insertrow $newhead $oldhead $curview
9398+ if {$mainhead ne {}} {
9399+ movehead $newhead $mainhead
9400+ movedhead $newhead $mainhead
9401+ }
9402+ set mainheadid $newhead
9403+ redrawtags $oldhead
9404+ redrawtags $newhead
9405+ selbyid $newhead
9406+ }
9407+
9408+ notbusy revert
9409+ }
9410+
93499411proc resethead {} {
93509412 global mainhead rowmenuid confirm_ok resettype NS
93519413
0 commit comments