From 840e23db03bb43148c83f079690aa48eeb33eb81 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 16 Dec 2013 09:43:12 -0600 Subject: [PATCH] shears.sh: support fixup! and squash! One of the most powerful feature added to the already powerful interactive rebase was to allow workflows where you *add* commits with the intention to amend ("fix up") other commits in the topic branch at a later stage, through "git rebase -i --autosquash". Such commits are added by crafting special-format commit messages, or by using the convenient --fixup or --squash options of "git commit". However, with the garden shears, we side-step the original interactive rebase, therefore we have to re-implement that very convenient fixup/squash handling. Signed-off-by: Johannes Schindelin --- share/msysGit/shears.sh | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/share/msysGit/shears.sh b/share/msysGit/shears.sh index 6e1ea6d3..a8e6bb97 100755 --- a/share/msysGit/shears.sh +++ b/share/msysGit/shears.sh @@ -152,6 +152,11 @@ case " $extra_commands " in ;; esac +string2regex () { + echo "$*" | + sed 's/[][\\\/*?]/\\&/g' +} + ensure_labeled () { for n in "$@" do @@ -293,6 +298,40 @@ exec git update-ref refs/rewritten/$commit HEAD\\ ")" done + lastline=9999 + while true + do + fixup="$(echo "$todo" | + sed "$lastline,\$d" | + grep -n -e '^pick [^ ]* \(fixup\|squash\)!' | + tail -n 1)" + test -n "$fixup" || break + + linenumber=${fixup%%:*} + oneline="${fixup#* }" + shortsha1="${oneline%% *}" + oneline="${oneline#* }" + command=${oneline%%!*} + oneline="${oneline#*! }" + oneline_regex="^pick [^ ]* $(string2regex "$oneline")\$" + targetline="$(echo "$todo" | + sed "$linenumber,\$d" | + grep -n "$oneline_regex" | + tail -n 1)" + targetline=${targetline%%:*} + if test -n "$targetline" + then + todo="$(echo "$todo" | + sed -e "${linenumber}d" \ + -e "${targetline}a\\ +$command $shortsha1 $oneline")" + lastline=$(($linenumber+1)) + else + echo "UNHANDLED: $oneline" >&2 + lastline=$(($linenumber)) + fi + done + todo="$(printf '%s\n\n%s' "$todo" "cleanup $needslabel")" echo "$todo" | uniq } -- 2.11.4.GIT