From: Andrew Pimlott <andrew@pimlott.net>
To: Thomas Rast <trast@inf.ethz.ch>, git <git@vger.kernel.org>
Subject: Re: [PATCH] rebase -i: fixup fixup! fixup!
Date: Fri, 14 Jun 2013 23:50:21 -0700 [thread overview]
Message-ID: <1371278908-sup-1930@pimlott.net> (raw)
In-Reply-To: <1371237209-sup-639@pimlott.net>
Excerpts from Andrew Pimlott's message of Fri Jun 14 12:31:57 -0700 2013:
> 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.
Here is a patch for commit.c that does this.
Andrew
When building the commit message for --fixup/--squash, ignore a leading
fixup! or squash! on the referenced commit. Handy in case the user referred
to an earlier squash/fixup commit instead of the original commit, for
example with :/msg.
Signed-off-by: Andrew Pimlott <andrew@pimlott.net>
---
builtin/commit.c | 18 ++++++++++++++----
t/t7500-commit.sh | 36 ++++++++++++++++++++++++++++++++++++
2 files changed, 50 insertions(+), 4 deletions(-)
diff --git a/builtin/commit.c b/builtin/commit.c
index 1621dfc..370df88 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -601,8 +601,13 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
if (!c)
die(_("could not lookup commit %s"), squash_message);
ctx.output_encoding = get_commit_output_encoding();
- format_commit_message(c, "squash! %s\n\n", &sb,
- &ctx);
+ format_commit_message(c, "%s\n\n", &sb, &ctx);
+ if (!prefixcmp(sb.buf, "fixup! ")) {
+ strbuf_remove(&sb, 0, strlen("fixup! "));
+ } else if (!prefixcmp(sb.buf, "squash! ")) {
+ strbuf_remove(&sb, 0, strlen("squash! "));
+ }
+ strbuf_insert(&sb, 0, "squash! ", strlen("squash! "));
}
}
@@ -634,8 +639,13 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
if (!commit)
die(_("could not lookup commit %s"), fixup_message);
ctx.output_encoding = get_commit_output_encoding();
- format_commit_message(commit, "fixup! %s\n\n",
- &sb, &ctx);
+ format_commit_message(commit, "%s\n\n", &sb, &ctx);
+ if (!prefixcmp(sb.buf, "fixup! ")) {
+ strbuf_remove(&sb, 0, strlen("fixup! "));
+ } else if (!prefixcmp(sb.buf, "squash! ")) {
+ strbuf_remove(&sb, 0, strlen("squash! "));
+ }
+ strbuf_insert(&sb, 0, "fixup! ", strlen("fixup! "));
hook_arg1 = "message";
} else if (!stat(git_path("MERGE_MSG"), &statbuf)) {
if (strbuf_read_file(&sb, git_path("MERGE_MSG"), 0) < 0)
diff --git a/t/t7500-commit.sh b/t/t7500-commit.sh
index 436b7b6..ecdf74a 100755
--- a/t/t7500-commit.sh
+++ b/t/t7500-commit.sh
@@ -320,4 +320,40 @@ test_expect_success 'invalid message options when using --fixup' '
test_must_fail git commit --fixup HEAD~1 -F log
'
+test_expect_success 'commit --fixup of existing fixup' '
+ commit_for_rebase_autosquash_setup &&
+ git commit --fixup HEAD~1 &&
+ echo "fourth content line" >>foo &&
+ git add foo
+ git commit --fixup HEAD &&
+ commit_msg_is "fixup! target message subject line"
+'
+
+test_expect_success 'commit --fixup of existing squash' '
+ commit_for_rebase_autosquash_setup &&
+ git commit --squash HEAD~1 &&
+ echo "fourth content line" >>foo &&
+ git add foo
+ git commit --fixup HEAD &&
+ commit_msg_is "fixup! target message subject line"
+'
+
+test_expect_success 'commit --squash of existing squash' '
+ commit_for_rebase_autosquash_setup &&
+ git commit --squash HEAD~1 &&
+ echo "fourth content line" >>foo &&
+ git add foo
+ git commit --squash HEAD &&
+ commit_msg_is "squash! target message subject linecommit message"
+'
+
+test_expect_success 'commit --squash of existing fixup' '
+ commit_for_rebase_autosquash_setup &&
+ git commit --fixup HEAD~1 &&
+ echo "fourth content line" >>foo &&
+ git add foo
+ git commit --squash HEAD &&
+ commit_msg_is "squash! target message subject linecommit message"
+'
+
test_done
--
1.7.10.4
next prev parent reply other threads:[~2013-06-15 6:50 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 ` [PATCH] rebase -i: fixup fixup! fixup! Andrew Pimlott
2013-06-15 6:50 ` Andrew Pimlott [this message]
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1371278908-sup-1930@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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).