Repository: vscode
Issue: Git - repository auto-detection not working for junctions on windows
Labels: bug,git


Issue Type: <b>Bug</b>

My current use-case is a multi-root workspace, where one of the workspaces (a source workspace) contains junctions that point to git worktree folders. Since last few releases, the Source Control tab doesn't detect any of the repositories that are in a junction until I open a file from the repository. A repository is detected only after I open a file from that repository (auto-detection via parent folders for opened file). So, for 10 repositories, I'd have to open one file from each repository to populate the source control tab correctly.

I was able to simplify the issue scenario to the following:

1. Create git repositories in folders like: 'C:/repos/r1', 'C:/repos/r2',...
2. Create a folder for VS workspace (e.g. 'C:/ws') and create junctions in it pointing to repositories. e.g. 'C:/ws/j1 -> C:/repos/r1', 'C:/ws/j2 -> C:/repos/r2',...
3. Open VS Code in the workspace folder (i.e. 'C:/ws' in this example).
4. Wait until workspace is loaded and switch to Source Control tab.
5. None of the repositories are detected.
6. Switch back to Explorer tab and open a file from one of the subfolders.
7. Switch to Source Control tab and you'll notice that the git repository for that file has been detected. The others are still undetected until their files are opened as well.


VS Code version: Code 1.65.1 (8908a9ca0f221f36507231afb39d2d8d1e182702, 2022-03-08T02:06:27.846Z)
OS version: Windows_NT x64 10.0.19044
Restricted Mode: No

<details><summary>Extensions (63)</summary>

Extension|Author (truncated)|Version
---|---|---
better-comments|aar|2.1.0
urscript|Ahe|0.1.9
Bookmarks|ale|13.2.4
cpp-helper|ami|0.3.1
qml-formatter|And|1.2.4
Doxygen|bbe|1.0.0
vagrant|bbe|0.5.0
proto3-nav|bri|0.2.2
doxdocgen|csc|1.4.0
vscode-eslint|dba|2.2.2
githistory|don|0.6.19
xml|Dot|2.5.1
clipboard-manager|Edg|1.4.2
felgo|fel|1.0.3
cmake-test-adapter|fre|0.15.4
vscode-pull-request-github|Git|0.38.0
gitkraken-authentication|git|1.0.3
gitlab-workflow|Git|3.41.0
vscode-test-explorer|hbe|2.21.1
output-colorizer|IBM|0.1.2
plantuml|jeb|2.17.2
better-cpp-syntax|jef|1.15.13
vscode-ksdiff|kal|1.0.0
auto-comment-blocks|kev|1.0.1
gitless|maa|11.7.1
git-graph|mhu|1.30.0
vscode-docker|ms-|1.20.0
python|ms-|2022.2.1924087327
vscode-pylance|ms-|2022.3.0
jupyter|ms-|2022.2.1030672458
jupyter-keymap|ms-|1.0.0
remote-containers|ms-|0.224.2
remote-ssh|ms-|0.76.1
remote-ssh-edit|ms-|0.76.1
remote-wsl|ms-|0.64.2
cmake-tools|ms-|1.9.2
cpptools|ms-|1.8.4
cpptools-extension-pack|ms-|1.1.0
test-adapter-converter|ms-|0.1.5
vsliveshare|ms-|1.0.5418
vsliveshare-audio|ms-|0.1.91
vsliveshare-pack|ms-|0.4.0
qml-debug|orc|0.1.0
ruby|reb|0.28.1
java|red|1.4.0
vscode-commons|red|0.0.6
vscode-xml|red|0.19.1
FileGroup|rio|1.0.1
html-related-links|rio|0.15.1
multi-command|ryu|1.5.1
vscode-qt-for-python|sea|1.1.7
comment-divider|sta|0.4.0
vscode-mermaid-editor|tom|0.14.0
qtvsctools|ton|0.10.1
cmake|twx|0.0.17
vscodeintellicode|Vis|1.2.17
vscode-java-debug|vsc|0.38.0
vscode-java-dependency|vsc|0.19.0
vscode-java-pack|vsc|0.22.0
vscode-maven|vsc|0.35.1
vscode-ruby|win|0.28.0
vscode-markdown-everywhere|zha|0.0.12
vscode-proto3|zxh|0.5.5

(1 theme extensions excluded)

</details><details>
<summary>A/B Experiments</summary>

```
vsliv368cf:30146710
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
pythonvspyl392:30443607
pythontb:30283811
pythonptprofiler:30281270
vsdfh931:30280409
vshan820:30294714
vstes263:30335439
pythondataviewer:30285071
vscod805cf:30301675
pythonvspyt200:30340761
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593cf:30376535
vsc1dst:30438360
pythonvs932:30410667
wslgetstarted:30449410
vsclayoutctrt:30448491
dsvsc008:30440022
pythonvspyt640:30450904
vsbas813:30436447
vscscmwlcmt:30438805
vscgsvidc:30447482
helix:30440343
pynewfile477:30450038

```

</details>

<!-- generated by issue reporter -->