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

Cannot read .git folder of a repo cloned from an admin-privileged cmd prompt #155910

Closed
gregsdennis opened this issue Jul 21, 2022 · 5 comments
Closed
Assignees
Labels
*duplicate Issue identified as a duplicate of another issue(s) git GIT issues

Comments

@gregsdennis
Copy link

gregsdennis commented Jul 21, 2022

Does this issue occur when all extensions are disabled?: Yes

Versions

Version: 1.69.2 (user setup)
Commit: 3b889b0
Date: 2022-07-18T16:12:52.460Z
Electron: 18.3.5
Chromium: 100.0.4896.160
Node.js: 16.13.2
V8: 10.0.139.17-electron.0
OS: Windows_NT x64 10.0.22000
git version 2.37.1.windows.1

Steps to Reproduce

  1. Start a command prompt as an admin
  2. Clone a repo
  3. Open the repo folder in VSCode, non-admin

VSCode does not recognize that the folder is a repo and shows a prompt to initialize a repo and/or sync to GitHub.

  1. Start a command prompt not as an admin
  2. Clone a repo
  3. Open the repo folder in VSCode, non-admin

VSCode correctly recognizs the folder as a git repo.

Remarks

This seems to be a new-ish behavior, but since VSCode is always up-to-date and I recently manually updated my git-for-windows, it could be either or their interaction.

@lszomoru
Copy link
Member

@gregsdennis, could you please enable trace logging as described in this wiki page. After that open the git repository in VS Code as a non-admin user, and share the contents of the git output window. That information should help me track down the root cause of the problem. Thank you!

@lszomoru lszomoru added info-needed Issue requires more information from poster git GIT issues labels Jul 27, 2022
@gregsdennis
Copy link
Author

Running without privilege:

Set the environment variable GIT_TEST_DEBUG_UNSAFE_DIRECTORIES=true and run
again for more information.
[2022-07-27T21:28:59.581Z] Log level: Trace
[2022-07-27T21:29:21.732Z] [trace] [svte] Scan visible text editors. autoRepositoryDetection=true
[2022-07-27T21:29:21.732Z] [trace] [svte] Open repository for editor resource c:\projects\vscode\README.md
[2022-07-27T21:29:21.741Z] [trace] Opening repository: c:\projects\vscode
[2022-07-27T21:29:21.885Z] > git rev-parse --show-toplevel [132ms]
[2022-07-27T21:29:21.885Z] fatal: detected dubious ownership in repository at 'C:/projects/vscode'
To add an exception for this directory, call:

	git config --global --add safe.directory C:/projects/vscode

Set the environment variable GIT_TEST_DEBUG_UNSAFE_DIRECTORIES=true and run
again for more information.
[2022-07-27T21:29:21.887Z] [trace] Opening repository for path='c:\projects\vscode' failed; ex=Failed to execute git {
  "exitCode": 128,
  "gitCommand": "rev-parse",
  "stdout": "",
  "stderr": "fatal: detected dubious ownership in repository at 'C:/projects/vscode'\nTo add an exception for this directory, call:\n\n\tgit config --global --add safe.directory C:/projects/vscode\n\nSet the environment variable GIT_TEST_DEBUG_UNSAFE_DIRECTORIES=true and run\nagain for more information.\n"
}

and with privilege:

[2022-07-27T21:37:47.825Z] Log level: Info
[2022-07-27T21:37:47.840Z] [info] Validating found git in: C:\Program Files\Git\cmd\git.exe
[2022-07-27T21:37:47.964Z] [info] Using git 2.37.1.windows.1 from C:\Program Files\Git\cmd\git.exe
[2022-07-27T21:37:48.076Z] > git rev-parse --show-toplevel [93ms]
[2022-07-27T21:37:48.183Z] > git rev-parse --git-dir --git-common-dir [90ms]
[2022-07-27T21:37:48.191Z] [info] Open repository: c:\projects\vscode
[2022-07-27T21:37:48.746Z] > git status -z -uall [542ms]
[2022-07-27T21:37:48.909Z] > git symbolic-ref --short HEAD [151ms]
[2022-07-27T21:37:48.999Z] > git show --textconv :README.md [150ms]
[2022-07-27T21:37:49.013Z] > git ls-files --stage -- C:\projects\vscode\README.md [149ms]
[2022-07-27T21:37:49.055Z] > git for-each-ref --format=%(refname)%00%(upstream:short)%00%(objectname)%00%(upstream:track)%00%(upstream:remotename)%00%(upstream:remoteref) refs/heads/main refs/remotes/main [128ms]
[2022-07-27T21:37:49.134Z] > git cat-file -s ba8f7224ff739019361f0b5c822c80d7886e3800 [106ms]
[2022-07-27T21:37:49.160Z] > git check-ignore -v -z --stdin [117ms]
[2022-07-27T21:37:49.181Z] > git remote --verbose [97ms]
[2022-07-27T21:37:49.210Z] > git for-each-ref --sort -committerdate --format %(refname) %(objectname) %(*objectname) [140ms]
[2022-07-27T21:37:49.332Z] > git config --get commit.template [90ms]
[2022-07-27T21:37:49.784Z] > git status -z -uall [433ms]
[2022-07-27T21:37:49.888Z] > git symbolic-ref --short HEAD [92ms]
[2022-07-27T21:37:49.994Z] > git for-each-ref --format=%(refname)%00%(upstream:short)%00%(objectname)%00%(upstream:track)%00%(upstream:remotename)%00%(upstream:remoteref) refs/heads/main refs/remotes/main [90ms]
[2022-07-27T21:37:50.104Z] > git remote --verbose [86ms]
[2022-07-27T21:37:50.136Z] > git for-each-ref --sort -committerdate --format %(refname) %(objectname) %(*objectname) [131ms]
[2022-07-27T21:37:50.235Z] > git config --get commit.template [81ms]

Looks to be that the repo is marked as unsafe. I'm fairly certain I've seen a warning saying that the folder isn't trusted and a prompt to mark it as such.

It's also strange that running as admin completely ignores the "untrusted" status.

@lszomoru
Copy link
Member

The dialog that you are seeing the VS Code is related to workspace trust. In your case, there has been a change in behaviour in git that is documented here. In your case, git.exe is the one that marks the repository as unsafe as the folder containing the repository has multiple owners. To resolve the problem you would have to run the command that is listed in the error message: git config --global --add safe.directory C:/projects/vscode.

@lszomoru lszomoru removed the info-needed Issue requires more information from poster label Jul 28, 2022
@lszomoru
Copy link
Member

Closing this issue as duplicate of #155812.

@lszomoru lszomoru added the *duplicate Issue identified as a duplicate of another issue(s) label Jul 28, 2022
@gregsdennis
Copy link
Author

That issue is already closed, so I'm putting this here. I don't think this is fully resolved.

While I agree that marking the repo as trusted is the correct action for me to take, it seems that having to open the git output (which I didn't even know existed) to find this information is not a good experience.

I suggest VSCode detect when this is the case and prompt the user to take action, either by displaying the CLI command to run or by presenting some UI where the user can have the app run the command for them.

@github-actions github-actions bot locked and limited conversation to collaborators Sep 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*duplicate Issue identified as a duplicate of another issue(s) git GIT issues
Projects
None yet
Development

No branches or pull requests

2 participants