* [PATCH] Allow hashes in git rebase --interactive --autosquash.
@ 2010-06-17 12:55 Peter Krefting
2010-06-17 13:17 ` Jay Soffian
0 siblings, 1 reply; 2+ messages in thread
From: Peter Krefting @ 2010-06-17 12:55 UTC (permalink / raw)
To: Git Mailing List
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] Allow hashes in git rebase --interactive --autosquash.
2010-06-17 12:55 [PATCH] Allow hashes in git rebase --interactive --autosquash Peter Krefting
@ 2010-06-17 13:17 ` Jay Soffian
0 siblings, 0 replies; 2+ messages in thread
From: Jay Soffian @ 2010-06-17 13:17 UTC (permalink / raw)
To: Peter Krefting; +Cc: Git Mailing List
On Thu, Jun 17, 2010 at 8:55 AM, Peter Krefting <peter@softwolves.pp.se> wrote:
> 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... :-)
Heh. I have this alias for creating my fixup commits:
$ git help fixup
`git fixup' is aliased to `!f() { git commit -m "$(git show -s
--pretty='format:fixup! %s%n%nFixup for %h%n' "$@")"; }; f'
:-)
j.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-06-17 13:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-17 12:55 [PATCH] Allow hashes in git rebase --interactive --autosquash Peter Krefting
2010-06-17 13:17 ` Jay Soffian
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).