Skip to content

includeIf not working with WSL/Network paths #2563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
Stanzilla opened this issue Mar 29, 2020 · 12 comments
Closed
1 task done

includeIf not working with WSL/Network paths #2563

Stanzilla opened this issue Mar 29, 2020 · 12 comments

Comments

@Stanzilla
Copy link

Stanzilla commented Mar 29, 2020

  • I was not able to find an open or closed issue matching what I'm seeing

Setup

  • Which version of Git for Windows are you using? Is it 32-bit or 64-bit?
$ git --version --build-options

git version 2.26.0.windows.1
cpu: x86_64
built from commit: 9c98e1ccdfd839e4eaae1c2747d0088ef89d446b
sizeof-long: 4
sizeof-size_t: 8
  • Which version of Windows are you running? Vista, 7, 8, 10? Is it 32-bit or 64-bit?
$ cmd.exe /c ver

Microsoft Windows [Version 10.0.19041.172]
  • What options did you set as part of the installation? Or did you choose the
    defaults?
# One of the following:
> type "C:\Program Files\Git\etc\install-options.txt"
> type "C:\Program Files (x86)\Git\etc\install-options.txt"
> type "%USERPROFILE%\AppData\Local\Programs\Git\etc\install-options.txt"
$ cat /etc/install-options.txt

Editor Option: VisualStudioCode
Custom Editor Path:
Path Option: Cmd
SSH Option: OpenSSH
Tortoise Option: false
CURL Option: OpenSSL
CRLF Option: LFOnly
Bash Terminal Option: ConHost
Performance Tweaks FSCache: Enabled
Use Credential Manager: Enabled
Enable Symlinks: Enabled
  • Any other interesting things about your environment that might be related
    to the issue you're seeing?

I'm using this setup

; personal config
[includeIf "gitdir/i:T:/home/stan/projects/personal/"]
    path = .gitconfig-personal

[includeIf "gitdir/i:C:/Users/Stan/projects/personal/"]
    path = .gitconfig-personal

; work config
[includeIf "gitdir/i:T:/home/stan/projects/work/"]
    path = .gitconfig-work

[includeIf "gitdir/i:C:/Users/Stan/projects/work/"]
    path = .gitconfig-work

and the config files get correctly included for projects on the C drive, but not for projects on the T drive. T is a WSL mount. Is there a known issue about WSL compat or am I just doing something wrong?

Details

  • Which terminal/shell are you running Git from? e.g Bash/CMD/PowerShell/other

PowerShell / Cmd

git config user.email
  • What did you expect to occur after running these commands?

the correct email

  • What actually happened instead?

no email

  • If the problem was occurring with a specific repository, can you provide the
    URL to that repository to help us with testing?

N/A

@dscho
Copy link
Member

dscho commented Mar 30, 2020

T is a WSL mount.

What is the output of git rev-parse --absolute-git-dir in T:/home/stan/project/work/?

A recent Git for Windows version started to resolve symbolic links/mount points/whatever when trying to canonicalize absolute directories, and that most likely changed the behavior of the includeIf for you.

@Stanzilla
Copy link
Author

Stanzilla commented Mar 30, 2020

That gives //wsl$/Ubuntu/home/stan/.git

Sadly switching to

; work config
[includeIf "gitdir/i://wsl$/Ubuntu/home/stan/projects/work/"]
    path = .gitconfig-work

doesn't work either :/

@dscho
Copy link
Member

dscho commented Mar 30, 2020

Those two paths look different to me... one ends in /.git, the other doesn't...

@Stanzilla
Copy link
Author

