Setting execution permission from git

Filed under: Automation, DevOps, Git, Linux, — Tags: Linux, Unix — Thomas Sundberg — 2020-01-31

The execution flag must be set on a file for it to be possible to be executed as a script on a Linux system.

Windows

This is a not possible if you develop your code on a Windows box.

To set the proper file permissions, you use chmod. But chmod doesn't exist on windows so doing chmod +x script can't be done.

Use git

There is a solution if you version control the files using Git. It is possible to set the file permissions in Git.

Lets start with checking the current file permissions with the command:

git ls-files --stage

This will list all files with the unix file permissions. It may look like this:

100644 c78a60c8d5f2c58f4abd248ee6513e29b147d92a 0       find-images.sh

The file above, find-images.sh, have the file permission 644.

File permission 644 means can be visualized like this:

| | User | Group | Other | |---------|------|-------|-------| | Read | Yes | Yes | Yes | | Write | Yes | No | No | | Execute | No | No | No |

The user can read and write, but not execute the file. In order to execute find-images.sh, the execution flag must be set. We would like to execute the command chmod +x but when we use windows, we can't.

The solution is to do

git update-index --chmod=+x 'find-images.sh'

This will set the execution flag and the file will be possible to execute.

Conclusion

Developing on a Windows box makes life complicated. But it is at least possible to set the execution flag on a script using git.

Acknowledgements

I would like to thank Malin Ekholm and Mika Kytöläinen for feedback.

Resources



(less...)

Pages

About
Events
Why

Categories

Agile
Automation
BDD
Clean code
Continuous delivery
Continuous deployment
Continuous integration
Cucumber
Culture
Design
DevOps
Executable specification
Git
Gradle
Guice
J2EE
JUnit
Java
Javascript
Kubernetes
Linux
Load testing
Maven
Mockito
New developers
Pair programming
PicoContainer
Presentation
Programming
Public speaking
Quality
React
Recruiting
Requirements
Scala
Selenium
Software craftsmanship
Software development
Spring
TDD
Teaching
Technical debt
Test automation
Tools
Web
Windows
eXtreme Programming

Authors

Thomas Sundberg
Adrian Bolboaca

Archives

Meta

rss RSS