git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Suggestion: Allow .gitattributes to specify executable mode
@ 2021-10-17 20:56 some-java-user-99206970363698485155
  2021-10-17 21:11 ` brian m. carlson
  0 siblings, 1 reply; 2+ messages in thread
From: some-java-user-99206970363698485155 @ 2021-10-17 20:56 UTC (permalink / raw)
  To: git

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:
```
gradlew    text exec
```

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



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Suggestion: Allow .gitattributes to specify executable mode
  2021-10-17 20:56 Suggestion: Allow .gitattributes to specify executable mode some-java-user-99206970363698485155
@ 2021-10-17 21:11 ` brian m. carlson
  0 siblings, 0 replies; 2+ messages in thread
From: brian m. carlson @ 2021-10-17 21:11 UTC (permalink / raw)
  To: some-java-user-99206970363698485155; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 2021 bytes --]

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:
> ```
> gradlew    text exec
> ```
> 
> 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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 262 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-10-17 21:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-17 20:56 Suggestion: Allow .gitattributes to specify executable mode some-java-user-99206970363698485155
2021-10-17 21:11 ` brian m. carlson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).