From: Andrew Pimlott <andrew@pimlott.net>
To: Thomas Rast <trast@inf.ethz.ch>
Cc: git <git@vger.kernel.org>
Subject: [PATCH] rebase -i: fixup fixup! fixup!
Date: Fri, 14 Jun 2013 12:31:57 -0700 [thread overview]
Message-ID: <1371237209-sup-639@pimlott.net> (raw)
In-Reply-To: <87obbc8otc.fsf@hexa.v.cablecom.net>
Excerpts from Thomas Rast's message of Tue Jun 11 11:50:07 -0700 2013:
> Andrew Pimlott <andrew@pimlott.net> writes:
> > git commit -m 'fix nasty bug'
> > ...
> > git commit --fixup :/nasty
> > ...
> > git commit --fixup :/nasty
> >
> > The second :/nasty resolves to the previous fixup, not the initial
> > commit. I could have made the regular expression more precise, but this
> > would be a hassle.
> >
> > Would a change to support fixup! fixup! be considered?
>
> Sure, why not. You could start with something like the patch below
> (untested). If that happens to work, just add a test and a good commit
> message.
It happened to work and I added a test. But then it occurred to me that
it might have been better to fix commit --fixup/--squash to strip the
fixup! or squash! from the referenced commit in the first place.
Anyhow, below is my patch for --autosquash, but unles someone has an
objection to doing it in commit, I'll work on that.
Andrew
Ignore subsequent "fixup! " or "squash! " after the first. Handy in case a
git commit --fixup/--squash referred to a previous fixup/squash instead of
the original commit, for example with :/msg.
Signed-off-by: Andrew Pimlott <andrew@pimlott.net>
---
Documentation/git-rebase.txt | 4 +++-
git-rebase--interactive.sh | 13 ++++++++++-
t/t3415-rebase-autosquash.sh | 49 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 64 insertions(+), 2 deletions(-)
diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt
index c84854a..725cf27 100644
--- a/Documentation/git-rebase.txt
+++ b/Documentation/git-rebase.txt
@@ -389,7 +389,9 @@ squash/fixup series.
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`).
+ commit from `pick` to `squash` (or `fixup`). Ignores subsequent
+ "fixup! " or "squash! " after the first, in case you referred to a
+ previous fixup/squash with `git commit --fixup/--squash`.
+
This option is only valid when the '--interactive' option is used.
+
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index f953d8d..54ed4c3 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -689,7 +689,18 @@ rearrange_squash () {
case "$message" in
"squash! "*|"fixup! "*)
action="${message%%!*}"
- rest="${message#*! }"
+ rest=$message
+ # ignore any squash! or fixup! after the first
+ while : ; do
+ case "$rest" in
+ "squash! "*|"fixup! "*)
+ rest="${rest#*! }"
+ ;;
+ *)
+ break
+ ;;
+ esac
+ done
echo "$sha1 $action $rest"
# if it's a single word, try to resolve to a full sha1 and
# emit a second copy. This allows us to match on both message
diff --git a/t/t3415-rebase-autosquash.sh b/t/t3415-rebase-autosquash.sh
index a1e86c4..1a3f40a 100755
--- a/t/t3415-rebase-autosquash.sh
+++ b/t/t3415-rebase-autosquash.sh
@@ -193,4 +193,53 @@ test_expect_success 'use commit --squash' '
test_auto_commit_flags squash 2
'
+test_auto_fixup_fixup () {
+ git reset --hard base &&
+ echo 1 >file1 &&
+ git add -u &&
+ test_tick &&
+ git commit -m "$1! first" &&
+ echo 2 >file1 &&
+ git add -u &&
+ test_tick &&
+ git commit -m "$1! $2! first" &&
+ git tag "final-$1-$2" &&
+ test_tick &&
+ git rebase --autosquash -i HEAD^^^^ &&
+ git log --oneline >actual &&
+ test_pause &&
+ if [ "$1" = "fixup" ]; then
+ test_line_count = 3 actual
+ elif [ "$1" = "squash" ]; then
+ test_line_count = 4 actual
+ else
+ false
+ fi &&
+ git diff --exit-code "final-$1-$2" &&
+ test 2 = "$(git cat-file blob HEAD^:file1)" &&
+ if [ "$1" = "fixup" ]; then
+ test 1 = $(git cat-file commit HEAD^ | grep first | wc -l)
+ elif [ "$1" = "squash" ]; then
+ test 3 = $(git cat-file commit HEAD^ | grep first | wc -l)
+ else
+ false
+ fi
+}
+
+test_expect_success 'fixup! fixup!' '
+ test_auto_fixup_fixup fixup fixup
+'
+
+test_expect_success 'fixup! squash!' '
+ test_auto_fixup_fixup fixup squash
+'
+
+test_expect_success 'squash! squash!' '
+ test_auto_fixup_fixup squash squash
+'
+
+test_expect_success 'squash! fixup!' '
+ test_auto_fixup_fixup squash fixup
+'
+
test_done
--
1.7.10.4
next prev parent reply other threads:[~2013-06-14 19:32 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-11 18:05 rebase --autosquash does not handle fixup! of fixup! Andrew Pimlott
2013-06-11 18:50 ` Thomas Rast
2013-06-14 19:31 ` Andrew Pimlott [this message]
2013-06-15 6:50 ` [PATCH] rebase -i: fixup fixup! fixup! Andrew Pimlott
2013-06-15 10:07 ` Junio C Hamano
2013-06-16 1:19 ` Junio C Hamano
2013-06-16 11:08 ` Thomas Rast
2013-06-17 2:38 ` Junio C Hamano
2013-06-17 8:07 ` Thomas Rast
2013-06-17 14:27 ` Junio C Hamano
2013-06-25 20:41 ` Andrew Pimlott
2013-06-25 21:33 ` Junio C Hamano
2013-06-25 23:17 ` Andrew Pimlott
2013-06-25 21:36 ` Junio C Hamano
2013-06-25 21:45 ` Junio C Hamano
2013-06-25 22:01 ` Junio C Hamano
2013-06-25 23:03 ` Andrew Pimlott
2013-06-26 22:00 ` Andrew Pimlott
2013-06-26 23:48 ` Junio C Hamano
2013-06-27 0:20 ` Andrew Pimlott
2013-06-27 19:26 ` Andrew Pimlott
2013-06-27 20:52 ` Junio C Hamano
2013-06-28 14:20 ` Andrew Pimlott
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=1371237209-sup-639@pimlott.net \
--to=andrew@pimlott.net \
--cc=git@vger.kernel.org \
--cc=trast@inf.ethz.ch \
/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).