Skip to content
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

Git integration does not correctly support includeIf directive #40354

Closed
motowilliams opened this issue Dec 16, 2017 · 12 comments
Closed

Git integration does not correctly support includeIf directive #40354

motowilliams opened this issue Dec 16, 2017 · 12 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug git GIT issues help wanted Issues identified as good community contribution opportunities
Milestone

Comments

@motowilliams
Copy link

motowilliams commented Dec 16, 2017

  • VSCode Version: 1.19.0
  • OS Version:Windows10 (version 1709) OS Build 16299.125

Steps to Reproduce:

  1. Update user git configuration to have a includeIf block
[includeIf "gitdir:~/some/path/to/personal/"]
	path = .gitconfig-personal
[includeIf "gitdir:~/some/path/to/work/"]
	path = .gitconfig-work
  1. Create a sample git repo in either your person or work directories
  2. Make a change to a file in your sample repo
  3. Attempt to use VSCode git features to add file to index and commit the file to the local repo.
  4. You will get an error where the log show the following
Looking for git in: C:\Program Files\Git\cmd\git.exe
Using git 2.15.1.windows.2 from C:\Program Files\Git\cmd\git.exe
git rev-parse --show-toplevel
git config --get commit.template
git status -z -u
git symbolic-ref --short HEAD
git rev-parse master
git rev-parse --symbolic-full-name --abbrev-ref master@{u}
fatal: no upstream configured for branch 'master'

[...]

git for-each-ref --format %(refname) %(objectname)
git remote --verbose
git ls-tree -l HEAD -- c:\Users\eric\code\personal\test-redirect\test-httpsredirect.ps1
git show 8ddceeffd5268e6e86e0a0c4eb0562b1b7a5cdd8
git show HEAD:test-httpsredirect.ps1
git add -A -- c:\Users\eric\code\personal\test-redirect\test-httpsredirect.ps1
git status -z -u
git symbolic-ref --short HEAD
git rev-parse master
git rev-parse --symbolic-full-name --abbrev-ref master@{u}
fatal: no upstream configured for branch 'master'

git for-each-ref --format %(refname) %(objectname)
git remote --verbose
git show :test-httpsredirect.ps1
git commit --quiet --allow-empty-message --file -

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'eric@DESKTOP-7O2SA82.(none)')

git config --get-all user.name
git status -z -u
git show :test-httpsredirect.ps1
git symbolic-ref --short HEAD
git rev-parse master
git rev-parse --symbolic-full-name --abbrev-ref master@{u}
fatal: no upstream configured for branch 'master'

git for-each-ref --format %(refname) %(objectname)
git remote --verbose

Reproduces without extensions: Yes

This is NOT a Please tell me who you are issue as indicated by #36368. This feature works as expected with the git cli and well as Visual Studio Team Explorer where it was fixed in issue Team Explorer does not recognize git includeIf directive

@vscodebot vscodebot bot added the git GIT issues label Dec 16, 2017
@joaomoreno
Copy link
Member

It sure seems to be so... This is what git returns:

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'eric@DESKTOP-7O2SA82.(none)')

@joaomoreno
Copy link
Member

What does git config --get-all user.name return, in that folder?

@motowilliams
Copy link
Author

git config --get-all user.name returns Eric Williams in my personal folder and Eric Williams (my company name) in my work folder

@joaomoreno joaomoreno changed the title git integration does not correct support includeIf directive Git integration does not correctly support includeIf directive Dec 20, 2017
@joaomoreno joaomoreno added this to the Backlog milestone Dec 20, 2017
@joaomoreno joaomoreno added bug Issue identified by VS Code Team member as probable bug help wanted Issues identified as good community contribution opportunities labels Dec 20, 2017
@Stuffbutts
Copy link

This issue also effects me and I am using includeif in my global gitconfig.


Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'shadi@DRDIRTYLOVE.(none)')
> git config --get-all user.name
> git rev-parse --show-toplevel
fatal: Not a git repository (or any of the parent directories): .git

@motowilliams
Copy link
Author

@joaomoreno any update on this issue? This is still friction for using the git integration in vscode.

@zhuowei
Copy link
Contributor

zhuowei commented May 22, 2018

