Home > OS >  git: permissions only being applied with execute bit: can it be done without?
git: permissions only being applied with execute bit: can it be done without?

Time:10-27

I'm having problems setting permissions on files with git. I'd like to make all files in the repository 644. When I first clone the repo, the files are a mix of different permissions:

-rw------- 1 username group   2305 Oct 25 15:16 addquotes.sas
-rw------- 1 username group    675 Oct 25 15:16 ama_permission.sas
-rw------- 1 username group   1581 Oct 25 15:16 append_words.sas
-rwx------ 1 username group   3688 Oct 25 15:16 sasv9_u8.cfg
-rwx------ 1 username group   1489 Oct 25 15:16 backtest/bt_means.sas
-rwx------ 1 username group    490 Oct 25 15:16 backtest/correct_vname.sas
-rwx------ 1 username group    838 Oct 25 15:16 backtest/gen_random_samples.sas

To attempt to fix this, I run find . -type f | xargs chmod 644. This changes the permissions on the file system, but only a few appear as modified when I do a git status:

        modified:   sasv9_u8.cfg
        modified:   backtest/bt_means.sas
        modified:   backtest/correct_vname.sas
        modified:   backtest/gen_random_samples.sas

Digging deeper, I noticed that the files showing as modified had the owner execute bit set. If I run find . -type f | xargs chmod 744 (744 vs 644, to set the owner execute bit), then all the files appear in the git status command.

Is there any way to get git to recognize the permission without setting the execute bit on the owner? This behavior seems odd.

CodePudding user response:

Two points worth mentioning :

  • git does not store the whole range of unix permissions on files : it only stores "regular files" and "executable files",
  • git behaves like a normal process, and doesn't try to go around your umask ; the reason why you see no access rights for the group or other part is probably because your umask is set to 0077

A "regular file" will be checked out as -rw-rw-rw- -- minus your umask ; an "executable file" will be checked out as -rwxrwxrwx -- again, minus your umask.


About what you see :

  • my guess is that your umask is set to 0077 (no rights for group and other), so the "regular files" get checked out as -rw------- and "executable files" as -rwx------
  • if you run chmod 644 on your files, git detects that files that were previously executable are not executable anymore, and these ones show up,
  • I'm surprised that setting chmod 744 makes git detect a change on "executable" files : on my machine, it looks like git only checks for the (linux) executable flag set for user to determine if a file should be stored as executable ; detecting a change on "regular files" is expected.

How to "fix" this :

  • perhaps there is a reason why your umask is so restrictive, so perhaps the situation you have is the correct one ;
  • if your umask is too restrictive : choose a way to set it to a suitable value ;
  • to "fix" existing files : as @torek suggested the easiest way is probably to use the X option of chmod, which will set the executable flag only if at least one executable flag is set :
# you seem to want to give rw (and possibly x) access to the group :
chmod -R g rwX *
# perhaps r (and possibly x) to "others" :
chmod -R o rX *
  •  Tags:  
  • git
  • Related