How, using git on Windows, to indicate that the file has permission to run in Unix environments?

I'm using git in development, and I'm wanting to put the gradle project to run on CI. To run gradle, you would just have to give a ./gradlew to start the process. However, when calling this in my CI, it complains that the gradlew file is not executable.

However, I am not able to change the permission of this file, as everyone on the team uses Windows and chmod +x in Windows is no-op, even over git-bash.

So how to indicate pro git change of permission to run a file, through Windows?

I am not interested here in "fixing" this problem at the CI level by calling chmod +x before the command is executed.

Author: Jefferson Quesado, 2019-10-16

1 answers

To list a file with a different mode, use the git update-index, with option --chmod=+x.

I needed to do this to make a bash script hbm.sh executable:

$ git update-index --chmod=+x hbm.sh

$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   hbm.sh


$ git diff

$ git diff HEAD
diff --git a/hbm.sh b/hbm.sh
old mode 100644
new mode 100755

An important detail to highlight is that the File Permissions option needs to be made before the file names. So git update-index arquivo.sh --chmod=+x does not give the effect of changing the permissions of the file arquivo.sh, but git update-index --chmod=+x arquivo.sh gives the expected result.

When did I need to do this with gradlew, I needed to add the option --add on the command line:

$ git update-index --chmod=+x --add gradlew

This was necessary because the file gradlew was not tracked, not even listed/ staged.

 4
Author: Jefferson Quesado, 2020-08-12 17:01:47