0

I'm working with a git repository on both windows and linux/mac. When I create new files on windows, or edit them in some text editors, the file mode is changed to 775. I can get git to ignore file mode changes with

git config core.filemode false

but I also want most new files to have mode 664 (not 775). The best I've come up with so far is the pre-commit hook

git diff --cached --name-only | egrep -v '\.(bat|py|sh|exe)' | xargs -d"\n" chmod 664
git diff --cached --name-only | egrep -v '\.(bat|py|sh|exe)' | xargs -d"\n" git add

but this does the wrong thing if I've added a new file, then edited it again before commiting, and then commited without adding it. Is there a better way to do this, or something like a pre-add or post-add hook?

Edit: git diff --cached --name-only also gives me files that have been deleted, so what I really want is something like git diff --cached --name-only --diff-filter=ACMRTUXB

Jason Gross
  • 5,928
  • 1
  • 26
  • 53

2 Answers2

1

Instead of using chmod and readding, you can use git update-index --chmod=-x <files> to modify the index directly.

mkarasek
  • 22,309
  • 2
  • 21
  • 10
0

Take a look at git attributes. You can handle it there. Smudge/clean may be a way to deal with it.

Adam Dymitruk
  • 124,556
  • 26
  • 146
  • 141
  • Smudge and clean seem to be filters that act on the contents of the file. Is there a way to make them act on the metadata? (Setting the clean operation to chmod -x gives an error.) – Jason Gross Mar 18 '11 at 05:56