According to the docs (https://git-scm.com/docs/git-config#_conditional_includes) this should work though? I want every folder inside of /work/ to use the work gitconfig etc.

@dscho
Copy link
Member

dscho commented Mar 31, 2020

Maybe you can build Git for Windows, start it in gdb and set a breakpoint on the relevant code?

@dscho
Copy link
Member

dscho commented Mar 31, 2020

git/config.c

Line 244 in 9c98e1c

if (!icase && strncmp(pattern.buf, text.buf, prefix))
should be the best location for said breakpoint.

@Stanzilla
Copy link
Author

that's sadly a bit out of my capabilities

@Stanzilla
Copy link
Author

This is sadly still an issue, is there any other way I can help get this fixed without providing a PR?

@dscho
Copy link
Member

dscho commented Apr 22, 2021

; work config
[includeIf "gitdir/i://wsl$/Ubuntu/home/stan/projects/work/"]
    path = .gitconfig-work

I should have spotted this right away, sorry. There are two problems with this:

  • this is not the path to the gitdir, it is the path to the top-level directory of the main worktree. If you append /.git, it should work
  • the path you provide is relative, which in the case of includeIf.<cond>.path means: relative to the gitdir. Since you most likely put this file into the worktree, you need to prefix it with ../. Note that Git will not complain about a missing file, giving you no indication that you used an incorrect path.

In short, I think that this should work for you:

; work config
[includeIf "gitdir/i://wsl$/Ubuntu/home/stan/projects/work/.git"]
    path = ../.gitconfig-work

@dscho
Copy link
Member

dscho commented Apr 22, 2021

In short, I think that this should work for you:

; work config
[includeIf "gitdir/i://wsl$/Ubuntu/home/stan/projects/work/.git"]
    path = ../.gitconfig-work

Whoops, I forgot one crucial thing. For technical reasons, Git for Windows assumes paths starting with a single slash to be relative to the MSYS2 root (i.e. the directory into which Git for Windows was installed, usually C:\Program Files\Git). If really a single slash was meant, it has to be doubled, as per MSYS2's convention. Which means that your //wsl$ is mistaken for meaning /wsl$. You need to use three slashes:

; work config
[includeIf "gitdir/i:///wsl$/Ubuntu/home/stan/projects/work/.git"]
    path = ../.gitconfig-work
  • this is not the path to the gitdir, it is the path to the top-level directory of the main worktree

Actually, that is an assumption on my part that might not even be true, if you have multiple worktrees inside that directory.

Note, however, that the gitdir/i:<pattern> condition uses a wildcard pattern, read: you could say "gitdir/i://wsl$/Ubuntu/home/stan/projects/work/**".

Also note that the path value, if relative, is actually relative to the directory in which the config file lives that contains that includeIf setting (I said previously that it is relative to the gitdir, which is incorrect). That is, if you configure this in ~/.gitconfig (which I assume you do, otherwise you would already know precisely what your gitdir is and would not have to have a conditional include), the value .gitconfig-work would mean that the file ~/.gitconfig-work would be read.

@Stanzilla
Copy link
Author

Stanzilla commented Apr 22, 2021

Okay thank you for the explanation, my head hurts a bit but that is fine.

So my setup now is:

.gitconfig in C:\Users\Stan

This contains:

[includeIf "gitdir/i:///wsl$/Ubuntu/home/stan/projects/personal/**"]
    path = .gitconfig-personal

[includeIf "gitdir/i:///wsl$/Ubuntu/home/stan/projects/work/**"]
    path = .gitconfig-work

Both .gitconfig-personal and .gitconfig-work are also in C:\Users\Stan.

So, now every project in home/stan/projects/personal/ should use the personal config and the ones in work, the work one, correct? At least on the command line, this seems to work! The extra / is definitely what tripped me up here, so thank you so much for clearing that up.

@dscho
Copy link
Member

dscho commented Apr 23, 2021

So, now every project in home/stan/projects/personal/ should use the personal config and the ones in work, the work one, correct?

Correct.

At least on the command line, this seems to work!

Great!

The extra / is definitely what tripped me up here, so thank you so much for clearing that up.

Yes, I can see how that is confusing, especially since you think you're working in WSL, but then, you still use Git for Windows ;-)

There is probably a lot of room for improvement when it comes to offering debugging capabilities in the includeIf machinery. Please do feel free to open a ticket at https://github.com/gitgitgadget/git/issues/new about this (not here, because it is not a Windows-specific issue).

As to this here ticket: I think it is resolved, so I will close it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants