Skip to content

Commit 2878533

Browse files
dschogitster
authored andcommitted
mingw: respect core.hidedotfiles = false in git-init again
This is a brown paper bag. When adding the tests, we actually failed to verify that the config variable is heeded in git-init at all. And when changing the original patch that marked the .git/ directory as hidden after reading the config, it was lost on this developer that the new code would use the hide_dotfiles variable before the config was read. The fix is obvious: read the (limited, pre-init) config *before* creating the .git/ directory. Please note that we cannot remove the identical-looking `git_config()` call from `create_default_files()`: we create the `.git/` directory between those calls. If we removed it, and if the parent directory is in a Git worktree, and if that worktree's `.git/config` contained any `init.templatedir` setting, we would all of a sudden pick that up. This fixes git-for-windows#789 Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6053c04 commit 2878533

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

builtin/init-db.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ static int git_init_db_config(const char *k, const char *v, void *cb)
155155
if (!strcmp(k, "init.templatedir"))
156156
return git_config_pathname(&init_db_template_dir, k, v);
157157

158+
if (starts_with(k, "core."))
159+
return platform_core_config(k, v, cb);
160+
158161
return 0;
159162
}
160163

@@ -185,6 +188,7 @@ static int create_default_files(const char *template_path,
185188
struct strbuf err = STRBUF_INIT;
186189

187190
/* Just look for `init.templatedir` */
191+
init_db_template_dir = NULL; /* re-set in case it was set before */
188192
git_config(git_init_db_config, NULL);
189193

190194
/*
@@ -361,6 +365,9 @@ int init_db(const char *git_dir, const char *real_git_dir,
361365
}
362366
startup_info->have_repository = 1;
363367

368+
/* Just look for `core.hidedotfiles` */
369+
git_config(git_init_db_config, NULL);
370+
364371
safe_create_dir(git_dir, 0);
365372

366373
init_is_bare_repository = is_bare_repository();

t/t0001-init.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,17 @@ test_expect_success 're-init from a linked worktree' '
454454
)
455455
'
456456

457+
test_expect_success MINGW 'core.hidedotfiles = false' '
458+
git config --global core.hidedotfiles false &&
459+
rm -rf newdir &&
460+
mkdir newdir &&
461+
(
462+
sane_unset GIT_DIR GIT_WORK_TREE GIT_CONFIG &&
463+
git -C newdir init
464+
) &&
465+
! is_hidden newdir/.git
466+
'
467+
457468
test_expect_success MINGW 'redirect std handles' '
458469
GIT_REDIRECT_STDOUT=output.txt git rev-parse --git-dir &&
459470
test .git = "$(cat output.txt)" &&

0 commit comments

Comments
 (0)