Saving files with Windows programs makes Git in Cygwin track filemode changes

455 views Asked by At

I am currently developing with Cygwin, Git in Cygwin and a Windows editor under Windows. It is quite annoying that saving files from native Windows programs makes a file executable in Cygwin. I want to track filemodes as we have Unix executables but updating files from Windows just shoudn't change the existing mode. I'd accept setting filemode once in Cygwin before committing the file the first time.

I read https://cygwin.com/cygwin-ug-net/using-filemodes.html but I'm on NTFS and I don't know how the ACLs will affect the file permissions. After all adding noacl to /etc/fstab didn't stop ls -l showing files as executable after updating them from Windows.

These two approaches seem to be possible:

  1. Make Cygwin keep the original x bit on existing files even after updated from Windows.

  2. Configure Git to ignore filemode changes only for already existing files. I really want to save the x flag when I add Unix executable files which is why git config core.fileMode false is not a solution. This saves all files as non-executable. (Sorry for all the emphasizing but while doing research I read too many articles from people happily dropping all the x bit information at all and considering it a solution)

What is a solution to either approach? I'd actually prefer the 1st one as it feels cleaner.

Update: Since I started using Komodo Edit rather than Geany files don't get the x bit anymore. Obviously there is some difference between different Windows programs saving files. This pretty much solves the problem for me although I think there must be a solution for Geany, too.

1

There are 1 answers

0
Zombo On

I see 2 situations here

  1. changed locally to +x, ignore change
  2. changed locally to +x, commit change

To do 1, I have this code in ~/.bashrc. ~/.bash_profile should work too

PROMPT_COMMAND='
if [ -d .git ]
then
  if [ ! -g .git/config ]
  then
    git config core.filemode 0
    chmod +s .git/config
  fi
fi
'

Then to do 2, I have a script that does this

git update-index --skip-worktree --chmod=+x hello-world.sh
git update-index --no-skip-worktree hello-world.sh

Run like this

git chmod.sh hello-world.sh

.bashrc

git-chmod.sh

Git ignoring gitconfig?

How do I make git accept mode changes without accepting all text changes?