4

In Git, you can check in a file either with 644 or 755 permissions. I would like to enforce that all .sh files would be always stored as 755 permissions so they can be immediately executed. Especially on windows environment it is easy to lose permissions accidentally.

So, is there a way to configure it, preferrably like file handling is configured with .gitattributes? It can probably be done with a hook, but is there a more clean way of doing it?

1 Answer 1

2

This might be possible using a .gitattributes filter. You can get part of the way there 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, the clean filter will be applied and its permissions will be changed. Unfortunately, the permission change won't be added to the index, so this solution is clearly incomplete.

Sign up to request clarification or add additional context in comments.

3 Comments

have I understood correctly that filter would be anyways something that has to be done locally and not anything we can store in version control so it would be for anybody using the repo?
You're right, I didn't think of that: You can add the .gitattributes file to the repo, but unless the other users have defined the permissions filter in their config it won't do anything.
This does not work! A filter will be called by piping the file to STDIN an is expected to deliver the results on STDOUT. If you do it like this, you end up in EMPTY FILES in your repository, because chmod does not deliver something on STDOUT.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.