git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Nieder <jrnieder@gmail.com>
To: "David D. Kilzer" <ddkilzer@kilzer.net>
Cc: Junio C Hamano <gitster@pobox.com>,
	git@vger.kernel.org,
	Johannes Schindelin <johannes.schindelin@gmx.de>
Subject: [PATCH 3/5] Teach "apply --index-info" to handle rename patches
Date: Fri, 23 Jul 2010 12:04:44 -0500	[thread overview]
Message-ID: <20100723170444.GD2507@burratino> (raw)
In-Reply-To: <20100723170103.GA2507@burratino>

From: Junio C Hamano <gitster@pobox.com>
Date: Mon, 10 Nov 2008 15:49:03 -0800

With v1.5.3.2~14 (apply --index-info: fall back to current index for
mode changes, 2007-09-17), git apply learned to stop worrying
about the lack of diff index line when a file already present in the
current index had no content change.

But it still worries too much: for rename patches, it is checking
that both the old and new filename are present in the current
index.  This makes no sense, since a file rename generally
involves creating a file there was none before.

So just check the old filename.

Noticed while trying to use “git rebase” with diff.renames = copies.

[jn: add tests]

Reported-by: David D. Kilzer <ddkilzer@kilzer.net>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 builtin/apply.c |    3 +--
 t/t4150-am.sh   |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/builtin/apply.c b/builtin/apply.c
index 12ef9ea..f38c1f7 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -2979,8 +2979,7 @@ static void build_fake_ancestor(struct patch *list, const char *filename)
 		else if (get_sha1(patch->old_sha1_prefix, sha1))
 			/* git diff has no index line for mode/type changes */
 			if (!patch->lines_added && !patch->lines_deleted) {
-				if (get_current_sha1(patch->new_name, sha1) ||
-				    get_current_sha1(patch->old_name, sha1))
+				if (get_current_sha1(patch->old_name, sha1))
 					die("mode change for %s, which is not "
 						"in current HEAD", name);
 				sha1_ptr = sha1;
diff --git a/t/t4150-am.sh b/t/t4150-am.sh
index 70b57de..1c3d8ed 100755
--- a/t/t4150-am.sh
+++ b/t/t4150-am.sh
@@ -116,6 +116,18 @@ test_expect_success setup '
 	git commit -m "added another file" &&
 
 	git format-patch --stdout master >lorem-move.patch &&
+
+	git checkout -b rename &&
+	git mv file renamed &&
+	git commit -m "renamed a file" &&
+
+	git format-patch -M --stdout lorem >rename.patch &&
+
+	git reset --soft lorem^ &&
+	git commit -m "renamed a file and added another" &&
+
+	git format-patch -M --stdout lorem^ >rename-add.patch &&
+
 	# reset time
 	unset test_tick &&
 	test_tick
@@ -246,8 +258,42 @@ test_expect_success 'am -3 falls back to 3-way merge' '
 	git diff --exit-code lorem
 '
 
+test_expect_success 'am can rename a file' '
+	grep "^rename from" rename.patch &&
+	rm -fr .git/rebase-apply &&
+	git reset --hard &&
+	git checkout lorem^0 &&
+	git am rename.patch &&
+	! test -d .git/rebase-apply &&
+	git update-index --refresh &&
+	git diff --exit-code rename
+'
+
+test_expect_success 'am -3 can rename a file' '
+	grep "^rename from" rename.patch &&
+	rm -fr .git/rebase-apply &&
+	git reset --hard &&
+	git checkout lorem^0 &&
+	git am -3 rename.patch &&
+	! test -d .git/rebase-apply &&
+	git update-index --refresh &&
+	git diff --exit-code rename
+'
+
+test_expect_success 'am -3 can rename a file after falling back to 3-way merge' '
+	grep "^rename from" rename-add.patch &&
+	rm -fr .git/rebase-apply &&
+	git reset --hard &&
+	git checkout lorem^0 &&
+	git am -3 rename-add.patch &&
+	! test -d .git/rebase-apply &&
+	git update-index --refresh &&
+	git diff --exit-code rename
+'
+
 test_expect_success 'am -3 -q is quiet' '
 	rm -fr .git/rebase-apply &&
+	git checkout -f lorem2 &&
 	git reset master2 --hard &&
 	sed -n -e "3,\$p" msg >file &&
 	head -n 9 msg >>file &&
-- 
1.7.2.rc3

  parent reply	other threads:[~2010-07-23 17:06 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-10 22:26 [PATCH] 3-way merge with file move fails when diff.renames = copies David D. Kilzer
2008-11-10 23:41 ` Johannes Schindelin
2008-11-10 23:53   ` [PATCH] Fix 3-way merge with file move " David D. Kilzer
2008-11-10 23:49 ` [PATCH] 3-way merge with file move fails " Junio C Hamano
2008-11-11  0:06   ` David D. Kilzer
2008-11-11  0:15   ` Junio C Hamano
2010-07-21 19:58     ` [PATCH] Fix rebase with file move " David D. Kilzer
2010-07-21 21:54       ` Junio C Hamano
2010-07-22  0:22         ` David D. Kilzer
2010-07-22  7:51       ` Jonathan Nieder
2010-07-22 21:59         ` David D. Kilzer
2010-07-23 17:01           ` [PATCH 0/5] " Jonathan Nieder
2010-07-23 17:03             ` [PATCH 1/5] t4150 (am): style tweaks Jonathan Nieder
2010-07-23 17:04             ` [PATCH 2/5] t4150 (am): futureproof against failing tests Jonathan Nieder
2010-07-23 17:04             ` Jonathan Nieder [this message]
2010-07-23 17:05             ` [PATCH 4/5] t3400 (rebase): whitespace cleanup Jonathan Nieder
2010-07-23 17:06             ` [PATCH 5/5] rebase: protect against diff.renames configuration Jonathan Nieder
2010-07-23 19:51               ` Sverre Rabbelier
2010-07-23 21:03                 ` Junio C Hamano
2010-07-23 19:53               ` Sverre Rabbelier
2010-07-23 18:47             ` [PATCH 0/5] Fix rebase with file move when diff.renames = copies David D. Kilzer
2010-07-24 21:59               ` Jonathan Nieder

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=20100723170444.GD2507@burratino \
    --to=jrnieder@gmail.com \
    --cc=ddkilzer@kilzer.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=johannes.schindelin@gmx.de \
    /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).