threads / bug / 55073

Git Conditional Includes Question (possible bug?)

Subject: Git Conditional Includes Question (possible bug?)

## tl;dr

3 messages between Jan 29, 2021 and Jan 31, 2021.

replies: 2people: 2as markdown or json

Colton Hurst· Jan 29, 2021, 21:21 UTC · lore
Hello,
I am attempting to use Git conditional includes, but it does not seem to work for me. Can you please help me find out what I’m doing wrong?

[Expectation] When I run `cd ~/colton/github/coltonhurst.com` (this is a valid git repo) and then run `git config user.email`, I expect ‘colton@coltonhurst.com’ will be returned.

[Actual Result] When I run `cd ~/colton/github/coltonhurst.com` (this is a valid git repo) and then run `git config user.email`, nothing is returned.

Is this correct behavior? It seems like Git is not recognizing my `.gitconfig` file, and the configuration is not set correctly.

I’m using git version 2.30.0 with on a Mac version 11.1 (Big Sur) My main shell is: fish, version 3.1.2 I also have tested & have the same issues using: GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin20)

To reproduce, I have the two files at the listed locations:
`.gitconfig` at: `~/`, with the following contents:
[user]
	name = Colton Hurst
[includeIf "gitdir:~/colton/github"]
	path = ~/colton/github/.gitconfig
[includeIf "gitdir:~/colton/sourcehut"]
	path = ~/colton/sourcehut/.gitconfig
`.gitconfig` at: `~/colton/github`, with the following contents:
[user]
	name = Colton Hurst
	email = colton@coltonhurst.com
This is the output from `git bugreport`:

[System Info] git version: git version 2.30.0 cpu: x86_64 no commit associated with this build sizeof-long: 8 sizeof-size_t: 8 shell-path: /bin/sh uname: Darwin 20.2.0 Darwin Kernel Version 20.2.0: Wed Dec 2 20:39:59 PST 2020; root:xnu-7195.60.75~1/RELEASE_X86_64 x86_64 compiler info: clang: 12.0.0 (clang-1200.0.32.28) libc info: no libc information available $SHELL (typically, interactive shell): /bin/zsh

Thank you for reading,
cdh
Junio C Hamano· Jan 29, 2021, 22:54 UTC · re: Colton Hurst · lore

Re: Git Conditional Includes Question (possible bug?)

Colton Hurst <colton@coltonhurst.com> writes:
Show 7 quoted lines
> [Expectation] When I run `cd ~/colton/github/coltonhurst.com`
> (this is a valid git repo) and then run `git config user.email`, I
> expect ‘colton@coltonhurst.com’ will be returned.
>
> [Actual Result] When I run `cd ~/colton/github/coltonhurst.com`
> (this is a valid git repo) and then run `git config user.email`,
> nothing is returned.
The relevant part of the per-user config are
> [user]
> 	name = Colton Hurst
This is not conditional, and applies when you are in the repository.
> [includeIf "gitdir:~/colton/github"]
> 	path = ~/colton/github/.gitconfig

This is conditional, and applies when you are in a repository whose ".git" location matches the glob pattern "~/colton/github". The location in question is "~/colton/github/coltonhurst.com", which does not match the pattern, so it would be skipped.

> [includeIf "gitdir:~/colton/sourcehut"]
> 	path = ~/colton/sourcehut/.gitconfig
Likewise.

So, nobody sets user.email in your example. Isn't it expected that nothing is returned?

I wonder what happens when the second one is updated to
> [includeIf "gitdir:~/colton/github/"]
> 	path = ~/colton/github/.gitconfig
as "git config --help" says:
 * If the pattern ends with `/`, `**` will be automatically added. For
   example, the pattern `foo/` becomes `foo/**`. In other words, it
   matches "foo" and everything inside, recursively.

and "~/colton/github/**" as a pattern would match the path to the repository in question.

Colton Hurst· Jan 31, 2021, 04:23 UTC · re: Junio C Hamano · lore

Re: Git Conditional Includes Question (possible bug?)

Junio,
Show 8 quoted lines
> as "git config --help" says:
> 
> * If the pattern ends with `/`, `**` will be automatically added. For
>   example, the pattern `foo/` becomes `foo/**`. In other words, it
>   matches "foo" and everything inside, recursively.
> 
> and "~/colton/github/**" as a pattern would match the path to the
> repository in question.
That solved the issue. My email was in the subdirectory config files, but not having the `/` at the end of the path ruined it. Thank you so much for the help!
Have a great day and weekend!
Colton

← back to recent threads