From 48b25f785e66e58e75fca8bf808b6f598d261a17 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Tue, 18 Jul 2023 18:05:50 +0200 Subject: [PATCH] feat: Allow executable bits to be overridden in archive-file externals --- .../chezmoiexternal-format.md | 3 ++- pkg/chezmoi/sourcestate.go | 2 +- pkg/cmd/testdata/scripts/external.txtar | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/assets/chezmoi.io/docs/reference/special-files-and-directories/chezmoiexternal-format.md b/assets/chezmoi.io/docs/reference/special-files-and-directories/chezmoiexternal-format.md index b68c05c95cf..941a7099c24 100644 --- a/assets/chezmoi.io/docs/reference/special-files-and-directories/chezmoiexternal-format.md +++ b/assets/chezmoi.io/docs/reference/special-files-and-directories/chezmoiexternal-format.md @@ -89,7 +89,8 @@ If `type` is `archive-file` then the target is a file or symlink with the contents of the entry `path` in the archive at `url`. The optional integer field `stripComponents` will remove leading path components from the members of the archive before comparing them with `path`. The behavior of `format` is the same -as for `archive`. +as for `archive`. If `executable` is `true` then chezmoi will set the executable +bits on the target file, even if they are not set in the archive. If `type` is `git-repo` then chezmoi will run `git clone $URL $TARGET_NAME` with the optional `clone.args` if the target does not exist. If the target diff --git a/pkg/chezmoi/sourcestate.go b/pkg/chezmoi/sourcestate.go index 9ed395c8cb5..f2b7b4c48d4 100644 --- a/pkg/chezmoi/sourcestate.go +++ b/pkg/chezmoi/sourcestate.go @@ -2410,7 +2410,7 @@ func (s *SourceState) readExternalArchiveFile( TargetName: fileInfo.Name(), Type: SourceFileTypeFile, Empty: fileInfo.Size() == 0, - Executable: isExecutable(fileInfo), + Executable: isExecutable(fileInfo) || external.Executable, Private: isPrivate(fileInfo), ReadOnly: isReadOnly(fileInfo), } diff --git a/pkg/cmd/testdata/scripts/external.txtar b/pkg/cmd/testdata/scripts/external.txtar index 083f58b8091..8b1360c34a3 100644 --- a/pkg/cmd/testdata/scripts/external.txtar +++ b/pkg/cmd/testdata/scripts/external.txtar @@ -103,6 +103,13 @@ chhome home12/user exec chezmoi apply cmp $HOME/.file golden/dir/file +chhome home13/user + +# test that chezmoi can set executable bits on archive-file externals +exec chezmoi apply +[umask:002] cmpmod 775 $HOME/.file +[umask:022] cmpmod 755 $HOME/.file + -- archive/dir/file -- # contents of dir/file -- golden/.file -- @@ -142,6 +149,13 @@ cmp $HOME/.file golden/dir/file url = "{{ env "HTTPD_URL" }}/archive.tar.gz" path = "dir/file" stripComponents = 1 +-- home13/user/.local/share/chezmoi/.chezmoiexternal.toml -- +[".file"] + type = "archive-file" + url = "{{ env "HTTPD_URL" }}/archive.tar.gz" + path = "dir/file" + executable = true + stripComponents = 1 -- home2/user/.local/share/chezmoi/.chezmoiexternal.toml -- [".file"] type = "file"