diff --git a/scripts/committer b/scripts/committer index 5b7956e1da9..4c76ac98f8a 100755 --- a/scripts/committer +++ b/scripts/committer @@ -216,11 +216,11 @@ fi committed=false if [ "$fast_commit" = true ]; then declare -a commit_env=(FAST_COMMIT=1) - if run_git_with_lock_retry "commit" env "${commit_env[@]}" git commit -m "$commit_message" -- "${files[@]}"; then + if run_git_with_lock_retry "commit" env "${commit_env[@]}" git commit -m "$commit_message"; then committed=true fi else - if run_git_with_lock_retry "commit" git commit -m "$commit_message" -- "${files[@]}"; then + if run_git_with_lock_retry "commit" git commit -m "$commit_message"; then committed=true fi fi diff --git a/test/scripts/committer.test.ts b/test/scripts/committer.test.ts index d943a66fb7e..052a8baf8e0 100644 --- a/test/scripts/committer.test.ts +++ b/test/scripts/committer.test.ts @@ -60,6 +60,10 @@ function committedPaths(repo: string) { return output.split("\n").filter(Boolean).toSorted(); } +function committedFileContents(repo: string, relativePath: string) { + return git(repo, "show", `HEAD:${relativePath}`); +} + describe("scripts/committer", () => { it("accepts supported path argument shapes", () => { const cases = [ @@ -161,6 +165,28 @@ describe("scripts/committer", () => { expect(committedPaths(repo)).toEqual(["note.txt"]); }); + it("commits the hook-restaged file contents and leaves the tree clean", () => { + const repo = createRepo(); + installHook( + repo, + ".githooks/pre-commit", + [ + "#!/usr/bin/env bash", + "set -euo pipefail", + "printf 'formatted\\n' > note.txt", + "git add note.txt", + ].join("\n") + "\n", + ); + writeRepoFile(repo, "note.txt", "raw\n"); + + const output = commitWithHelperArgs(repo, "test: hook rewrite", "note.txt"); + + expect(output).toContain('Committed "test: hook rewrite" with 1 files'); + expect(committedPaths(repo)).toEqual(["note.txt"]); + expect(committedFileContents(repo, "note.txt")).toBe("formatted"); + expect(git(repo, "status", "--short", "--untracked-files=no")).toBe(""); + }); + it("prints usage for --help", () => { const repo = createRepo();