Hello,
some build systems have script files with certain specific names which are always intended to be executable.
For example Gradle has a `gradlew` file, and Maven has a (currently unofficial) `mvnw` file.
For Windows users these script files often cause problems when checked in with Git and used by a CI (continuous
integration) system running Linux. The CI build usually fails because the script files do not have the executable
flag set (Windows does not have this concept).
Would it be possible to extend the `.gitattributes` file to allow specifying that files should automatically get
the executable flag when added to the index? For example Gradle's `gradle init` command already creates a
`.gitattributes` file; it could then add such a default entry to ease development for Windows users to make sure
they add the `gradlew` script file with the correct file mode.
Assuming the flag is called `exec`, Gradle could then create the following `.gitattributes` entry:
It might also help with questions such as https://stackoverflow.com/q/14267441.
What do you think?
My C knowledge is rather limited, and I am not familiar with the Git source, so unfortunately I cannot submit a
patch for this.
Kind regards
On 2021-10-17 at 20:56:05, some-java-user-99206970363698485155@vodafonemail.de wrote:
Hello,
some build systems have script files with certain specific names which are always intended to be executable.
For example Gradle has a `gradlew` file, and Maven has a (currently unofficial) `mvnw` file.
For Windows users these script files often cause problems when checked in with Git and used by a CI (continuous
integration) system running Linux. The CI build usually fails because the script files do not have the executable
flag set (Windows does not have this concept).
Would it be possible to extend the `.gitattributes` file to allow specifying that files should automatically get
the executable flag when added to the index? For example Gradle's `gradle init` command already creates a
`.gitattributes` file; it could then add such a default entry to ease development for Windows users to make sure
they add the `gradlew` script file with the correct file mode.
Assuming the flag is called `exec`, Gradle could then create the following `.gitattributes` entry:
It might also help with questions such as https://stackoverflow.com/q/14267441.
What do you think?
I think this might end up being duplicative on Unix systems, but you
could implement this with a pre-commit hook if you wanted. Something
like this might work:
#!/bin/sh
files=$(git ls-files | git check-attr --stdin exec | grep 'exec: set$' | awk -F': ' '{print $1}')
files=$(git ls-files -s $files | grep '^100644' | awk -F'\t' '{print $2}')
git update-index --chmod=+x $files
git add $files
This obviously doesn't handle filenames with spaces, so it would need
some improvements, but it might work for your case.
It may also be beneficial to actually check this in CI as a first sanity
check, although it sounds like this CI system does this implicitly.
--
brian m. carlson (he/him or they/them)
Toronto, Ontario, CA