Git: shell script execute enforcement

In Git, you can check a file with 644 or 755 permissions. I would like to ensure that all .sh files are always saved as 755 permissions so that they can be executed immediately. Especially in a Windows environment, it's easy to lose permissions by accident.

So, is there any way to configure it, it is desirable that the file processing be configured using .gitattributes? Maybe this can be done with a hook, but is there a cleaner way to do this?

+4
source share
1 answer

This may be possible with the .gitattributes filter. You can get part of the path with the following configuration:

Add this to .gitattributes :

 *.sh filter=permissions 

And add this to .git/config :

 [filter "permissions"] clean = chmod 755 %f 

As soon as you git add a .sh file, a clean filter will be applied and its permissions will be changed. Unfortunately, a permission change will not be added to the index, so this solution is clearly incomplete.

+2
source

Source: https://habr.com/ru/post/1414704/


All Articles