Skip to content

Commit e4034df

Browse files
committed
path: protect NTFS everywhere
Enable core.protectNTFS by default everywhere and in every codepath, not just on checkout.
1 parent d9c0c9c commit e4034df

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

src/checkout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,7 @@ static int checkout_verify_paths(
12711271
int action,
12721272
git_diff_delta *delta)
12731273
{
1274-
unsigned int flags = GIT_PATH_REJECT_WORKDIR_DEFAULTS | GIT_PATH_REJECT_DOT_GIT_NTFS;
1274+
unsigned int flags = GIT_PATH_REJECT_WORKDIR_DEFAULTS;
12751275

12761276
if (action & CHECKOUT_ACTION__REMOVE) {
12771277
if (!git_path_isvalid(repo, delta->old_file.path, delta->old_file.mode, flags)) {

src/path.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,7 +1832,7 @@ GIT_INLINE(unsigned int) dotgit_flags(
18321832
git_repository *repo,
18331833
unsigned int flags)
18341834
{
1835-
int protectHFS = 0, protectNTFS = 0;
1835+
int protectHFS = 0, protectNTFS = 1;
18361836
int error = 0;
18371837

18381838
flags |= GIT_PATH_REJECT_DOT_GIT_LITERAL;
@@ -1841,16 +1841,12 @@ GIT_INLINE(unsigned int) dotgit_flags(
18411841
protectHFS = 1;
18421842
#endif
18431843

1844-
#ifdef GIT_WIN32
1845-
protectNTFS = 1;
1846-
#endif
1847-
18481844
if (repo && !protectHFS)
18491845
error = git_repository__configmap_lookup(&protectHFS, repo, GIT_CONFIGMAP_PROTECTHFS);
18501846
if (!error && protectHFS)
18511847
flags |= GIT_PATH_REJECT_DOT_GIT_HFS;
18521848

1853-
if (repo && !protectNTFS)
1849+
if (repo)
18541850
error = git_repository__configmap_lookup(&protectNTFS, repo, GIT_CONFIGMAP_PROTECTNTFS);
18551851
if (!error && protectNTFS)
18561852
flags |= GIT_PATH_REJECT_DOT_GIT_NTFS;

src/repository.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ typedef enum {
113113
/* core.protectHFS */
114114
GIT_PROTECTHFS_DEFAULT = GIT_CONFIGMAP_FALSE,
115115
/* core.protectNTFS */
116-
GIT_PROTECTNTFS_DEFAULT = GIT_CONFIGMAP_FALSE,
116+
GIT_PROTECTNTFS_DEFAULT = GIT_CONFIGMAP_TRUE,
117117
/* core.fsyncObjectFiles */
118118
GIT_FSYNCOBJECTFILES_DEFAULT = GIT_CONFIGMAP_FALSE,
119119
} git_configmap_value;

tests/index/tests.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,21 @@ void test_index_tests__honors_protect_filesystems(void)
765765
cl_fixture_cleanup("invalid");
766766
}
767767

768+
void test_index_tests__protectntfs_on_by_default(void)
769+
{
770+
git_repository *repo;
771+
772+
p_mkdir("invalid", 0700);
773+
774+
cl_git_pass(git_repository_init(&repo, "./invalid", 0));
775+
assert_write_fails(repo, ".git./hello");
776+
assert_write_fails(repo, "git~1/hello");
777+
778+
git_repository_free(repo);
779+
780+
cl_fixture_cleanup("invalid");
781+
}
782+
768783
void test_index_tests__remove_entry(void)
769784
{
770785
git_repository *repo;

0 commit comments

Comments
 (0)