Skip to content

Commit 450870c

Browse files
peffgitster
authored andcommitted
t1450: refactor ".", "..", and ".git" fsck tests
We check that fsck notices and complains about confusing paths in trees. However, there are a few shortcomings: 1. We check only for these paths as file entries, not as intermediate paths (so ".git" and not ".git/foo"). 2. We check "." and ".." together, so it is possible that we notice only one and not the other. 3. We repeat a lot of boilerplate. Let's use some loops to be more thorough in our testing, and still end up with shorter code. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cc2fc7c commit 450870c

File tree

1 file changed

+27
-30
lines changed

1 file changed

+27
-30
lines changed

t/t1450-fsck.sh

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -237,35 +237,32 @@ test_expect_success 'fsck notices submodule entry pointing to null sha1' '
237237
)
238238
'
239239

240-
test_expect_success 'fsck notices "." and ".." in trees' '
241-
(
242-
git init dots &&
243-
cd dots &&
244-
blob=$(echo foo | git hash-object -w --stdin) &&
245-
tab=$(printf "\\t") &&
246-
git mktree <<-EOF &&
247-
100644 blob $blob$tab.
248-
100644 blob $blob$tab..
249-
EOF
250-
git fsck 2>out &&
251-
cat out &&
252-
grep "warning.*\\." out
253-
)
254-
'
255-
256-
test_expect_success 'fsck notices ".git" in trees' '
257-
(
258-
git init dotgit &&
259-
cd dotgit &&
260-
blob=$(echo foo | git hash-object -w --stdin) &&
261-
tab=$(printf "\\t") &&
262-
git mktree <<-EOF &&
263-
100644 blob $blob$tab.git
264-
EOF
265-
git fsck 2>out &&
266-
cat out &&
267-
grep "warning.*\\.git" out
268-
)
269-
'
240+
while read name path; do
241+
while read mode type; do
242+
test_expect_success "fsck notices $path as $type" '
243+
(
244+
git init $name-$type &&
245+
cd $name-$type &&
246+
echo content >file &&
247+
git add file &&
248+
git commit -m base &&
249+
blob=$(git rev-parse :file) &&
250+
tree=$(git rev-parse HEAD^{tree}) &&
251+
value=$(eval "echo \$$type") &&
252+
printf "$mode $type %s\t%s" "$value" "$path" >bad &&
253+
git mktree <bad &&
254+
git fsck 2>out &&
255+
cat out &&
256+
grep "warning.*\\." out
257+
)'
258+
done <<-\EOF
259+
100644 blob
260+
040000 tree
261+
EOF
262+
done <<-\EOF
263+
dot .
264+
dotdot ..
265+
dotgit .git
266+
EOF
270267

271268
test_done

0 commit comments

Comments
 (0)