Windows bash git and execute permissions

In Go development it’s important to be able to connecting ussing SSH with github if that is where your  sources are. A very good explanation of hooking up visual studio code using SSH with github using Pageant and Putty can be found on http://www.cgranade.com/blog/2016/06/06/ssh-keys-in-vscode.html

Next to that, on Windows the file permissions for running scripts and executables do not matter that much as windows simply can execute whatever is readable but that is of course different on Linux or *nix like systems where file permissions are needed to be able to execute scripts, like bash scripts (*.sh).

In our git repositories we are also maintaining the bash scripts for dockerizing builds that run in Jenkins and unfortunately, copying over a script to another git repo on a windows machine suddenly might give the script different permissions. Resulting in the script failing with a nasty execute permission error within Jenkins. That is, the script might not be having the execute permissions.

What to do is to add the execute permission to the script. But how to do that on windows?

An example:

PS> git ls-tree HEAD
100644 blob 8a90f8535a375f936095a7d072fa3e8f0ab615cb    docker.sh

PS> git update-index --chmod=+x docker.sh
PS> git ls-files --stage
100755 8a90f8535a375f936095a7d072fa3e8f0ab615cb 0       docker.sh

Explanation of the shown commands:

git ls-tree HEAD will show the permissions for each file of the path you are in. In the above example the permissions are still 644, so not executable.

git update-index –chmod=+x <filename>

adds the execute permission to the file. Note that this is not visible when you again do

git ls-files –stage shows the staged change. 755 has added the execute permission.

After committing this script, jenkins will execute this docker.sh script just fine.

Conclusion

You don’t need a mac to update file permissions for *nix based bash scripts; you can do that on Windows as well, it’s just about running some *nix like commands via the git command.