Skip to content

Commit 7e75aeb

Browse files
committed
Merge branch 'rs/fsck-duplicate-names-in-trees'
The check in "git fsck" to ensure that the tree objects are sorted still had corner cases it missed unsorted entries. * rs/fsck-duplicate-names-in-trees: fsck: detect more in-tree d/f conflicts t1450: demonstrate undetected in-tree d/f conflict t1450: increase test coverage of in-tree d/f detection fsck: fix a typo in a comment
2 parents ce095ec + fe74704 commit 7e75aeb

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

fsck.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ static int verify_ordered(unsigned mode1, const char *name1,
598598

599599
/*
600600
* There can be non-consecutive duplicates due to the implicitly
601-
* add slash, e.g.:
601+
* added slash, e.g.:
602602
*
603603
* foo
604604
* foo.bar
@@ -620,7 +620,7 @@ static int verify_ordered(unsigned mode1, const char *name1,
620620
if (!f_name)
621621
break;
622622
if (!skip_prefix(name2, f_name, &p))
623-
break;
623+
continue;
624624
if (!*p)
625625
return TREE_HAS_DUPS;
626626
if (is_less_than_slash(*p)) {

t/t1450-fsck.sh

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -257,21 +257,34 @@ test_expect_success 'tree object with duplicate entries' '
257257
test_i18ngrep "error in tree .*contains duplicate file entries" out
258258
'
259259

260-
test_expect_success 'tree object with dublicate names' '
261-
test_when_finished "remove_object \$blob" &&
262-
test_when_finished "remove_object \$tree" &&
263-
test_when_finished "remove_object \$badtree" &&
264-
blob=$(echo blob | git hash-object -w --stdin) &&
265-
printf "100644 blob %s\t%s\n" $blob x.2 >tree &&
266-
tree=$(git mktree <tree) &&
267-
printf "100644 blob %s\t%s\n" $blob x.1 >badtree &&
268-
printf "100644 blob %s\t%s\n" $blob x >>badtree &&
269-
printf "040000 tree %s\t%s\n" $tree x >>badtree &&
270-
badtree=$(git mktree <badtree) &&
271-
test_must_fail git fsck 2>out &&
272-
test_i18ngrep "$badtree" out &&
273-
test_i18ngrep "error in tree .*contains duplicate file entries" out
274-
'
260+
check_duplicate_names () {
261+
expect=$1 &&
262+
shift &&
263+
names=$@ &&
264+
test_expect_$expect "tree object with duplicate names: $names" '
265+
test_when_finished "remove_object \$blob" &&
266+
test_when_finished "remove_object \$tree" &&
267+
test_when_finished "remove_object \$badtree" &&
268+
blob=$(echo blob | git hash-object -w --stdin) &&
269+
printf "100644 blob %s\t%s\n" $blob x.2 >tree &&
270+
tree=$(git mktree <tree) &&
271+
for name in $names
272+
do
273+
case "$name" in
274+
*/) printf "040000 tree %s\t%s\n" $tree "${name%/}" ;;
275+
*) printf "100644 blob %s\t%s\n" $blob "$name" ;;
276+
esac
277+
done >badtree &&
278+
badtree=$(git mktree <badtree) &&
279+
test_must_fail git fsck 2>out &&
280+
test_i18ngrep "$badtree" out &&
281+
test_i18ngrep "error in tree .*contains duplicate file entries" out
282+
'
283+
}
284+
285+
check_duplicate_names success x x.1 x/
286+
check_duplicate_names success x x.1.2 x.1/ x/
287+
check_duplicate_names success x x.1 x.1.2 x/
275288

276289
test_expect_success 'unparseable tree object' '
277290
test_oid_cache <<-\EOF &&

0 commit comments

Comments
 (0)