Open idanmiara opened 2 years ago
They're not completely wrong, they just assume a POSIX-ish shell (like Git Bash). Git tends to do that when giving out advice about command line syntax.
We don't have a way to detect the shell you're calling git from to customise the advice though.
An approach that could be easier to implement than detecting the shell could be a config option that sets a preferred command line syntax.
We don't have a way to detect the shell you're calling git from to customise the advice though.
I guess we could use the presence of the environment variable PSModulePath
as a tell-tale that we're running inside a PowerShell, PROMPT
as a tell-tale that we're running inside a CMD, and SHELL
as a tell-tale that we're running inside a Bash (but that somehow does not work for dash
, so we might want to fall back to assuming a POSIX shell anyway).
That approach could still get confused when calling one shell from another.
Would it make sense to instead provide multiple variations, and rely upon the user to choose the appropriate item? Something like:
fatal: unsafe repository ('//mynas/porjects/my project' is owned by someone else)
To add an exception for this directory, please choose the appropriate command below based upon the environment in use:
bash/posix shell: git config --global --add safe.directory '%(prefix)///mynas/porjects/my project'
cmd/powershell: git config --global --add safe.directory "%(prefix)///mynas/porjects/my project"
It's not perfect—naturally—since some users won't know which version to select (especially when using third-party software that invokes GfW), but may be useful as a starting point.
I actually got the initial error message from TortoiseGit, so it wasn't even from a shell. So I think it's a good idea to give this informative error.
On Tue, 17 May 2022, 19:58 Adric Norris, @.***> wrote:
Would it make sense to instead provide multiple variations, and rely upon the user to choose the appropriate item? Something like:
fatal: unsafe repository ('//mynas/porjects/my project' is owned by someone else)
To add an exception for this directory, please choose the appropriate command below based upon the environment in use:
bash/posix shell: git config --global --add safe.directory '%(prefix)///mynas/porjects/my project'
cmd/powershell: git config --global --add safe.directory "%(prefix)///mynas/porjects/my project"
It's not perfect—naturally—since some users won't know which version to select (especially when using third-party software that invokes GfW), but may be useful as a starting point.
— Reply to this email directly, view it on GitHub https://github.com/git-for-windows/git/issues/3856#issuecomment-1129104434, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGJBBLPN564LGJEZ3JXVDYTVKPF35ANCNFSM5WDVH6OA . You are receiving this because you authored the thread.Message ID: @.***>
That approach could still get confused when calling one shell from another.
All too true.
Would it make sense to instead provide multiple variations, and rely upon the user to choose the appropriate item? Something like:
fatal: unsafe repository ('//mynas/porjects/my project' is owned by someone else) To add an exception for this directory, please choose the appropriate command below based upon the environment in use: bash/posix shell: git config --global --add safe.directory '%(prefix)///mynas/porjects/my project' cmd/powershell: git config --global --add safe.directory "%(prefix)///mynas/porjects/my project"
It's not perfect—naturally—since some users won't know which version to select (especially when using third-party software that invokes GfW), but may be useful as a starting point.
I'd rather just add a comment (e.g. "Use single quotes instead of double quotes to run this command in PowerShell/CMD").
On Windows, the instructions for
git config --global --add safe.directory "%(prefix)///mynas/porjects/my project"
path should be with the within"
instead of'
Setup
Windows 11 64 bit
Default
Related issues: https://github.com/git-for-windows/git/pull/3790 https://github.com/git-for-windows/git/pull/3791
Details
cmd
run
git status
on a shared network drive folder.gitconfig
should be updatederror: wrong number of arguments, should be 2
Using double quotes instead of single quotes solves the problem.
git config --global --add safe.directory "%(prefix)///mynas/porjects/my project"
No