]> rtime.felk.cvut.cz Git - sojka/gitk.git/commitdiff
gitk: Learn how to fixup commits edit-commit
authorMichal Sojka <sojka@os.inf.tu-dresden.de>
Thu, 25 Aug 2011 07:36:35 +0000 (09:36 +0200)
committerMichal Sojka <sojka@os.inf.tu-dresden.de>
Mon, 29 Aug 2011 09:46:35 +0000 (11:46 +0200)
Signed-off-by: Michal Sojka <sojka@os.inf.tu-dresden.de>
gitk

diff --git a/gitk b/gitk
index c0fdd658ae9e7f7bac6f2e14fd998ce1df442b63..79f281a8e49e637fba64cef7bbb21bb9f13064d9 100755 (executable)
--- a/gitk
+++ b/gitk
@@ -2482,6 +2482,7 @@ proc makewindow {} {
        {mc "Diff this -> selected" command {diffvssel 0}}
        {mc "Diff selected -> this" command {diffvssel 1}}
        {mc "Edit this commit" command edit_commit}
+       {mc "Fold this into selected (fixup)" command fixup_commit}
        {mc "Make patch" command mkpatch}
        {mc "Create tag" command mktag}
        {mc "Write commit to file" command writecommit}
@@ -8446,18 +8447,19 @@ proc rowmenu {x y id} {
     if {$id ne $nullid && $id ne $nullid2} {
        set menu $rowctxmenu
        if {$mainhead ne {}} {
-           $menu entryconfigure 8 -label [mc "Reset %s branch to here" $mainhead] -state normal
+           $menu entryconfigure 9 -label [mc "Reset %s branch to here" $mainhead] -state normal
        } else {
-           $menu entryconfigure 8 -label [mc "Detached head: can't reset" $mainhead] -state disabled
+           $menu entryconfigure 9 -label [mc "Detached head: can't reset" $mainhead] -state disabled
        }
+       $menu entryconfigure [mca "Fold this into selected (fixup)"] -state $state
        if {[info exists markedid] && $markedid ne $id} {
-           $menu entryconfigure 10 -state normal
            $menu entryconfigure 11 -state normal
            $menu entryconfigure 12 -state normal
+           $menu entryconfigure 13 -state normal
        } else {
-           $menu entryconfigure 10 -state disabled
            $menu entryconfigure 11 -state disabled
            $menu entryconfigure 12 -state disabled
+           $menu entryconfigure 13 -state disabled
        }
     } else {
        set menu $fakerowmenu
@@ -9182,6 +9184,25 @@ proc edit_commit {} {
     notbusy edit
 }
 
+proc fixup_commit {} {
+    global rowmenuid selectedline
+    set selectedid [commitonrow $selectedline]
+    set baseid [exec git merge-base $selectedid $rowmenuid]
+
+    if {![rebase_ok $baseid]} return
+
+    set this [string range $rowmenuid 0 6]
+    set selected [string range $selectedid  0 6]
+    nowbusy fixup
+    if {[catch {exec sh -c "GIT_EDITOR=\"sed -i -e '/^pick $selected/a fixup $this' -e '/^pick $this/d'\" git rebase -p -i --no-autosquash $baseid^ 2>&1"} err]} {
+       notbusy fixup
+       error_popup $err
+       exec git rebase --abort
+       return
+    }
+    updatecommits
+    notbusy fixup
+}
 
 proc resethead {} {
     global mainhead rowmenuid confirm_ok resettype NS