twpayne/chezmoi

Preserve executable bit from source file

Closed this issue · 2 comments

Is your feature request related to a problem? Please describe.

Whether a file is executable can already be stored in git, since git preserves the executable bit of files.

It seems unnecessary, and a bit surprising that I have to include an executable_ prefix if a regular file already contains an executable flag.

Describe the solution you'd like

If a regular file has the executable bit set on its permission, then make the target file executable as well (respecting umask). Essentially, treat a file being executable as equivalent to having the executable_ attribute.

Describe alternatives you've considered

It is, of course, possible to use the executable_ attribute. However, it is very surprising (at least to me) that if I have a source file with mode 0700, without specifying executable as part of the file name, then running chezmoi apply produces a target file with mode 600.

Additional context

Note that git stores the executable bit of files.

No. Yes, git stores executable bits, but chezmoi is designed to work with all version control systems (some of which do not presreve executable bits) and all file systems (some of which do not have executable bits). Also, such a feature would introduce ambiguity: for the target file to have the executable bit set, is it necessary for the source file to have the executable_ attribute, the executable bit set, or both?

For more info on chezmoi's design, see https://www.chezmoi.io/user-guide/frequently-asked-questions/design/#why-does-chezmoi-use-weird-filenames.

but chezmoi is designed to work with all version control systems (some of which do not presreve executable bits)

Which ones don't? From some quick research it looks like git, svn, fossil, mercurial, bzr and darcs have some facility for marking files as executable (although in some it must be done explicitly when adding the file).

To be clear I am not suggesting removing the executable_ attribute, but allowing you to also use the executable bit to signify that it is executable. So if you do use a VCS that doesn't keep track of an executable flag, you can still use that.

Support for this could even be in a configuration option that needs to be opted in to.

and all file systems (some of which do not have executable bits)

true. But if the target file system doesn't have an executable bit, then the executable_ attribute doesn't really do anything does it? And if your target file system does have an executable bit, and your source file system doesn't, you can still use the executable_ flag.

such a feature would introduce ambiguity: for the target file to have the executable bit set, is it necessary for the source file to have the executable_ attribute, the executable bit set, or both?

I would think either. That is, the target file is executable if the source file has the executable_ attribute OR it has the executable bit set and doesn't have any of the attributes indicating a script, or a template (run_, .tmpl).

In pseudocode something like:

targetIsExecutable = source.attributes.includes("executable") || (source.permissions.executable && source.isNormalFile())