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

safe.directory setting issue #3787

Closed
1 task done
DoveBoy opened this issue Apr 13, 2022 · 14 comments
Closed
1 task done

safe.directory setting issue #3787

DoveBoy opened this issue Apr 13, 2022 · 14 comments

Comments

@DoveBoy
Copy link

DoveBoy commented Apr 13, 2022

  • I was not able to find an open or closed issue matching what I'm seeing

Setup

  • Which version of Git for Windows are you using? Is it 32-bit or 64-bit?
$ git --version --build-options

git version 2.35.2.windows.1
cpu: x86_64
built from commit: 518ccba2352ce721cabbbf2933869c3c3313d1c3
sizeof-long: 4
sizeof-size_t: 8
shell-path: /bin/sh
feature: fsmonitor--daemon
  • Which version of Windows are you running? Vista, 7, 8, 10? Is it 32-bit or 64-bit?
$ cmd.exe /c ver

Microsoft Windows [版本 10.0.22000.593]
  • What options did you set as part of the installation? Or did you choose the
    defaults?
# One of the following:
> type "C:\Program Files\Git\etc\install-options.txt"
> type "C:\Program Files (x86)\Git\etc\install-options.txt"
> type "%USERPROFILE%\AppData\Local\Programs\Git\etc\install-options.txt"
$ cat /etc/install-options.txt

scoop install git
  • Any other interesting things about your environment that might be related
    to the issue you're seeing?

** insert your response here **

Details

  • Which terminal/shell are you running Git from? e.g Bash/CMD/PowerShell/other

PowerShell7

git pull
  • What did you expect to occur after running these commands?

The process of git pull working properly

  • What actually happened instead?
fatal: unsafe repository ('E:\Program Files\Scoop\apps\scoop\current' is owned by someone else) To add an exception for this directory, call:

        git config --global --add safe.directory E:\Program Files\Scoop\apps\scoop\current

  • If the problem was occurring with a specific repository, can you provide the
    URL to that repository to help us with testing?

** insert URL here **

The original repo cannot be manipulated by any git related command, and must be forced to set git config --global --add safe.directory for each repo in order to work, as we currently know from the 2.35.2 update in order to fix a security issue. How to set global trust for all repo in .gitconfig, instead of having to set it for each repo individually, because there are too many repo's and it's too tedious to set each one.

@derrickstolee
Copy link

Hello, @DoveBoy. The per-repository assignment is by design. There is no setting to completely ignore this protection.

If you have a list of these repositories, then some automation (such as a shell script) can assist in running these commands.

@derrickstolee
Copy link

I am working on a modification to safe.directory to allow an opt-out of the feature: gitgitgadget#1215

@t-b
Copy link

t-b commented Apr 13, 2022

I see a related issue after updating to git version 2.35.2.windows.1.

With

$ cat ~/.gitconfig
[imap]
  pass = "/abcd"

[sendemail]
  smtppass = "/abcd"

I get in a repo outside of the users home on Windows:

$ git status
warning: encountered old-style '/abcd' that should be '%(prefix)/abcd'
warning: encountered old-style '/abcd' that should be '%(prefix)/abcd'
fatal: unsafe repository ('E:/projekte/git' is owned by someone else)
To add an exception for this directory, call:

        git config --global --add safe.directory E:/projekte/git

I don't expect a warning here as that is my password and not a path component.

@derrickstolee
Copy link

@t-b: thanks for helping here with an additional symptom. That's actually a problem with the config parser that skips the safe.directory key and checks all config values. It's being fixed now.

@AlexDanault
Copy link

AlexDanault commented Apr 13, 2022

If an option to disable this feature entirely is being worked on, please make sure it also disabled the owner check itself, because on a Windows machine, the owner check crashes when running commands in a command prompt (windows) for anything related to WSL :

L:\home\alex\Code\vtcloud>git status
error: failed to get owner for '//wsl$/Ubuntu20.04LTS/home/alex/Code/vtcloud' (1)
fatal: unsafe repository ('//wsl$/Ubuntu20.04LTS/home/alex/Code/vtcloud' is owned by someone else)
To add an exception for this directory, call:

        git config --global --add safe.directory '//wsl$/Ubuntu20.04LTS/home/alex/Code/vtcloud'

Running the git config (...) command also crashes (same message) is ran from a command prompt in a WSL folder. The command works if it is ran from a regular folder, and the config stays, bu has no impact at all, because git crashe at the owner check anyway.

@gitfool
Copy link

gitfool commented Apr 14, 2022

FYI: actions/checkout#760 (comment)

Looks like with git 2.35.3, git config --global --add safe.directory * will work to opt-out of the safe directory check.
git@1ac7422#diff-c62827315018c95283562ab55db59c26e544debaad579b77a7f96ffed09c45c2R18

@DoveBoy
Copy link
Author

DoveBoy commented Apr 14, 2022

Looks like with git 2.35.3, git config --global --add safe.directory * will work to opt-out of the safe directory check.
git@1ac7422#diff-c62827315018c95283562ab55db59c26e544debaad579b77a7f96ffed09c45c2R18

It would be nice if the update afterwards could really be set up in this way, without being too overbearing

@dscho
Copy link
Member

dscho commented Apr 19, 2022

The safe.directory=* handling made it into https://github.com/git-for-windows/git/releases/tag/v2.35.3.windows.1, I believe, therefore I am closing this ticket.

@dscho dscho closed this as completed Apr 19, 2022
@DoveBoy
Copy link
Author

DoveBoy commented Apr 20, 2022

The safe.directory=* handling made it into v2.35.3.windows.1 (release), I believe, therefore I am closing this ticket.

@dscho Updated git to the latest version

$ git --version --build-options

git version 2.35.3.windows.1
cpu: x86_64
built from commit: b952ed2
sizeof-long: 4
sizeof-size_t: 8
shell-path: /bin/sh
feature: fsmonitor--daemon

Use git config --global --add safe.directory=* to set the error, change it to git config --global --add safe.directory =* to set no error, but use git related commands still prompt you must set safe.directory

image
image
image
image

@naine
Copy link

naine commented Apr 20, 2022

@DoveBoy You do not use an = on the git config command line:

git config --global --add safe.directory *

@DoveBoy
Copy link
Author

DoveBoy commented Apr 20, 2022

git config --global --add safe.directory *

@naine excellent

@orgads
Copy link

orgads commented Apr 24, 2022

On Git Bash the * should be quoted:

git config --global --add safe.directory '*'

@phil-blain
Copy link

@orgads I saw somewhere else that using the quoted form in CMD resulted in the quotes making it to the config file and so the setting then didn't work. So I would advise to single quote in Git Bash but not in CMD (I'm not sure about PowerShell).

@orgads
Copy link

orgads commented Apr 24, 2022

Yes, I referred to Git Bash. I'll clarify that in my original message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants