`safe.directory` handling broken when using Cygwin Git
See original GitHub issueThe 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 initworks at all – but that layer is bypassed after the initial executable call. - Set
safe.directoryto*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)
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:8 (3 by maintainers)

Top Related StackOverflow Question
@TingluoHuang I think that depends on how you check. Running
git config --global safe.directoryand checking if the output is non-empty would definitely work. Checking the contents of the.gitconfigfile won’t help for the same reasons the current solution doesn’t work: the Windows runners don’t have theHOMEenvironment variable defined, meaningactions/checkoutlooks for the global.gitconfigin a different place to where Cygwin Git expects it to be.For now, per https://github.com/me-and/Cygwin-Git/commit/08056b45533326523201414990bbc8968025331a, I’m working around this by just defining
HOMEexplicitly, and that seems to have got everything working.This is a useful trick, thanks! (Note that whatever solution you all go for, it should handle submodules gracefully; see also https://github.com/actions/checkout/issues/766#issuecomment-1100104891)