microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.86k stars 29.51k forks source link

Git Extension doesn't detect repo - MacOS homebrew #232049

Open jpshack-at-palomar opened 1 month ago

jpshack-at-palomar commented 1 month ago

Type: Bug

Open any folder in which there is an initialized git repo. I have not yet found root cause but current theory is that the extension cannot handle a symlinked git binary as with homebrew.

I am using default settings for git extension on a completely clean install.

VS Code version: Code - Insiders 1.95.0-insider (fe997185b5e6db94693ed6ef5456cfa4e8211edf, 2024-10-23T05:06:13.568Z) OS version: Darwin arm64 24.0.0 Modes:

System Info |Item|Value| |---|---| |CPUs|Apple M1 (8 x 2400)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off| |Load (avg)|2, 2, 3| |Memory (System)|8.00GB (0.10GB free)| |Process Argv|--log vscode.git=trace --crash-reporter-id f58ace6f-1116-4b33-80b7-c3f39217abbf| |Screen Reader|no| |VM|0%|
Extensions: none
A/B Experiments ``` vsliv368:30146709 vspor879:30202332 vspor708:30202333 vspor363:30204092 vscod805cf:30301675 vsaa593cf:30376535 py29gd2263:31024238 c4g48928:30535728 962ge761:30841072 pythongtdpath:30726887 pythonnoceb:30776497 asynctok:30898717 dsvsc014:30777825 dsvsc015:30821418 pythonmypyd1:30859725 h48ei257:31000450 pythontbext0:30879054 cppperfnew:30980852 pythonait:30973460 0ee40948:31013168 dvdeprecation:31040973 dwnewjupyter:31046869 2f103344:31071589 nb_pri_only:31057983 nativerepl1:31134653 refactort:31084545 pythonrstrctxt:31093868 wkspc-onlycs-t:31132770 nativeloc1:31118317 wkspc-ranged-t:31151552 cf971741:31144450 e80f6927:31120813 autoexpandse:31146404 12bdf347:31141542 iacca1:31150324 notype1:31143044 dwcopilot:31158714 g7688163:31155431 ```

Logs:

