From 309d7fd719cf8d3be60fd0b2770929965165bf39 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Fri, 24 Jan 2025 23:09:48 -0500 Subject: [PATCH] fix: Warn, don't error, when generating git commit messages for unknown states --- assets/templates/COMMIT_MESSAGE.tmpl | 8 ++++---- internal/cmd/testdata/scripts/issue3344.txtar | 13 +++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 internal/cmd/testdata/scripts/issue3344.txtar diff --git a/assets/templates/COMMIT_MESSAGE.tmpl b/assets/templates/COMMIT_MESSAGE.tmpl index 244e89b38da..573a391790f 100644 --- a/assets/templates/COMMIT_MESSAGE.tmpl +++ b/assets/templates/COMMIT_MESSAGE.tmpl @@ -4,23 +4,23 @@ {{ if and (eq .X 'A') (eq .Y '.') -}}Add {{ .Path | targetRelPath }} {{ else if and (eq .X 'D') (eq .Y '.') -}}Remove {{ .Path | targetRelPath }} {{ else if and (eq .X 'M') (eq .Y '.') -}}Update {{ .Path | targetRelPath }} -{{ else }}{{with (printf "unsupported XY: %q" (printf "%c%c" .X .Y)) }}{{ fail . }}{{ end }} +{{ else }}{{ warnf "unsupported XY: %c%c" .X .Y }} {{ end }} {{- end -}} {{- range .RenamedOrCopied -}} {{ if and (eq .X 'R') (eq .Y '.') }}Change attributes of {{ .Path | targetRelPath }} {{ else if and (eq .X 'C') (eq .Y '.') -}}Copy {{ .OrigPath | targetRelPath }} to {{ .Path | targetRelPath }} -{{ else }}{{with (printf "unsupported XY: %q" (printf "%c%c" .X .Y)) }}{{ fail . }}{{ end }} +{{ else }}{{ warnf "unsupported XY: %c%c" .X .Y }} {{ end }} {{- end -}} {{- range .Unmerged -}} -{{ fail "unmerged files" }} +{{ warnf "unmerged files" }} {{- end -}} {{- range .Untracked -}} -{{ fail "untracked files" }} +{{ warnf "untracked files" }} {{- end -}} {{- end -}} diff --git a/internal/cmd/testdata/scripts/issue3344.txtar b/internal/cmd/testdata/scripts/issue3344.txtar new file mode 100644 index 00000000000..2dd39c85e28 --- /dev/null +++ b/internal/cmd/testdata/scripts/issue3344.txtar @@ -0,0 +1,13 @@ +[!exec:git] skip 'git not found in $PATH' + +mkgitconfig + +exec chezmoi init + +# test that chezmoi generate git-commit-message warns about untracked files +cp golden/.file $CHEZMOISOURCEDIR +exec chezmoi generate git-commit-message +stderr 'chezmoi: warning: untracked files' + +-- golden/.file -- +# contents of .file