From: Junio C Hamano <junkio@cox.net>
To: git@vger.kernel.org
Subject: Re: git-add fails after file type change
Date: Sat, 16 Dec 2006 17:39:06 -0800 [thread overview]
Message-ID: <7vk60r7139.fsf@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: <7vvekb73jh.fsf@assigned-by-dhcp.cox.net> (Junio C. Hamano's message of "Sat, 16 Dec 2006 16:46:10 -0800")
When replacing an existing file A with a directory B that has a
file B/C in it in the index, 'update-index --replace --add B/C'
did not properly remove the file to make room for the new
directory.
There was a trivial logic error, most likely a cut & paste one,
dating back to quite early days of git.
Signed-off-by: Junio C Hamano <junkio@cox.net>
---
Junio C Hamano <junkio@cox.net> writes:
> But I think you helped me to spot a bug ;-).
>
> $ git update-index --replace --add 3/2
> $ git ls-files -s
> 100644 00750edc07d6415dcc07ae0351e9397b0222b7ba 0 1
> 100644 00750edc07d6415dcc07ae0351e9397b0222b7ba 0 3
> 100644 fa457baf8abbf5dd3bb4cbfab0c5a4cf0523d7f8 0 3/2
>
> The entry '3' should have been removed when we did --replace.
> This index cannot be written out as a tree:
>
> $ git write-tree
> You have both 3 and 3/2
> fatal: git-write-tree: error building trees
And this fixes it.
read-cache.c | 2 +-
t/t0000-basic.sh | 9 +++++++++
2 files changed, 10 insertions(+), 1 deletions(-)
diff --git a/read-cache.c b/read-cache.c
index a602010..e856a2e 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -517,7 +517,7 @@ static int has_dir_name(const struct cache_entry *ce, int pos, int ok_to_replace
pos = cache_name_pos(name, ntohs(create_ce_flags(len, stage)));
if (pos >= 0) {
retval = -1;
- if (ok_to_replace)
+ if (!ok_to_replace)
break;
remove_cache_entry_at(pos);
continue;
diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh
index 3260d1d..0cd1c41 100755
--- a/t/t0000-basic.sh
+++ b/t/t0000-basic.sh
@@ -272,4 +272,13 @@ test_expect_success \
wc -l) &&
test $numparent = 1'
+test_expect_success 'update-index D/F conflict' '
+ mv path0 tmp &&
+ mv path2 path0 &&
+ mv tmp path2 &&
+ git update-index --add --replace path2 path0/file2 &&
+ numpath0=$(git ls-files path0 | wc -l) &&
+ test $numpath0 = 1
+'
+
test_done
next prev parent reply other threads:[~2006-12-17 1:39 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-12-16 18:16 git-add fails after file type change Steven Grimm
2006-12-16 18:31 ` Jakub Narebski
2006-12-16 18:44 ` Steven Grimm
2006-12-16 18:35 ` A Large Angry SCM
2006-12-16 21:58 ` Junio C Hamano
2006-12-16 22:40 ` Steven Grimm
2006-12-17 0:19 ` Steven Grimm
2006-12-17 0:46 ` Junio C Hamano
2006-12-17 1:39 ` Junio C Hamano [this message]
2006-12-17 9:11 ` [PATCH] git-add: remove conflicting entry when adding Junio C Hamano
2006-12-16 19:23 ` git-add fails after file type change Junio C Hamano
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=7vk60r7139.fsf@assigned-by-dhcp.cox.net \
--to=junkio@cox.net \
--cc=git@vger.kernel.org \
/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