From: Johannes Sixt <johannes.sixt@telecom.at>
To: gitster@pobox.com
Cc: git@vger.kernel.org, Johannes Sixt <johannes.sixt@telecom.at>
Subject: [PATCH] git-commit --amend: respect grafted parents.
Date: Wed, 26 Sep 2007 14:11:36 +0200 [thread overview]
Message-ID: <11908086961933-git-send-email-johannes.sixt@telecom.at> (raw)
This allows a poor-mans-filter-branch of the top-most commit.
Specifically, I had this history:
--o--o--A' <-- amended version of A
\
A
\
--o--B--M
I now wanted to "amend" M to pull in A' instead of A as its second parent.
For various reasons I didn't want to redo the merge M again, in particular,
it already contained the changes that were amended into A'. So I figured
I would just install a graft that lists B and A' as parents of M and then
do a simple git commit --amend. Alas, git commit looks at the real parents
instead of the grafted ones, so the amended M' would still have A as its
second parent. Here is the fix that picks the grafted parents instead.
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
---
I know that git-commit is becoming a builtin. At the least, here is
a test that makes sure that the behavior is remains.
-- Hannes
git-commit.sh | 4 ++--
t/t7501-commit.sh | 9 +++++++++
2 files changed, 11 insertions(+), 2 deletions(-)
mode change 100644 => 100755 t/t7501-commit.sh
diff --git a/git-commit.sh b/git-commit.sh
index 7a7a2cb..33e7503 100755
--- a/git-commit.sh
+++ b/git-commit.sh
@@ -529,8 +529,8 @@ then
PARENTS="-p HEAD "`sed -e 's/^/-p /' "$GIT_DIR/MERGE_HEAD"`
elif test -n "$amend"; then
rloga='commit (amend)'
- PARENTS=$(git cat-file commit HEAD |
- sed -n -e '/^$/q' -e 's/^parent /-p /p')
+ PARENTS=$(git rev-list --parents -1 HEAD |
+ sed -e 's/^[^ ]*//' -e 's/ / -p /g')
fi
current="$(git rev-parse --verify HEAD)"
else
diff --git a/t/t7501-commit.sh b/t/t7501-commit.sh
old mode 100644
new mode 100755
index b151b51..09c0d98
--- a/t/t7501-commit.sh
+++ b/t/t7501-commit.sh
@@ -163,4 +163,13 @@ test_expect_success 'partial commit that involves removal (3)' '
'
+test_expect_success '--amend respects grafts' '
+
+ grandparent=$(git rev-parse HEAD~2) &&
+ echo $(git rev-parse HEAD) $grandparent > .git/info/grafts &&
+ git commit --amend -C HEAD &&
+ test "parent $grandparent" = "$(git cat-file commit HEAD | grep "^parent")"
+
+'
+
test_done
--
1.5.3.3.gcc9e
next reply other threads:[~2007-09-26 12:11 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-26 12:11 Johannes Sixt [this message]
2007-09-26 12:24 ` [PATCH] git-commit --amend: respect grafted parents Johannes Schindelin
2007-09-26 12:52 ` Johannes Sixt
2007-09-26 14:03 ` Johannes Schindelin
2007-09-26 14:29 ` Johannes Sixt
2007-09-26 18:50 ` Junio C Hamano
2007-09-26 19:47 ` Johannes Schindelin
2007-09-27 8:39 ` David Kastrup
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=11908086961933-git-send-email-johannes.sixt@telecom.at \
--to=johannes.sixt@telecom.at \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.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).