git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Stuart MacDonald <stuartm.coding@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [Bug report] includeIf config is not displayed in normal directories
Date: Tue, 15 Dec 2020 14:23:17 -0800	[thread overview]
Message-ID: <xmqqczza7lpm.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <CAPQE4+qq11W9VzftJ6y+cbdJ1x64c8Astjwd4z4M-oc5hv1jeA@mail.gmail.com> (Stuart MacDonald's message of "Tue, 15 Dec 2020 10:52:35 -0500")

Stuart MacDonald <stuartm.coding@gmail.com> writes:

> Hello,
>
> I've seen this thread:
> https://public-inbox.org/git/F55DC360-9C1E-45B9-B8BA-39E1001BD620@gmail.com/t/#u
>
> and respectfully disagree with the conclusion. Conditionally included
> configuration can contain items like core.sshCommand that are required
> for git clone while in a normal non-git directory. These should be
> displayed properly so users know what configuration they are operating
> with.

I have a feeling that this just repeats what was said in the quoted
thread.  It is a chicken-and-egg problem that cannot be solved by
use of [includeif "gitdir:*"] pattern, as it won't kick in until
your $(pwd) is associated with a git repository, and before "clone"
or "init", your $(pwd) that is a newly created directory won't be.

> Also, conditionally included config is acted upon despite not being
> displayed. This makes tracking down problems much more difficult.

> $ mkdir ~/work/git-bug-test
> $ cd ~/work/git-bug-test
> $ git config --show-origin --get-all core.sshCommand 
> OBSERVE A: There is no output

This is expected, as [includeif "gitdir:*"] is used and there is no
gitdir associated with the current location (yet).

It _might_ be possible to give "git config" a new option
"--pretend-as-if-cwd-is-the-root-of-a-git-working-tree" and teach it
to read ~/.gitconfig while pretending $(pwd)/.git exists and is a
gitdir, but it won't be as simple as exporting GIT_DIR=$(pwd)/.git,
I suspect.  A lot of other things would break by actually not having
a real repository there.

> $ git clone --recursive git@github.com:git/git.git
> OBSERVE B: The clone succeeds

This may be an unexpected but is an understandable behaviour.

First the command has to create an empty repository with an initial
configuration file, and at that point [includeif "gitdir:*"] match
would notice that there is a gitdir at $(pwd)/.git; by the time the
command actually starts talking to the other side, the repository
specific configuration can be picked up.

> $ cd git
> $ git config --show-origin --get-all core.sshCommand 
> file:C:/Users/stuartm/.gitconfig-work        ssh -i ~/.ssh/id_rsa.stuartm_github
> OBSERVE C: The configuration item is displayed

Of course.  At that point, you have a full fledged repository there.

> $ cd ..
> $ git config --show-origin --get-all core.sshCommand 
> OBSERVE D: There is no output

And you are outside any repository, so there shouldn't be any gitdir
in effect to influence [includeif "gitdir:*"] matching.

Another option, as Peff suggested in the old thread, would be to
introduce a separate [includeif "cwd:*"] match, but I do not know
how well it would fly.  with that, you may be able to

	[includeif "cwd:/home/stuart/work/*"]
		path = ...

I think that may be cleaner than the "pretend we have already a
git-dir here" hack I mentioned earlier, but I didn't think things
through.

THanks.


  parent reply	other threads:[~2020-12-15 22:30 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
2020-12-15 22:23 ` Junio C Hamano [this message]
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=xmqqczza7lpm.fsf@gitster.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --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).