safe.directory
handling broken when using Cygwin Git #767
Description
The fix at f25a3a9 is great for the vast majority of folk, but the way safe.directory
is set and handled breaks my use case: I'm using Cygwin Git on Windows runners (I'm the maintainer of a number of Cygwin packages, including the Cygwin Git package). I'm installing Cygwin Git on the runner and adding it to the PATH before calling actions/checkout, which means actions/checkout uses Cygwin Git rather than the default Git that's present on the runner.
Prior to Git v2.35.1, this worked perfectly. Using Git v2.35.1 or v2.35.2 with actions/checkout@v2.4.0, I needed to configure safe.directory
before calling actions/checkout, but that makes sense and worked. However, with actions/checkout@v2.4.1, safe.directory
gets overridden to (say) D:\a\Cygwin-Git\Cygwin-Git
, and that doesn't work, because that's not the sort of path Cygwin Git expects. Even setting safe.directory
to /cygdrive/d/a/Cygwin-Git/Cygwin-Git
in an earlier step doesn't work, because when git
gets called as part of actions/checkout, it doesn't look at the default global .gitconfig at all.
I'm not sure what the best solution is here; I'm aware my use case is fairly niche. Options I can see:
- Don't use actions/checkout, or at least maintain my own fork of actions/checkout that handles Cygwin gracefully. This'd be a shame, but I entirely understand that supporting non-default Git installations on the runners isn't what y'all signed up for.
- I work out how to get Cygwin Git to accept Windows-style paths to be handled in this configuration option, as well as the more POSIX-like Cygwin ones. There's already code in the Cygwin wrapper layers that handles this when the executable is called – which is why the call to
git init
works at all – but that layer is bypassed after the initial executable call. - Set
safe.directory
to*
rather than a specific path in this action. I think that's safe – certainly I can't immediately come up with something that would break, given the config would only exist for the duration of the action run – but it might not be in the spirit of that configuration option. - Add some configuration toggle to make this scenario work; default to the behaviour added in f25a3a9, but allowing someone using actions/checkout to disable the new behaviour.
- Something else cunning I haven't yet thought of.
For reference, the output I'm getting right now when trying to use actions/checkout looks like this:
Run actions/checkout@v2
Syncing repository: me-and/Cygwin-Git
Getting Git version info
Temporarily overriding HOME='D:\a\_temp\01a36204-8528-42[13](https://github.com/me-and/Cygwin-Git/runs/6030136677?check_suite_focus=true#step:4:13)-acd7-fa55cd902b9e' before making global git config changes
Adding working directory to the temporary git global config as a safe directory
C:\cygwin\bin\git.exe config --global --add safe.directory D:\a\Cygwin-Git\Cygwin-Git
Deleting the contents of 'D:\a\Cygwin-Git\Cygwin-Git'
Initializing the repository
C:\cygwin\bin\git.exe init D:\a\Cygwin-Git\Cygwin-Git
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /cygdrive/d/a/Cygwin-Git/Cygwin-Git/.git/
C:\cygwin\bin\git.exe remote add origin https://github.com/me-and/Cygwin-Git
Error: fatal: unsafe repository ('/cygdrive/d/a/Cygwin-Git/Cygwin-Git' is owned by someone else)
To add an exception for this directory, call:
git config --global --add safe.directory /cygdrive/d/a/Cygwin-Git/Cygwin-Git
Error: The process 'C:\cygwin\bin\git.exe' failed with exit code 1[28](https://github.com/me-and/Cygwin-Git/runs/6030136677?check_suite_focus=true#step:4:28)