From: Peter Krefting <peter@softwolves.pp.se>
To: Git Mailing List <git@vger.kernel.org>
Subject: [PATCH] Allow hashes in git rebase --interactive --autosquash.
Date: Thu, 17 Jun 2010 13:55:22 +0100 [thread overview]
Message-ID: <20100617125746.E86B42FC00@perkele> (raw)
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@softwolves.pp.se>
---
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
next reply other threads:[~2010-06-17 13:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-17 12:55 Peter Krefting [this message]
2010-06-17 13:17 ` [PATCH] Allow hashes in git rebase --interactive --autosquash Jay Soffian
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100617125746.E86B42FC00@perkele \
--to=peter@softwolves.pp.se \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).