Repository: vscode
Issue: Git - Source Control tab doesn't respect global .gitignore for Git repositories
Labels: bug,git

<!-- ⚠️⚠️ Do Not Delete This! bug_report_template ⚠️⚠️ -->
<!-- Please read our Rules of Conduct: https://opensource.microsoft.com/codeofconduct/ -->
<!-- 🕮 Read our guide about submitting issues: https://github.com/microsoft/vscode/wiki/Submitting-Bugs-and-Suggestions -->
<!-- 🔎 Search existing issues to avoid creating duplicates. -->
<!-- 🧪 Test using the latest Insiders build to see if your issue has already been fixed: https://code.visualstudio.com/insiders/ -->
<!-- 💡 Instead of creating your report here, use 'Report Issue' from the 'Help' menu in VS Code to pre-fill useful information. -->
<!-- 🔧 Launch with `code --disable-extensions` to check. -->
Does this issue occur when all extensions are disabled?:

  No, because the "Source Control" tab does not show Git information with extensions disabled.

<!-- 🪓 If you answered No above, use 'Help: Start Extension Bisect' from Command Palette to try to identify the cause. -->
<!-- 📣 Issues caused by an extension need to be reported directly to the extension publisher. The 'Help > Report Issue' dialog can assist with this. -->
- VS Code Version:   1.87.0
- OS Version:   Windows 11, enumerated as "Windows_NT x64 10.0.22631" in Help->About

Issue:  In my day-to-day use of VSCode, I am developing code in a Git repository using a build system that generates output files in subdirectories adjacent to the source code.  For Git to operate in a sane manner, I need to use ".gitignore" (core.excludesfile) to tell Git to ignore these directories/files.  Since I have many separate trees/repositories, I use a single .gitignore-global file in my home directory in my global .gitconfig file to avoid having to create separate .gitignore files in each repository.

When I launch VSCode in any directory of one of these repositories, it shows a warning dialog in the lower right that says my repo "has too many active changes".  When I click on the source control tab on the left side toolbar, it shows 10000+ pending changes, even when "git status" reports no pending edits.  All of the files enumerated in that tab should be covered by the global .gitignore file.  However, it appears that the VSCode (or Git extension) logic managing the Source Control tab ignores the global .gitignore file.

Steps to Reproduce:

(1) Create a new Git repository (I started in C:/home/pbrown/junk):

$ git init test
$ cd test
$ touch a
$ mkdir b
$ touch b/c

(2) Create a local .gitignore file in the root of "test" whose contents are shown below:

$ cat .gitignore
.gitignore
.gitignore-global
a
b/

(3) Note that "git status" reports nothing to commit.

$ git status
On branch master
No commits yet
nothing to commit (create/copy files and use "git add" to track)

(4) Launch VSCode in "test":

$ code

Go to the "Source Control" tab, using the third button on the toolbar on the left of VS code and note that no pending changes are reported.  Everything works as expected with a local ".gitignore" file.

(5) Rename the file to ".gitignore-global" and ensure you have no global excludes file.  In this case, note that Git reports three untracked files.

$ mv .gitignore .gitignore-global
$ git config --global --unset core.excludesfile
$ git status
On branch master
No commits yet
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        .gitignore-global
        a
        b/

(6) Switch back to VSCode, which now reports the same three untracked files as "Changes" in the "Source Control" tab.

(7) Configure Git to use ".gitignore-global" as the global excludes file and note that the untracked files are now ignored.

$ git config --global core.excludesfile C:/home/pbrown/junk/test/.gitignore-global
$ git status
On branch master
No commits yet
nothing to commit (create/copy files and use "git add" to track)

(8) Switch back to VSCode and note that the three files from (5) and (6) are still being reported.  This situation persists even if you terminate and restart VSCode.

The desired behavior is obviously to have the "Source Control" tab not display any of the ignored files.

Note also that Git supports the use of "\~" to identify the user's HOME directory in the core.excludesfile setting.  If VSCode could support that also, that would be great.  I normally use "~/.gitignore-global" for this setting but could use a full path with forward slashes ("c:/home/pbrown/.gitignore-global") or escaped backslashes ("c:\\home\\pbrown\\.gitignore-global") if necessary.

While researching this issue, I came across the setting "Search: Use Global Ignore Files" in VSCode settings.  That seemed like it could be relevant, but enabling it (and "Search: Use Ignore Files") had no effect on the Source Control tab.  I suppose that just affects search in the project.