Skip to content

Commit 1cb12f3

Browse files
peffgitster
authored andcommitted
t7450: test .gitmodules symlink matching against obscured names
In t7450 we check that both verify_path() and fsck catch malformed .gitmodules entries in trees. However, we don't check that we catch filesystem-equivalent forms of these (e.g., ".GITMOD~1" on Windows). Our name-matching functions are exercised well in t0060, but there's nothing to test that we correctly call the matching functions from the actual fsck and verify_path() code. So instead of testing just .gitmodules, let's repeat our tests for a few basic cases. We don't need to be exhaustive here (t0060 handles that), but just make sure we hit one name of each type. Besides pushing the tests into a function that takes the path as a parameter, we'll need to do a few things: - adjust the directory name to accommodate the tests running multiple times - set core.protecthfs for index checks. Fsck always protects all types by default, but we want to be able to exercise the HFS routines on every system. Note that core.protectntfs is already the default these days, but it doesn't hurt to explicitly label our need for it. - we'll also take the filename ("gitmodules") as a parameter. All calls use the same name for now, but a future patch will extend this to handle other .gitfoo files. Note that our fake-content symlink destination is somewhat .gitmodules specific. But it isn't necessary for other files (which don't do a content check). And it happens to be a valid attribute and ignore file anyway. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a1ca398 commit 1cb12f3

File tree

1 file changed

+53
-38
lines changed

1 file changed

+53
-38
lines changed

t/t7450-bad-git-dotfiles.sh

Lines changed: 53 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -139,44 +139,59 @@ test_expect_success 'index-pack --strict works for non-repo pack' '
139139
grep gitmodulesName output
140140
'
141141

142-
test_expect_success 'set up repo with symlinked .gitmodules file' '
143-
git init symlink &&
144-
(
145-
cd symlink &&
146-
147-
# Make the tree directly to avoid index restrictions.
148-
#
149-
# Because symlinks store the target as a blob, choose
150-
# a pathname that could be parsed as a .gitmodules file
151-
# to trick naive non-symlink-aware checking.
152-
tricky="[foo]bar=true" &&
153-
content=$(git hash-object -w ../.gitmodules) &&
154-
target=$(printf "$tricky" | git hash-object -w --stdin) &&
155-
{
156-
printf "100644 blob $content\t$tricky\n" &&
157-
printf "120000 blob $target\t.gitmodules\n"
158-
} >bad-tree
159-
) &&
160-
tree=$(git -C symlink mktree <symlink/bad-tree)
161-
'
162-
163-
test_expect_success 'fsck detects symlinked .gitmodules file' '
164-
(
165-
cd symlink &&
166-
167-
# Check not only that we fail, but that it is due to the
168-
# symlink detector
169-
test_must_fail git fsck 2>output &&
170-
grep "tree $tree: gitmodulesSymlink" output
171-
)
172-
'
173-
174-
test_expect_success 'refuse to load symlinked .gitmodules into index' '
175-
test_must_fail git -C symlink read-tree $tree 2>err &&
176-
grep "invalid path.*gitmodules" err &&
177-
git -C symlink ls-files >out &&
178-
test_must_be_empty out
179-
'
142+
check_dotx_symlink () {
143+
name=$1
144+
type=$2
145+
path=$3
146+
dir=symlink-$name-$type
147+
148+
test_expect_success "set up repo with symlinked $name ($type)" '
149+
git init $dir &&
150+
(
151+
cd $dir &&
152+
153+
# Make the tree directly to avoid index restrictions.
154+
#
155+
# Because symlinks store the target as a blob, choose
156+
# a pathname that could be parsed as a .gitmodules file
157+
# to trick naive non-symlink-aware checking.
158+
tricky="[foo]bar=true" &&
159+
content=$(git hash-object -w ../.gitmodules) &&
160+
target=$(printf "$tricky" | git hash-object -w --stdin) &&
161+
{
162+
printf "100644 blob $content\t$tricky\n" &&
163+
printf "120000 blob $target\t$path\n"
164+
} >bad-tree
165+
) &&
166+
tree=$(git -C $dir mktree <$dir/bad-tree)
167+
'
168+
169+
test_expect_success "fsck detects symlinked $name ($type)" '
170+
(
171+
cd $dir &&
172+
173+
# Check not only that we fail, but that it is due to the
174+
# symlink detector
175+
test_must_fail git fsck 2>output &&
176+
grep "tree $tree: ${name}Symlink" output
177+
)
178+
'
179+
180+
test_expect_success "refuse to load symlinked $name into index ($type)" '
181+
test_must_fail \
182+
git -C $dir \
183+
-c core.protectntfs \
184+
-c core.protecthfs \
185+
read-tree $tree 2>err &&
186+
grep "invalid path.*$name" err &&
187+
git -C $dir ls-files -s >out &&
188+
test_must_be_empty out
189+
'
190+
}
191+
192+
check_dotx_symlink gitmodules vanilla .gitmodules
193+
check_dotx_symlink gitmodules ntfs ".gitmodules ."
194+
check_dotx_symlink gitmodules hfs ".${u200c}gitmodules"
180195

181196
test_expect_success 'fsck detects non-blob .gitmodules' '
182197
git init non-blob &&

0 commit comments

Comments
 (0)