[PATCH] Allow hashes in git rebase --interactive --autosquash.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In addition to matching the "fixup!" and "squash!" commits to the commit
message, also match the commit hash. This allows a commit message like
"fixup! e83c5163316f89bfbde7d9ab23ca2e25604af290" to be detected as a
fixup commit.

Signed-off-by: Peter Krefting <peter@xxxxxxxxxxxxxxxx>
---

I actually misread the git-rebase manual page to think that this was how
"fixup!" and "squash!" was supposed to be used, and now I have so many
"fixup! <hash>" commits to rebase that I felt it worth it to implement
support for it... :-)

 Documentation/git-rebase.txt |    8 ++++----
 git-rebase--interactive.sh   |   12 +++++++++---
 t/t3415-rebase-autosquash.sh |   17 +++++++++++++++++
 3 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt
index 0d07b1b..e28d742 100644
--- a/Documentation/git-rebase.txt
+++ b/Documentation/git-rebase.txt
@@ -318,10 +318,10 @@ link:howto/revert-a-faulty-merge.txt[revert-a-faulty-merge How-To] for details).
 --autosquash::
 	When the commit log message begins with "squash! ..." (or
 	"fixup! ..."), and there is a commit whose title begins with
-	the same ..., automatically modify the todo list of rebase -i
-	so that the commit marked for squashing comes right after the
-	commit to be modified, and change the action of the moved
-	commit from `pick` to `squash` (or `fixup`).
+	the same ..., or whose hash is ..., automatically modify the
+        todo list of rebase -i so that the commit marked for squashing
+        comes right after the commit to be modified, and change the
+        action of the moved commit from `pick` to `squash` (or `fixup`).
 +
 This option is only valid when the '--interactive' option is used.
 
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 436b7f5..d639ee6 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -634,9 +634,9 @@ get_saved_options () {
 }
 
 # Rearrange the todo list that has both "pick sha1 msg" and
-# "pick sha1 fixup!/squash! msg" appears in it so that the latter
-# comes immediately after the former, and change "pick" to
-# "fixup"/"squash".
+# "pick sha1 fixup!/squash! msg" or "pick sha1 fixup!/squash!
+# sha1" appears in it so that the latter comes immediately
+# after the former, and change "pick" to "fixup"/"squash".
 rearrange_squash () {
 	sed -n -e 's/^pick \([0-9a-f]*\) \(squash\)! /\1 \2 /p' \
 		-e 's/^pick \([0-9a-f]*\) \(fixup\)! /\1 \2 /p' \
@@ -658,6 +658,12 @@ rearrange_squash () {
 				used="$used$squash "
 				;;
 			esac
+			case "$msg" in
+			"$sha1"*)
+				echo "$action $squash $action! $msg"
+				used="$used$squash "
+				;;
+			esac
 		done <"$1.sq"
 	done >"$1.rearranged" <"$1"
 	cat "$1.rearranged" >"$1"
diff --git a/t/t3415-rebase-autosquash.sh b/t/t3415-rebase-autosquash.sh
index b63f4e2..2f1a1b4 100755
--- a/t/t3415-rebase-autosquash.sh
+++ b/t/t3415-rebase-autosquash.sh
@@ -38,6 +38,23 @@ test_expect_success 'auto fixup' '
 	test 1 = $(git cat-file commit HEAD^ | grep first | wc -l)
 '
 
+test_expect_success 'auto fixup with hash' '
+	git reset --hard base &&
+	echo 1 >file1 &&
+	git add -u &&
+	test_tick &&
+	git log -1 --pretty="fixup! %h" HEAD^ | git commit -F -
+
+	git tag final-fixup-hash &&
+	test_tick &&
+	git rebase --autosquash -i HEAD^^^ &&
+	git log --oneline >actual &&
+	test 3 = $(wc -l <actual) &&
+	git diff --exit-code final-fixup-hash &&
+	test 1 = "$(git cat-file blob HEAD^:file1)" &&
+	test 1 = $(git cat-file commit HEAD^ | grep first | wc -l)
+'
+
 test_expect_success 'auto squash' '
 	git reset --hard base &&
 	echo 1 >file1 &&
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]