fsck: complain about NTFS ".git" aliases in trees
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Wed, 10 Dec 2014 21:28:27 +0000 (22:28 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 17 Dec 2014 19:04:45 +0000 (11:04 -0800)
Now that the index can block pathnames that can be mistaken
to mean ".git" on NTFS and FAT32, it would be helpful for
fsck to notice such problematic paths. This lets servers
which use receive.fsckObjects block them before the damage
spreads.

Note that the fsck check is always on, even for systems
without core.protectNTFS set. This is technically more
restrictive than we need to be, as a set of users on ext4
could happily use these odd filenames without caring about
NTFS.

However, on balance, it's helpful for all servers to block
these (because the paths can be used for mischief, and
servers which bother to fsck would want to stop the spread
whether they are on NTFS themselves or not), and hardly
anybody will be affected (because the blocked names are
variants of .git or git~1, meaning mischief is almost
certainly what the tree author had in mind).

Ideally these would be controlled by a separate
"fsck.protectNTFS" flag. However, it would be much nicer to
be able to enable/disable _any_ fsck flag individually, and
any scheme we choose should match such a system. Given the
likelihood of anybody using such a path in practice, it is
not unreasonable to wait until such a system materializes.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
fsck.c
t/t1450-fsck.sh
diff --git a/fsck.c b/fsck.c
index b49113bf0ebf1c0532727d3758c29c3fb60cde48..0b76de6f68fa748f789d1405d29da5fb175f80ff 100644 (file)
--- a/fsck.c
+++ b/fsck.c
@@ -176,7 +176,8 @@ static int fsck_tree(struct tree *item, int strict, fsck_error error_func)
                        has_dot = 1;
                if (!strcmp(name, ".."))
                        has_dotdot = 1;
-               if (!strcasecmp(name, ".git") || is_hfs_dotgit(name))
+               if (!strcasecmp(name, ".git") || is_hfs_dotgit(name) ||
+                               is_ntfs_dotgit(name))
                        has_dotgit = 1;
                has_zero_pad |= *(char *)desc.buffer == '0';
                update_tree_entry(&desc);
index 8158b98e6f9ad84b7e0d02e1f1c89d733dae53ac..6edd99a81ef235808ffd36327813ccf1e8832e06 100755 (executable)
@@ -251,10 +251,10 @@ while read name path pretty; do
                        tree=$(git rev-parse HEAD^{tree}) &&
                        value=$(eval "echo \$$type") &&
                        printf "$mode $type %s\t%s" "$value" "$path" >bad &&
-                       git mktree <bad &&
+                       bad_tree=$(git mktree <bad) &&
                        git fsck 2>out &&
                        cat out &&
-                       grep "warning.*\\." out
+                       grep "warning.*tree $bad_tree" out
                )'
        done <<-\EOF
        100644 blob
@@ -266,6 +266,11 @@ dotdot ..
 dotgit .git
 dotgit-case .GIT
 dotgit-unicode .gI${u200c}T .gI{u200c}T
+dotgit-case2 .Git
+git-tilde1 git~1
+dotgitdot .git.
+dot-backslash-case .\\\\.GIT\\\\foobar
+dotgit-case-backslash .git\\\\foobar
 EOF
 
 test_done