зеркало из https://github.com/microsoft/git.git
fsck: complain when .gitmodules is a symlink
We've recently forbidden .gitmodules to be a symlink in verify_path(). And it's an easy way to circumvent our fsck checks for .gitmodules content. So let's complain when we see it. Signed-off-by: Jeff King <peff@peff.net>
This commit is contained in:
Родитель
73c3f0f704
Коммит
b7b1fca175
11
fsck.c
11
fsck.c
|
@ -63,6 +63,7 @@ static struct oidset gitmodules_done = OIDSET_INIT;
|
||||||
FUNC(GITMODULES_BLOB, ERROR) \
|
FUNC(GITMODULES_BLOB, ERROR) \
|
||||||
FUNC(GITMODULES_PARSE, ERROR) \
|
FUNC(GITMODULES_PARSE, ERROR) \
|
||||||
FUNC(GITMODULES_NAME, ERROR) \
|
FUNC(GITMODULES_NAME, ERROR) \
|
||||||
|
FUNC(GITMODULES_SYMLINK, ERROR) \
|
||||||
/* warnings */ \
|
/* warnings */ \
|
||||||
FUNC(BAD_FILEMODE, WARN) \
|
FUNC(BAD_FILEMODE, WARN) \
|
||||||
FUNC(EMPTY_NAME, WARN) \
|
FUNC(EMPTY_NAME, WARN) \
|
||||||
|
@ -576,8 +577,14 @@ static int fsck_tree(struct tree *item, struct fsck_options *options)
|
||||||
has_dotgit |= is_hfs_dotgit(name) || is_ntfs_dotgit(name);
|
has_dotgit |= is_hfs_dotgit(name) || is_ntfs_dotgit(name);
|
||||||
has_zero_pad |= *(char *)desc.buffer == '0';
|
has_zero_pad |= *(char *)desc.buffer == '0';
|
||||||
|
|
||||||
if (is_hfs_dotgitmodules(name) || is_ntfs_dotgitmodules(name))
|
if (is_hfs_dotgitmodules(name) || is_ntfs_dotgitmodules(name)) {
|
||||||
oidset_insert(&gitmodules_found, oid);
|
if (!S_ISLNK(mode))
|
||||||
|
oidset_insert(&gitmodules_found, oid);
|
||||||
|
else
|
||||||
|
retval += report(options, &item->object,
|
||||||
|
FSCK_MSG_GITMODULES_SYMLINK,
|
||||||
|
".gitmodules is a symbolic link");
|
||||||
|
}
|
||||||
|
|
||||||
if (update_tree_entry_gently(&desc)) {
|
if (update_tree_entry_gently(&desc)) {
|
||||||
retval += report(options, &item->object, FSCK_MSG_BAD_TREE, "cannot be parsed as a tree");
|
retval += report(options, &item->object, FSCK_MSG_BAD_TREE, "cannot be parsed as a tree");
|
||||||
|
|
|
@ -122,4 +122,33 @@ test_expect_success 'transfer.fsckObjects handles odd pack (index)' '
|
||||||
test_must_fail git -C dst.git index-pack --strict --stdin <odd.pack
|
test_must_fail git -C dst.git index-pack --strict --stdin <odd.pack
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'fsck detects symlinked .gitmodules file' '
|
||||||
|
git init symlink &&
|
||||||
|
(
|
||||||
|
cd symlink &&
|
||||||
|
|
||||||
|
# Make the tree directly to avoid index restrictions.
|
||||||
|
#
|
||||||
|
# Because symlinks store the target as a blob, choose
|
||||||
|
# a pathname that could be parsed as a .gitmodules file
|
||||||
|
# to trick naive non-symlink-aware checking.
|
||||||
|
tricky="[foo]bar=true" &&
|
||||||
|
content=$(git hash-object -w ../.gitmodules) &&
|
||||||
|
target=$(printf "$tricky" | git hash-object -w --stdin) &&
|
||||||
|
tree=$(
|
||||||
|
{
|
||||||
|
printf "100644 blob $content\t$tricky\n" &&
|
||||||
|
printf "120000 blob $target\t.gitmodules\n"
|
||||||
|
} | git mktree
|
||||||
|
) &&
|
||||||
|
commit=$(git commit-tree $tree) &&
|
||||||
|
|
||||||
|
# Check not only that we fail, but that it is due to the
|
||||||
|
# symlink detector; this grep string comes from the config
|
||||||
|
# variable name and will not be translated.
|
||||||
|
test_must_fail git fsck 2>output &&
|
||||||
|
grep gitmodulesSymlink output
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|
Загрузка…
Ссылка в новой задаче