question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`safe.directory` handling broken when using Cygwin Git

See original GitHub issue

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)

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
me-andcommented, Apr 18, 2022

@TingluoHuang I think that depends on how you check. Running git config --global safe.directory and checking if the output is non-empty would definitely work. Checking the contents of the .gitconfig file won’t help for the same reasons the current solution doesn’t work: the Windows runners don’t have the HOME environment variable defined, meaning actions/checkout looks for the global .gitconfig in 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 HOME explicitly, and that seems to have got everything working.

1reaction
JasonGrosscommented, Apr 15, 2022
  • 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.

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)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Git Clone under Cygwin hangs - Stack Overflow
It's not true that git is completely broken under Cygwin. If I clone a repository outside of Cygwin, I can do git checkout,...
Read more >
Chapter 3. Using Cygwin
Directory delimiters may be either forward slashes or backslashes. Paths using backslashes or starting with a drive letter are always handled as Win32...
Read more >
remove-section <name> git config [<file-option>] [--show-origin]
it is replaced with the directory containing the current config file. ... visiting a Cygwin created repository with Git for Windows or Eclipse)....
Read more >
git-config - Get and set repository or global options
This command will fail with non-zero status upon error. Some exit codes are: 1. The config file is invalid (ret=3), 2. can not...
Read more >
[PATCH 0/3] Some improvements to safe.directory on Windows
[PATCH 0/3] Some improvements to safe. · [PATCH 1/3] Allow debugging unsafe directories' ownership 2022-07-13 8:17 · [PATCH 2/3] mingw: handle a file...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found