threads / patch / 50678

patchFix git init with core.hidedotfiles

Subject: [PATCH 0/1] Fix git init with core.hidedotfiles

## tl;dr

6 messages between Mar 7, 2019 and Mar 11, 2019. Diffs are folded; open one to read it.

replies: 5people: 2as markdown or json

Johannes Schindelin via GitGitGadget· Mar 7, 2019, 09:35 UTC · lore

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
-- 
gitgitgadget
Johannes Schindelin via GitGitGadget· Mar 7, 2019, 09:35 UTC · re: Johannes Schindelin via GitGitGadget · lore

[PATCH 1/1] mingw: respect core.hidedotfiles = false in git-init again

From: Johannes Schindelin <johannes.schindelin@gmx.de>

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
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 builtin/init-db.c |  6 ++++++
 t/t0001-init.sh   | 12 ++++++++++++
 2 files changed, 18 insertions(+)
Show changes to 2 files +18 −0

builtin/init-db.c, t/t0001-init.sh

diff --git a/builtin/init-db.c b/builtin/init-db.c
index 93eff7618c..94df241ad5 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -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();
diff --git a/t/t0001-init.sh b/t/t0001-init.sh
index 42a263cada..35ede1b0b0 100755
--- a/t/t0001-init.sh
+++ b/t/t0001-init.sh
@@ -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)" &&
-- 
gitgitgadget
Junio C Hamano· Mar 8, 2019, 03:18 UTC · re: Johannes Schindelin via GitGitGadget · lore

Re: [PATCH 1/1] mingw: respect core.hidedotfiles = false in git-init again

"Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com> writes:

Show 13 quoted lines
> diff --git a/builtin/init-db.c b/builtin/init-db.c
> index 93eff7618c..94df241ad5 100644
> --- a/builtin/init-db.c
> +++ b/builtin/init-db.c
> @@ -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.

Show 5 quoted lines
> @@ -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.

> +	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()?

Show 20 quoted lines
>  	safe_create_dir(git_dir, 0);
>  
>  	init_is_bare_repository = is_bare_repository();
> diff --git a/t/t0001-init.sh b/t/t0001-init.sh
> index 42a263cada..35ede1b0b0 100755
> --- a/t/t0001-init.sh
> +++ b/t/t0001-init.sh
> @@ -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
> +	) &&

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.

Johannes Schindelin· Mar 11, 2019, 19:56 UTC · re: Junio C Hamano · lore

Re: [PATCH 1/1] mingw: respect core.hidedotfiles = false in git-init again

Hi Junio,
On Fri, 8 Mar 2019, Junio C Hamano wrote:
Show 21 quoted lines
> "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
> writes:
> 
> > diff --git a/builtin/init-db.c b/builtin/init-db.c
> > index 93eff7618c..94df241ad5 100644
> > --- a/builtin/init-db.c
> > +++ b/builtin/init-db.c
> > @@ -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.
I am glad you agree.
Show 9 quoted lines
> > @@ -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.

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...
Show 6 quoted lines
> > +	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()?
... we have to call `git_config()` *again* in `create_default_files()`.
Show 31 quoted lines
> >  	safe_create_dir(git_dir, 0);
> >  
> >  	init_is_bare_repository = is_bare_repository();
> > diff --git a/t/t0001-init.sh b/t/t0001-init.sh
> > index 42a263cada..35ede1b0b0 100755
> > --- a/t/t0001-init.sh
> > +++ b/t/t0001-init.sh
> > @@ -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
> > +	) &&
> 
> 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 ... &&
> 		...
> 	) &&
Legit.

Thanks, Dscho

Show 6 quoted lines
> 
> Other than these, I find nothing questionable in the patch.  Nicely
> done.
> 
> 
> 
Johannes Schindelin via GitGitGadget· Mar 11, 2019, 20:10 UTC · re: Johannes Schindelin via GitGitGadget · lore

[PATCH v2 0/1] 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.

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 <johannes.schindelin@gmx.de>
     @@ -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
      +'
-- 
gitgitgadget
Johannes Schindelin via GitGitGadget· Mar 11, 2019, 20:10 UTC · re: Johannes Schindelin via GitGitGadget · lore

[PATCH v2 1/1] mingw: respect core.hidedotfiles = false in git-init again

From: Johannes Schindelin <johannes.schindelin@gmx.de>

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
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 builtin/init-db.c |  7 +++++++
 t/t0001-init.sh   | 11 +++++++++++
 2 files changed, 18 insertions(+)
Show changes to 2 files +18 −0

builtin/init-db.c, t/t0001-init.sh

diff --git a/builtin/init-db.c b/builtin/init-db.c
index 93eff7618c..190754ba39 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -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();
diff --git a/t/t0001-init.sh b/t/t0001-init.sh
index 5e27604b24..1f462204ea 100755
--- a/t/t0001-init.sh
+++ b/t/t0001-init.sh
@@ -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)" &&
-- 
gitgitgadget

← back to recent threads