@motowilliams I can't seem to reproduce this on macOS: I removed the user.name and user.email from my global .gitconfig, added the includeIf directive, verified that git config user.name picks up the name from the .gitconfig-personal, and tried to commit from VS Code: it worked fine.

$ code-insiders --version
1.24.0-insider
a521c01d56ec7f07bea2471880f28a77f37983af
x64
$ git --version
git version 2.15.1 (Apple Git-101)

is this a Windows specific issue? I'll try testing on Windows and Linux.

Edit: I can reproduce the issue on Windows 10 (1803) and Git for Windows 2.17. I have not tested on Linux. This may be a Windows specific issue.

@zhuowei
Copy link
Contributor

zhuowei commented May 22, 2018

@motowilliams I figured out the issue and have devised a workaround: VS Code passes a lowercase drive letter when launching Git, which somehow breaks the includeIf checking logic.

Thus, just use

[includeIf "gitdir/i:~/path/to/repo/"]

which enables case insensitive compare. This fixes the issue; I was able to commit successfully (Windows 10 1803, Git for Windows 2.17, Version 1.24.0-insider Commit a521c01 Date 2018-05-21T05:18:01.058Z)

I'm not sure whether the lowercase drive letter is coming from. I'll have to see how Git is launched on Windows.


How I found this:

I wrapped Git with a Batch file to see what was passed into Git:

@echo off
echo %* in %cd% >>"C:\Users\zhuowei\mygitlog%1.txt"
git config --list --show-origin >>"C:\Users\zhuowei\mygitlog%1.txt"
"C:\Program Files\Git\cmd\git.exe" %*

And set git.path in VSCode to use this executable. I tried to commit from VSCode, which failed to pick up the includeIf config. Then I ran the wrapper from the command line, and it did pick up the includeIf. I then checked the log:

In VSCode:

config --get-all user.name in c:\Users\zhuowei\Documents\repos\includeIf 

Outside:

config --get-all user.name in C:\Users\zhuowei\Documents\repos\includeIf

Note the difference in the case letter.

zhuowei added a commit to zhuowei/vscode that referenced this issue May 24, 2018
…40354)

Git's includeIf feature by default matches the path against the current
working directory in a case sensitive manner.

VS Code launches Git using a current working directory with a lowercase
drive letter, while everything else uses an uppercase drive letter,
so includeIf directives that work everywhere else don't work in
VS Code.

This commit borrows the fix from microsoft#9448, which manually uppercases the
drive letter for Windows.
@jkanczler
Copy link

That means there's an actual workaround until releasing a new version of VSCode.

Use [includeIf "gitdir/i: in your .gitconfig file, so the include check will be case insensitive.

@alexvy86
Copy link

alexvy86 commented Jul 9, 2018

Can confirm the workaround of using case-insensitive gitdir ([includeIf "gitdir/i:) works, thanks @zhuowei !

@joaomoreno
Copy link
Member

Guys, I can't even get this working on my Windows machine, independent of VS Code. Here's my setup:

~/.gitconfig

[includeIf "gitdir/i:~/Work/vscode"]
	path = ~/.gitconfig-work
[includeIf "gitdir/i:~/Work/inno-updater"]
	path = ~/.gitconfig-personal

~/.gitconfig-personal

[user]
	name = Personal

~/.gitconfig-work

[user]
	name = Work

When running git config --get-all user.name from ~/Work/vscode in both Git Bash and the Command Prompt, git always returns and empty result and returns with 1.

What am I doing wrong?

@zhuowei
Copy link
Contributor

zhuowei commented Sep 13, 2018

@joaomoreno You need a trailing slash in the path.

Try:

[includeIf "gitdir/i:~/Work/vscode/"]

@joaomoreno
Copy link
Member

joaomoreno commented Sep 14, 2018

Thanks @zhuowei, that was it.

I really do think gitdir/i is not only the workaround but the actual proper way to do this. Since the FS is case insensitive, /i needs to be used instead of always changing the drive letter to a specific casing as #50376 attempts to do; this may and will have other consequences.

Closing this.

@vscodebot vscodebot bot locked and limited conversation to collaborators Oct 29, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug git GIT issues help wanted Issues identified as good community contribution opportunities
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants