How can I make files I check out with git on Windows writable by default in Cygwin?

2

2

I'm developing on Windows and I prefer to run git and build commands from the Windows command line, but I also enjoy using cygwin sometimes when I want to just explore the project repository using my favorite Unix tools.

The problem I have is that whenever I do any sort of git checkout, the files it checks out are read-only from the perspective of cygwin. I can fix it easily with a recursive chmod, but I don't want to have to do that after every git checkout. Note that if I edit those same files using any Windows program, they are writable - only cygwin sees them as read-only.

I'm not sure I can add a git hook, because as I said, I'm running git checkout from the Windows command line.

I guess I'm confused about the interaction between Windows permissions and cygwin permissions.

dmazzoni

Posted 2012-08-03T17:45:39.487

Reputation: 73

When you run Git from the Windows command line, do you know if you're using Cygwin Git? If you're not sure, can you post the output from git --exec-path? – me_and – 2012-08-06T10:52:21.263

No, I'm not using Cygwin git, I just checked. I prefer to use the non-Cygwin version of git because I'm using some hooks that assume it's being run from a Windows environment, not a Cygwin environment. – dmazzoni – 2012-08-06T14:29:33.540

I know I could switch to using Cygwin git, but that's not what I want to do - what I want to do is understand the relationship between Windows file permissions and Cygwin file permissions. How can I set permissions in Windows so that a file becomes readable in Cygwin? – dmazzoni – 2012-08-06T14:30:42.477

Answers

3

Without spending some time going through your assorted Windows file permissions, it's hard to say exactly what's going wrong.

Thankfully, I don't need to know that. The simple fix to resolve all your file permission woes is to use the noacl option for all the Cygwin mounts.

Open /etc/fstab in your favourite Cygwin text editor (or, normally, C:\cygwin\etc\fstab in your favourite Windows one, provided it supports Unix line-endings [so not Notepad]). Mine previously looked like this:

# For a description of the file format, see the Users Guide
# http://cygwin.com/cygwin-ug-net/using.html#mount-table

# This is default anyway:
# none /cygdrive cygdrive binary,posix=0,user 0 0

If that last line is still commented out, delete the leading so the system will pay attention to it. It may not be commented out, in which case there'll be no to delete.

Then, to the list of options (that's the binary,posix=0,user bit), add ,noacl to the end. The relevant line in my /etc/fstab then looked like the below:

none /cygdrive cygdrive binary,posix=0,user,noacl 0 0

Then close and reopen all your Cygwin applications (you may need to reboot), and you should stop seeing any permissions issues.

Note that if you've been doing complicated things with your mount points, you may need to edit multiple lines in /etc/fstab, as well as any files that have accumulated in /etc/fstab.d. The changes you'll need to make will be the same for all of these.

The noacl option will result in Cygwin completely ignoring all NTFS access control lists. It'll still look at the DOS read-only attribute, but that's not tied to any user. This means it won't be able to tell if a file is executable based off permissions, either; instead, it assumes any file ending .bat, .com or .exe is executable, as well as any file starting with #!.

Further reading, if you're interested, from the Cygwin User's Guide:

me_and

Posted 2012-08-03T17:45:39.487

Reputation: 2 118