Fix check_file_directory_conflict().
authorJunio C Hamano <junkio@cox.net>
Sun, 17 Dec 2006 01:39:06 +0000 (17:39 -0800)
committerJunio C Hamano <junkio@cox.net>
Sun, 17 Dec 2006 09:14:44 +0000 (01:14 -0800)
When replacing an existing file A with a directory A that has a
file A/B in it in the index, 'update-index --replace --add A/B'
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>
read-cache.c
t/t0000-basic.sh
index 983e68b892a9922e8d46c83a5a39b36d535d95dd..b8d83ccd9f7985d60f69b7cd44db698d4e932612 100644 (file)
@@ -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;
                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;
                                break;
                        remove_cache_entry_at(pos);
                        continue;
index 3260d1d7a746f6968aab0d3f374bd7e76bf33bd0..0cd1c41866c6ca344ed99fae3d71014dd9321e2d 100755 (executable)
@@ -272,4 +272,13 @@ test_expect_success \
         wc -l) &&
      test $numparent = 1'
 
         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
 test_done