024-10-23 09:45:11.406 [info] [main] Log level: Trace
2024-10-23 09:45:11.406 [info] [main] Validating found git in: "opt/homebrew/bin/git"
2024-10-23 09:45:11.438 [info] [main] Using git "2.47.0" from "opt/homebrew/bin/git"
2024-10-23 09:45:11.438 [info] [Model][doInitialScan] Initial repository scan started
2024-10-23 09:45:11.438 [trace] [Model][doInitialScan] Settings: autoRepositoryDetection=true, openRepositoryInParentFolders=prompt
2024-10-23 09:45:11.438 [trace] [Model][onDidChangeWorkspaceFolders] Workspace folders: []
2024-10-23 09:45:11.440 [info] [Model][doInitialScan] Initial repository scan completed - repositories (0), closed repositories (0), parent repositories (0), unsafe repositories (0)
2024-10-23 09:45:13.368 [trace] [Model][onDidChangeConfiguration] Workspace folders: []
2024-10-23 09:45:15.491 [info] [main] Log level: Trace
2024-10-23 09:45:15.491 [info] [main] Validating found git in: "opt/homebrew/bin/git"
2024-10-23 09:45:15.500 [info] [main] Using git "2.47.0" from "opt/homebrew/bin/git"
2024-10-23 09:45:15.501 [info] [Model][doInitialScan] Initial repository scan started
2024-10-23 09:45:15.501 [trace] [Model][doInitialScan] Settings: autoRepositoryDetection=true, openRepositoryInParentFolders=prompt
2024-10-23 09:45:15.501 [trace] [Model][onDidChangeWorkspaceFolders] Workspace folders: [/Users/jpshack/code/aider]
2024-10-23 09:45:15.501 [trace] [Model][scanWorkspaceFolders] Workspace folder: /Users/jpshack/code/aider
2024-10-23 09:45:15.501 [trace] [Model][openRepository] Repository: /Users/jpshack/code/aider
2024-10-23 09:45:15.505 [trace] [Model][openRepository] Opening repository for path='/Users/jpshack/code/aider' failed. Error:spawn opt/homebrew/bin/git ENOENT {
  "gitErrorCode": "NotAGitRepository"
}Error: spawn opt/homebrew/bin/git ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:286:19)
    at onErrorNT (node:internal/child_process:484:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
2024-10-23 09:45:15.507 [trace] [Model][scanWorkspaceFolders] Workspace scan settings: repositoryScanMaxDepth=1; repositoryScanIgnoredFolders=[node_modules]; scanRepositories=[]
2024-10-23 09:45:15.507 [trace] [Model][scanWorkspaceFolders] Workspace scan sub folders: [/Users/jpshack/code/aider/.aider.tags.cache.v3, /Users/jpshack/code/aider/.github, /Users/jpshack/code/aider/.pytest_cache, /Users/jpshack/code/aider/aider, /Users/jpshack/code/aider/aider_chat.egg-info, /Users/jpshack/code/aider/benchmark, /Users/jpshack/code/aider/docker, /Users/jpshack/code/aider/scripts, /Users/jpshack/code/aider/tests, /Users/jpshack/code/aider/website]
2024-10-23 09:45:15.507 [trace] [Model][openRepository] Repository: /Users/jpshack/code/aider/.aider.tags.cache.v3
2024-10-23 09:45:15.508 [trace] [Model][openRepository] Opening repository for path='/Users/jpshack/code/aider/.aider.tags.cache.v3' failed. Error:spawn opt/homebrew/bin/git ENOENT {
  "gitErrorCode": "NotAGitRepository"
}Error: spawn opt/homebrew/bin/git ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:286:19)
    at onErrorNT (node:internal/child_process:484:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
2024-10-23 09:45:15.508 [trace] [Model][openRepository] Repository: /Users/jpshack/code/aider/.github
2024-10-23 09:45:15.508 [trace] [Model][openRepository] Opening repository for path='/Users/jpshack/code/aider/.github' failed. Error:spawn opt/homebrew/bin/git ENOENT {
  "gitErrorCode": "NotAGitRepository"
}Error: spawn opt/homebrew/bin/git ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:286:19)
    at onErrorNT (node:internal/child_process:484:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
2024-10-23 09:45:15.508 [trace] [Model][openRepository] Repository: /Users/jpshack/code/aider/.pytest_cache
2024-10-23 09:45:15.509 [trace] [Model][openRepository] Opening repository for path='/Users/jpshack/code/aider/.pytest_cache' failed. Error:spawn opt/homebrew/bin/git ENOENT {
  "gitErrorCode": "NotAGitRepository"
}Error: spawn opt/homebrew/bin/git ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:286:19)
    at onErrorNT (node:internal/child_process:484:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
2024-10-23 09:45:15.509 [trace] [Model][openRepository] Repository: /Users/jpshack/code/aider/aider
2024-10-23 09:45:15.510 [trace] [Model][openRepository] Opening repository for path='/Users/jpshack/code/aider/aider' failed. Error:spawn opt/homebrew/bin/git ENOENT {
  "gitErrorCode": "NotAGitRepository"
}Error: spawn opt/homebrew/bin/git ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:286:19)
    at onErrorNT (node:internal/child_process:484:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
2024-10-23 09:45:15.510 [trace] [Model][openRepository] Repository: /Users/jpshack/code/aider/aider_chat.egg-info
2024-10-23 09:45:15.510 [trace] [Model][openRepository] Opening repository for path='/Users/jpshack/code/aider/aider_chat.egg-info' failed. Error:spawn opt/homebrew/bin/git ENOENT {
  "gitErrorCode": "NotAGitRepository"
}Error: spawn opt/homebrew/bin/git ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:286:19)
    at onErrorNT (node:internal/child_process:484:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
2024-10-23 09:45:15.510 [trace] [Model][openRepository] Repository: /Users/jpshack/code/aider/benchmark
2024-10-23 09:45:15.511 [trace] [Model][openRepository] Opening repository for path='/Users/jpshack/code/aider/benchmark' failed. Error:spawn opt/homebrew/bin/git ENOENT {
  "gitErrorCode": "NotAGitRepository"
}Error: spawn opt/homebrew/bin/git ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:286:19)
    at onErrorNT (node:internal/child_process:484:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
2024-10-23 09:45:15.511 [trace] [Model][openRepository] Repository: /Users/jpshack/code/aider/docker
2024-10-23 09:45:15.511 [trace] [Model][openRepository] Opening repository for path='/Users/jpshack/code/aider/docker' failed. Error:spawn opt/homebrew/bin/git ENOENT {
  "gitErrorCode": "NotAGitRepository"
}Error: spawn opt/homebrew/bin/git ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:286:19)
    at onErrorNT (node:internal/child_process:484:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
2024-10-23 09:45:15.511 [trace] [Model][openRepository] Repository: /Users/jpshack/code/aider/scripts
2024-10-23 09:45:15.512 [trace] [Model][openRepository] Opening repository for path='/Users/jpshack/code/aider/scripts' failed. Error:spawn opt/homebrew/bin/git ENOENT {
  "gitErrorCode": "NotAGitRepository"
}Error: spawn opt/homebrew/bin/git ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:286:19)
    at onErrorNT (node:internal/child_process:484:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
2024-10-23 09:45:15.512 [trace] [Model][openRepository] Repository: /Users/jpshack/code/aider/tests
2024-10-23 09:45:15.512 [trace] [Model][openRepository] Opening repository for path='/Users/jpshack/code/aider/tests' failed. Error:spawn opt/homebrew/bin/git ENOENT {
  "gitErrorCode": "NotAGitRepository"
}Error: spawn opt/homebrew/bin/git ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:286:19)
    at onErrorNT (node:internal/child_process:484:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
2024-10-23 09:45:15.512 [trace] [Model][openRepository] Repository: /Users/jpshack/code/aider/website
2024-10-23 09:45:15.513 [trace] [Model][openRepository] Opening repository for path='/Users/jpshack/code/aider/website' failed. Error:spawn opt/homebrew/bin/git ENOENT {
  "gitErrorCode": "NotAGitRepository"
}Error: spawn opt/homebrew/bin/git ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:286:19)
    at onErrorNT (node:internal/child_process:484:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
2024-10-23 09:45:15.514 [info] [Model][doInitialScan] Initial repository scan completed - repositories (0), closed repositories (0), parent repositories (0), unsafe repositories (0)
2024-10-23 09:45:17.502 [trace] [Model][onDidChangeConfiguration] Workspace folders: [/Users/jpshack/code/aider]
2024-10-23 09:45:17.502 [trace] [Model][openRepository] Repository: /Users/jpshack/code/aider
2024-10-23 09:45:17.503 [trace] [Model][openRepository] Opening repository for path='/Users/jpshack/code/aider' failed. Error:spawn opt/homebrew/bin/git ENOENT {
  "gitErrorCode": "NotAGitRepository"
}Error: spawn opt/homebrew/bin/git ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:286:19)
    at onErrorNT (node:internal/child_process:484:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

The logs are noisy because of all of the sub-directories the extension is searching--but I can confirm that there is indeed a git repo:

drwxr-xr-x  33 jpshack  staff   1.0K Jul 13 10:42 .
drwxr-xr-x  88 jpshack  staff   2.8K Oct 21 15:33 ..
-rw-r--r--@  1 jpshack  staff   161K Jun  3 15:07 .aider.chat.history.md
-rw-r--r--@  1 jpshack  staff   5.2K Jun  3 15:07 .aider.input.history
drwxr-xr-x@  5 jpshack  staff   160B Jun  3 10:05 .aider.tags.cache.v3
-rw-r--r--   1 jpshack  staff    61B May 30 10:43 .dockerignore
-rw-r--r--   1 jpshack  staff    50B May 30 10:43 .flake8
drwxr-xr-x  15 jpshack  staff   480B Jul 13 10:39 .git
drwxr-xr-x   4 jpshack  staff   128B May 30 10:43 .github
-rw-r--r--   1 jpshack  staff   131B Jun 18 11:57 .gitignore
-rw-r--r--   1 jpshack  staff   385B Jun 18 12:39 .pre-commit-config.yaml
drwxr-xr-x@  6 jpshack  staff   192B May 31 10:41 .pytest_cache
jpshack-at-palomar commented 1 month ago

Originally thought this was https://github.com/microsoft/vscode/issues/204387 as same symptoms.

jpshack-at-palomar commented 1 month ago

Ha! The problem appears just to be that for some reason on MacOS the initial slash is getting trimmed in the executable path.

$ which git
/opt/homebrew/bin/git

But see in the logs references to the git executable have opt/homebrew/bin/git

When I add this to settings.json, it works.

"git.path": "/opt/homebrew/bin/git"
lszomoru commented 1 month ago

@jpshack-at-palomar, is there any reason why you have set the git.path setting? That should not be necessary.

jpshack-at-palomar commented 1 month ago

The only reason I set it was to troubleshoot this issue. The issue occurred with no setting. I could see from the logging that prior to the setting VS Code was using opt/homebrew/bin/git as the path. I added the setting to satisfy myself that the issue was not the missing / but a deeper problem. However I was surprised to find that adding the setting with git.path: /opt/homebrew/bin/git actually resolved the issue. So there is a bug somewhere in the VS Code configuration discovery that took a '$ which git' result of /opt/homebrew/bin/git and trimmed the initial slash with the result that repository discovery was failing. It is that bug that this issue is reporting.

lszomoru commented 4 weeks ago

Thank to the clarifications.

I am using git installed using homebrew and here is the snippet from my log without having the git.path setting set:

2024-11-01 10:19:54.685 [info] [main] Log level: Info
2024-11-01 10:19:55.128 [info] [main] Validating found git in: "/opt/homebrew/bin/git"
2024-11-01 10:19:55.213 [info] [main] Using git "2.46.0" from "/opt/homebrew/bin/git"

So without specifying the git.path setting, git should be correctly discovered. Could you clear the git.path setting on your machine and see if your log would match what I am seeing?

jpshack-at-palomar commented 3 weeks ago

All of the traces I shared previously are WITHOUT the git.path setting. I am happy to provide any additional logging you need to hunt down the issue.