git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: Stuart MacDonald <stuartm.coding@gmail.com>,
	git@vger.kernel.org, Raphael Stolt <raphael.stolt@gmail.com>,
	Sebastian Schuberth <sschuberth@gmail.com>,
	Jeff King <peff@peff.net>
Subject: Re: [Bug report] includeIf config is not displayed in normal directories
Date: Tue, 15 Dec 2020 16:23:34 -0800	[thread overview]
Message-ID: <xmqq4kkm7g55.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <875z52wu2a.fsf@evledraar.gmail.com> ("Ævar Arnfjörð Bjarmason"'s message of "Wed, 16 Dec 2020 00:03:41 +0100")

Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:

> But it's not a "no" until that point (and not even then, maybe we can
> keep the general idea of Y, but have Z which is mostly the same & works
> for most people), it's just "nobody's really worked on it yet".

Thanks for spelling these out.

Here is my snack-time hack to add the --pretend-gitdir option to "git
config".  It _might_ not be a bad idea to trigger this behaviour
(using $(pwd)/.git as the pretended directory path) automatically
when do not have a repository, but that would certainly be a
compatibility breaking change and would break existing workflow.

Only very lightly tested, and certainly not ready for inclusion (it
does not even have a doc update).


 builtin/config.c          |  4 ++++
 config.c                  |  2 ++
 config.h                  |  1 +
 t/t1305-config-include.sh | 21 +++++++++++++++++++++
 4 files changed, 28 insertions(+)

diff --git c/builtin/config.c w/builtin/config.c
index f71fa39b38..2603dc448c 100644
--- c/builtin/config.c
+++ w/builtin/config.c
@@ -30,6 +30,7 @@ static int use_worktree_config;
 static struct git_config_source given_config_source;
 static int actions, type;
 static char *default_value;
+static char *pretend_gitdir;
 static int end_nul;
 static int respect_includes_opt = -1;
 static struct config_options config_options;
@@ -165,6 +166,7 @@ static struct option builtin_config_options[] = {
 	OPT_BOOL(0, "show-origin", &show_origin, N_("show origin of config (file, standard input, blob, command line)")),
 	OPT_BOOL(0, "show-scope", &show_scope, N_("show scope of config (worktree, local, global, system, command)")),
 	OPT_STRING(0, "default", &default_value, N_("value"), N_("with --get, use default value when missing entry")),
+	OPT_FILENAME(0, "pretend-gitdir", &pretend_gitdir, N_("when outside a repository, pretend this is the gitdir")),
 	OPT_END(),
 };
 
@@ -732,6 +734,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
 		config_options.commondir = get_git_common_dir();
 		config_options.git_dir = get_git_dir();
 	}
+	if (pretend_gitdir)
+		config_options.pretend_gitdir = pretend_gitdir;
 
 	if (end_nul) {
 		term = '\0';
diff --git c/config.c w/config.c
index 1137bd73af..d8d406ecda 100644
--- c/config.c
+++ w/config.c
@@ -224,6 +224,8 @@ static int include_by_gitdir(const struct config_options *opts,
 
 	if (opts->git_dir)
 		git_dir = opts->git_dir;
+	else if (opts->pretend_gitdir)
+		git_dir = opts->pretend_gitdir;
 	else
 		goto done;
 
diff --git c/config.h w/config.h
index c1449bb790..14e8d8c576 100644
--- c/config.h
+++ w/config.h
@@ -89,6 +89,7 @@ struct config_options {
 	unsigned int system_gently : 1;
 	const char *commondir;
 	const char *git_dir;
+	const char *pretend_gitdir;
 	config_parser_event_fn_t event_fn;
 	void *event_fn_data;
 	enum config_error_action {
diff --git c/t/t1305-config-include.sh w/t/t1305-config-include.sh
index f1e1b289f9..883762ad36 100755
--- c/t/t1305-config-include.sh
+++ w/t/t1305-config-include.sh
@@ -162,6 +162,27 @@ test_expect_success 'relative includes from stdin line fail' '
 	test_must_fail git config --file - test.one
 '
 
+test_expect_success 'conditional include, pretend gitdir' '
+	test_when_finished "git config --global --unset-all \"includeif.gitdir:*.path\"" &&
+	git config --global "includeif.gitdir:*.path" included &&
+
+	git config --file included "custom.variable" value &&
+	echo value >expect &&
+
+	# in the TRASH repository
+	git config --get custom.variable >actual &&
+	test_cmp expect actual &&
+
+	# nongit without pretend should not find stuff from included
+	nongit test_must_fail git config --get custom.variable >actual &&
+	test_must_be_empty actual &&
+
+	# nongit with pretend should find stuff from included
+	nongit git config --pretend-gitdir "$(pwd)/.git" \
+		--get custom.variable >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'conditional include, both unanchored' '
 	git init foo &&
 	(

  reply	other threads:[~2020-12-16  0:28 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-15 15:52 [Bug report] includeIf config is not displayed in normal directories Stuart MacDonald
2017-05-11 18:53 ` Possible bug in includeIf / conditional includes on non git initialised directories Raphael Stolt
2017-05-11 20:31   ` Sebastian Schuberth
2017-05-11 23:43     ` Jeff King
2017-05-12  8:58   ` Ævar Arnfjörð Bjarmason
2020-12-15 23:03     ` [Bug report] includeIf config is not displayed in normal directories Ævar Arnfjörð Bjarmason
2020-12-16  0:23       ` Junio C Hamano [this message]
2020-12-15 22:23 ` Junio C Hamano
2020-12-16 19:24   ` Jeff King
2020-12-16 20:43     ` Stuart MacDonald
2020-12-16 23:24       ` Junio C Hamano
2020-12-18  6:23         ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq4kkm7g55.fsf@gitster.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    --cc=raphael.stolt@gmail.com \
    --cc=sschuberth@gmail.com \
    --cc=stuartm.coding@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).