0

Since git always mess the file permission settings I want add a shell script to git do the permission change after checkout. So I thought of adding following to post-checkout

#!/bin/sh

find . -type f -print0 | xargs -0 chmod 664
find . -type d -print0 | xargs -0 chmod 775

but git post-checkout is in .git/hooks/ so by using . operator will only look in that folder or does git somehow knows to get this to start search from main project directory?

One of the reason that I got little confuse is that if you do a git status on .git/hooks you get following:

% git status
fatal: This operation must be run in a work tree
add-semi-colons
  • 18,094
  • 55
  • 145
  • 232
  • 1
    Watch out for `find .` descending into `.git` itself (although given the chmod commands here that should be harmless). But: git should not "mess the file permission settings": files checked-out should have the mode indicated by your umask and the execute bit stored in the repo. If your umask is 002 (group write), directories should already be 775 and files should already be 664. Objects in the repo should have modes based on `core.sharedRepository`; see [git-config documentation](https://www.kernel.org/pub/software/scm/git/docs/git-config.html). – torek Sep 18 '13 at 20:02

1 Answers1

0

Each hook is run with the root directory of the Git repository (i.e., the directory containing .git) as its working directory. Your script should work.

chepner
  • 497,756
  • 71
  • 530
  • 681