Fix git init with core.hidedotfiles
cover Fix git init with core.hidedotfiles
This fixes an regression that was not present in Git for Windows's original core.hideDotFiles patch, but in the shape of the core.hideDotFiles patch that made it into git.git.
We fixed it in one big hurry in Git for Windows, and I simply forgot to upstream this right away.
Johannes Schindelin (1):
mingw: respect core.hidedotfiles = false in git-init again
builtin/init-db.c | 6 ++++++ t/t0001-init.sh | 12 ++++++++++++ 2 files changed, 18 insertions(+)
base-commit: 39ffebd23b1ef6830bf86043ef0b5c069d9299a9
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-131%2Fdscho%2Funhidden-git-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-131/dscho/unhidden-git-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/131
Signature · 1 line
gitgitgadget
PATCH 1/1 mingw: respect core.hidedotfiles = false in git-init again
From: Johannes Schindelin <[email protected]>
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.
This fixes https://github.com/git-for-windows/git/issues/789
--- builtin/init-db.c | 6 ++++++ t/t0001-init.sh | 12 ++++++++++++ 2 files changed, 18 insertions(+)
builtin/init-db.c +6 -0
@@ -155,6 +155,9 @@ static int git_init_db_config(const char *k, const char *v, void *cb)if (!strcmp (k,"init.templatedir" ))return git_config_pathname (&init_db_template_dir, k, v); +if (starts_with (k,"core." )) +return platform_core_config (k, v, cb); +return 0 ; }
@@ -361,6 +364,9 @@ int init_db(const char *git_dir, const char *real_git_dir, } startup_info->have_repository =1 ; +/* Just look for `init.templatedir` and `core.hidedotfiles` */ +git_config (git_init_db_config,NULL ); +safe_create_dir (git_dir,0 ); init_is_bare_repository =is_bare_repository ();
t/t0001-init.sh +12 -0
@@ -453,6 +453,18 @@ test_expect_success 're-init from a linked worktree' ' ) ' +test_expect_success MINGW 'core.hidedotfiles = false' ' + git config --global core.hidedotfiles false && + rm -rf newdir && + ( + sane_unset GIT_DIR GIT_WORK_TREE GIT_CONFIG && + mkdir newdir && + cd newdir && + git init + ) && + ! is_hidden newdir/.git +' + test_expect_success MINGW 'redirect std handles' ' GIT_REDIRECT_STDOUT=output.txt git rev-parse --git-dir && test .git = "$(cat output.txt)" &&
Signature · 1 line
gitgitgadget
Re: [PATCH 1/1] mingw: respect core.hidedotfiles = false in git-init again
"Johannes Schindelin via GitGitGadget" <[email protected]>
builtin/init-db.c static int git_init_db_config(const char *k, const char *v, void *cb) · line 162
Quoted 13 lines · writes:
builtin/init-db.c +3
-0@@ -155,6 +155,9 @@ static int git_init_db_config(const char *k, const char *v, void *cb)if (!strcmp (k,"init.templatedir" ))return git_config_pathname (&init_db_template_dir, k, v); +if (starts_with (k,"core." )) +return platform_core_config (k, v, cb); +return 0 ; }
OK. I think this is very much futureproof and a sensible thing to have a "platform_core_config()" call here. That way, we do not have to say the details of what platform specific thing each platform wants when init_db_config works.
builtin/init-db.c int init_db(const char *git_dir, const char *real_git_dir, · line 367
Quoted 5 lines
builtin/init-db.c +1
-0@@ -361,6 +364,9 @@ int init_db(const char *git_dir, const char *real_git_dir, } startup_info->have_repository =1 ; +/* Just look for `init.templatedir` and `core.hidedotfiles` */
And from that point of view, replacing core.hidedotfiles with something like "platform specific core config" would be more appropriate.
builtin/init-db.c int init_db(const char *git_dir, const char *real_git_dir, · line 369
Quoted 2 lines
builtin/init-db.c +2
-0+git_config (git_init_db_config,NULL ); +
We use git_init_db_config from create_default_files(), which is a function called several lines after this point; shouldn't that now be removed from create_default_files()?
Quoted 10 lines
builtin/init-db.c +0
-0safe_create_dir (git_dir,0 ); init_is_bare_repository =is_bare_repository ();t/t0001-init.sh +0
-0@@ -453,6 +453,18 @@ test_expect_success 're-init from a linked worktree' ' ) '
t/t0001-init.sh test_expect_success 're-init from a linked worktree' ' · line 464
Quoted 10 lines
t/t0001-init.sh +9
-0+test_expect_success MINGW 'core.hidedotfiles = false' ' + git config --global core.hidedotfiles false && + rm -rf newdir && + ( + sane_unset GIT_DIR GIT_WORK_TREE GIT_CONFIG && + mkdir newdir && + cd newdir && + git init + ) &&
This is not incorrect per-se, but I think most tests do the mkdir outside subshell, i.e.
rm -rf newdir && mkdir newdir && ( cd newdir && sane_unset ... && ... ) &&
Other than these, I find nothing questionable in the patch. Nicely done.
Re: [PATCH 1/1] mingw: respect core.hidedotfiles = false in git-init again
Hi Junio,
Quoted 11 lines · Junio C Hamano
"Johannes Schindelin via GitGitGadget" <[email protected]>
Quoted 8 lines · writes:
builtin/init-db.c +0
-0@@ -155,6 +155,9 @@ static int git_init_db_config(const char *k, const char *v, void *cb)if (!strcmp (k,"init.templatedir" ))return git_config_pathname (&init_db_template_dir, k, v);
Quoted 10 lines
builtin/init-db.c static int git_init_db_config(const char *k, const char *v, void *cb) · line 162
Quoted 5 lines
builtin/init-db.c +3
-0+if (starts_with (k,"core." )) +return platform_core_config (k, v, cb); +return 0 ; }OK. I think this is very much futureproof and a sensible thing to have a "
platform_core_config()" call here. That way, we do not have to say the details of what platform specific thing each platform wants wheninit_db_configworks.
I am glad you agree.
Quoted 9 lines
builtin/init-db.c int init_db(const char *git_dir, const char *real_git_dir, · line 367
Quoted 5 lines
builtin/init-db.c +1
-0@@ -361,6 +364,9 @@ int init_db(const char *git_dir, const char *real_git_dir, } startup_info->have_repository =1 ; +/* Just look for `init.templatedir` and `core.hidedotfiles` */ And from that point of view, replacing
core.hidedotfileswith something like "platform specific core config" would be more appropriate.
Probably. But it could potentially make some developer (such as myself, six months from now) wonder why we don't just remove this call because clearly nothing uses this on Linux.
So even if it is not quite future-proof from the point of view where we *technically* would have to extend this comment if we ever introduced another platform-specific config setting that is relevant to the early phase of git init, I would like to keep the comment in the current form.
Well, actually *almost* in the current form.
I did realize, based on your comment below, that the mention of init.templatedir here is bogus, wrong even: if git init is started in a Git worktree, we do not *want* to use the init.templatedir setting from said worktree.
And that is the reason why...
Quoted 6 lines
builtin/init-db.c int init_db(const char *git_dir, const char *real_git_dir, · line 369
Quoted 2 lines
builtin/init-db.c +2
-0+git_config (git_init_db_config,NULL ); +We use
git_init_db_configfromcreate_default_files(), which is a function called several lines after this point; shouldn't that now be removed fromcreate_default_files()?
... we have to call git_config() *again* in create_default_files().
Quoted 24 lines
Quoted 10 lines
builtin/init-db.c +0
-0safe_create_dir (git_dir,0 ); init_is_bare_repository =is_bare_repository ();t/t0001-init.sh +0
-0@@ -453,6 +453,18 @@ test_expect_success 're-init from a linked worktree' ' ) 't/t0001-init.sh test_expect_success 're-init from a linked worktree' ' · line 464
Quoted 10 lines
t/t0001-init.sh +9
-0+test_expect_success MINGW 'core.hidedotfiles = false' ' + git config --global core.hidedotfiles false && + rm -rf newdir && + ( + sane_unset GIT_DIR GIT_WORK_TREE GIT_CONFIG && + mkdir newdir && + cd newdir && + git init + ) &&This is not incorrect per-se, but I think most tests do the mkdir outside subshell, i.e.
Quoted 7 lines
rm -rf newdir && mkdir newdir && ( cd newdir && sane_unset ... && ... ) &&
Legit.
Thanks,
Dscho
Quoted 6 lines
Other than these, I find nothing questionable in the patch. Nicely done.
v2 cover Fix git init with core.hidedotfiles
In reply to Johannes Schindelin via GitGitGadgetThis fixes an regression that was not present in Git for Windows's original core.hideDotFiles patch, but in the shape of the core.hideDotFiles patch that made it into git.git.
We fixed it in one big hurry in Git for Windows, and I simply forgot to upstream this right away.
Changes since v1:
* Clarified in the code comment that our intention is to pick up core.hidedotfiles in the first git_config() call.
* Explained in the commit message why we cannot remove the git_config(git_init_db_config, NULL) call from create_default_files(): it would cause a change of behavior with regard to the init.templatedir setting.
* Simplified the test case.
Johannes Schindelin (1):
mingw: respect core.hidedotfiles = false in git-init again
builtin/init-db.c | 7 +++++++ t/t0001-init.sh | 11 +++++++++++ 2 files changed, 18 insertions(+)
base-commit: e902e9bcae2010bc42648c80ab6adc6c5a16a4a5
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-131%2Fdscho%2Funhidden-git-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-131/dscho/unhidden-git-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/131
Range-diff vs v1:
1: 008e367d26 ! 1: f187d0d247 mingw: respect core.hidedotfiles = false in git-init again
@@ -12,6 +12,12 @@
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 https://github.com/git-for-windows/git/issues/789
Signed-off-by: Johannes Schindelin <[email protected]>
@@ -29,11 +35,19 @@
return 0;
}
+@@
+ struct strbuf err = STRBUF_INIT;
+
+ /* Just look for `init.templatedir` */
++ init_db_template_dir = NULL; /* re-set in case it was set before */
+ git_config(git_init_db_config, NULL);
+
+ /*
@@
}
startup_info->have_repository = 1;
-+ /* Just look for `init.templatedir` and `core.hidedotfiles` */
++ /* Just look for `core.hidedotfiles` */
+ git_config(git_init_db_config, NULL);
+
safe_create_dir(git_dir, 0);
@@ -50,11 +64,10 @@
+test_expect_success MINGW 'core.hidedotfiles = false' '
+ git config --global core.hidedotfiles false &&
+ rm -rf newdir &&
++ mkdir newdir &&
+ (
+ sane_unset GIT_DIR GIT_WORK_TREE GIT_CONFIG &&
-+ mkdir newdir &&
-+ cd newdir &&
-+ git init
++ git -C newdir init
+ ) &&
+ ! is_hidden newdir/.git
+'Signature · 1 line
gitgitgadget
PATCH v2 1/1 mingw: respect core.hidedotfiles = false in git-init again
From: Johannes Schindelin <[email protected]>
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 https://github.com/git-for-windows/git/issues/789
--- builtin/init-db.c | 7 +++++++ t/t0001-init.sh | 11 +++++++++++ 2 files changed, 18 insertions(+)
builtin/init-db.c +7 -0
@@ -155,6 +155,9 @@ static int git_init_db_config(const char *k, const char *v, void *cb)if (!strcmp (k,"init.templatedir" ))return git_config_pathname (&init_db_template_dir, k, v); +if (starts_with (k,"core." )) +return platform_core_config (k, v, cb); +return 0 ; }
@@ -185,6 +188,7 @@ static int create_default_files(const char *template_path,struct strbuf err =STRBUF_INIT ;/* Just look for `init.templatedir` */ + init_db_template_dir =NULL ;/* re-set in case it was set before */ git_config (git_init_db_config,NULL );/*
@@ -361,6 +365,9 @@ int init_db(const char *git_dir, const char *real_git_dir, } startup_info->have_repository =1 ; +/* Just look for `core.hidedotfiles` */ +git_config (git_init_db_config,NULL ); +safe_create_dir (git_dir,0 ); init_is_bare_repository =is_bare_repository ();
t/t0001-init.sh +11 -0
@@ -454,6 +454,17 @@ test_expect_success 're-init from a linked worktree' ' ) ' +test_expect_success MINGW 'core.hidedotfiles = false' ' + git config --global core.hidedotfiles false && + rm -rf newdir && + mkdir newdir && + ( + sane_unset GIT_DIR GIT_WORK_TREE GIT_CONFIG && + git -C newdir init + ) && + ! is_hidden newdir/.git +' + test_expect_success MINGW 'redirect std handles' ' GIT_REDIRECT_STDOUT=output.txt git rev-parse --git-dir && test .git = "$(cat output.txt)" &&
Signature · 1 line
gitgitgadget