git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [Bug report] includeIf config is not displayed in normal directories

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 15, 2020, 22:23 UTC
Message-ID
<xmqqczza7lpm.fsf@gitster.c.googlers.com>
In-Reply-To
<CAPQE4+qq11W9VzftJ6y+cbdJ1x64c8Astjwd4z4M-oc5hv1jeA@mail.gmail.com>
Stuart MacDonald <stuartm.coding@gmail.com> writes:
Show 10 quoted lines
> 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.
Previous: Stuart MacDonaldNext: Jeff King
Message 2 of 8 in “[Bug report] includeIf config is not displayed in normal directories”
  1. Stuart MacDonaldDec 15, 2020
  2. Junio C HamanoDec 15, 2020
  3. Jeff KingDec 16, 2020
  4. Stuart MacDonaldDec 16, 2020
  5. Junio C HamanoDec 16, 2020
  6. Jeff KingDec 18, 2020
  7. Ævar Arnfjörð BjarmasonDec 15, 2020
  8. Junio C HamanoDec 16, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.