From: Junio C Hamano <gitster@pobox.com>
To: Alex Riesen <raa.lkml@gmail.com>
Cc: git@vger.kernel.org
Subject: [PATCH] fix git commit --amend -m "new message"
Date: Wed, 19 Dec 2007 19:23:03 -0800 [thread overview]
Message-ID: <7v8x3qrqw8.fsf@gitster.siamese.dyndns.org> (raw)
The prepare_log_message() function serves two purposes:
- Prepares the commit log message template, to be given to the end
user;
- Return true if there is something committable;
7168624c3530d8c7ee32f930f8fb2ba302b9801f (Do not generate full commit
log message if it is not going to be used) cheated to omit the former
when we know the log message template is not going to be used. However,
its replacement logic to see if there is something committable was
botched. When amending, it should compare the index with the parent of
the HEAD, not the current HEAD. Otherwise you cannot run --amend to
fix only the message without changing the tree.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
* I think the other cheat to return !!active_nr is checking if it is
the initial commit, and its test that appear in the context of this
patch should be replaced with "if (initial_commit)", but I wanted to
first fix the bug.
builtin-commit.c | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/builtin-commit.c b/builtin-commit.c
index 0a91013..96410de 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -375,6 +375,7 @@ static int prepare_log_message(const char *index_file, const char *prefix)
if (no_edit) {
struct rev_info rev;
unsigned char sha1[40];
+ const char *parent = "HEAD";
fclose(fp);
@@ -384,9 +385,12 @@ static int prepare_log_message(const char *index_file, const char *prefix)
if (get_sha1("HEAD", sha1) != 0)
return !!active_nr;
+ if (amend)
+ parent = "HEAD^1";
+
init_revisions(&rev, "");
rev.abbrev = 0;
- setup_revisions(0, NULL, &rev, "HEAD");
+ setup_revisions(0, NULL, &rev, parent);
DIFF_OPT_SET(&rev.diffopt, QUIET);
DIFF_OPT_SET(&rev.diffopt, EXIT_WITH_STATUS);
run_diff_index(&rev, 1 /* cached */);
reply other threads:[~2007-12-20 3:23 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=7v8x3qrqw8.fsf@gitster.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=raa.lkml@gmail.com \
/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).