[PATCH 3/3] t345x: cover signed history rewrites
From: Souma <hidden>
Date: 2026-07-03 14:51:36
Subsystem:
the rest · Maintainer:
Linus Torvalds
History signing needs regression coverage because these commands bypass the usual commit machinery and create replacement commits through lower-level APIs. Add GPG-gated tests for config-driven signing, command-line signing, --no-gpg-sign precedence, and signing of replayed descendants after fixup, reword, and split. Signed-off-by: Souma <redacted> --- t/t3451-history-reword.sh | 39 ++++++++++++++++++++++++++++++++++ t/t3452-history-split.sh | 44 +++++++++++++++++++++++++++++++++++++++ t/t3453-history-fixup.sh | 39 ++++++++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+)
diff --git a/t/t3451-history-reword.sh b/t/t3451-history-reword.sh
index de7b357685..5b41fb6489 100755
--- a/t/t3451-history-reword.sh
+++ b/t/t3451-history-reword.sh@@ -4,6 +4,7 @@ test_description='tests for git-history reword subcommand' . ./test-lib.sh . "$TEST_DIRECTORY/lib-log-graph.sh" +. "$TEST_DIRECTORY/lib-gpg.sh" reword_with_message () { cat >message &&
@@ -26,6 +27,37 @@ expect_log () { test_cmp expect actual } +test_reword_gpg_sign () { + must_fail= will=will + if test "x$1" = "x!" + then + must_fail=test_must_fail + will="will not" + shift + fi + conf=$1 + shift + + test_expect_success GPG "reword $* with commit.gpgsign=$conf $will sign rewritten history" " + test_when_finished 'rm -rf repo' && + git init repo && + ( + cd repo && + test_commit first && + test_commit second && + test_commit third && + + git config commit.gpgsign $conf && + reword_with_message $* HEAD~ <<-EOF && + second reworded + EOF + + $must_fail git verify-commit HEAD~ && + $must_fail git verify-commit HEAD + ) + " +} + test_expect_success 'can reword tip of a branch' ' test_when_finished "rm -rf repo" && git init repo &&
@@ -77,6 +109,13 @@ test_expect_success 'can reword commit in the middle' ' ) ' +test_reword_gpg_sign ! false +test_reword_gpg_sign true +test_reword_gpg_sign false --gpg-sign +test_reword_gpg_sign ! true --no-gpg-sign +test_reword_gpg_sign ! true --gpg-sign --no-gpg-sign +test_reword_gpg_sign false --no-gpg-sign --gpg-sign + test_expect_success 'can reword commit in the middle even on detached head' ' test_when_finished "rm -rf repo" && git init repo &&
diff --git a/t/t3452-history-split.sh b/t/t3452-history-split.sh
index 8ed0cebb50..e96f492cc6 100755
--- a/t/t3452-history-split.sh
+++ b/t/t3452-history-split.sh@@ -4,6 +4,7 @@ test_description='tests for git-history split subcommand' . ./test-lib.sh . "$TEST_DIRECTORY/lib-log-graph.sh" +. "$TEST_DIRECTORY/lib-gpg.sh" # The fake editor takes multiple arguments, each of which represents a commit # message. Subsequent invocations of the editor will then yield those messages
@@ -36,6 +37,42 @@ expect_tree_entries () { test_cmp expect actual } +test_split_gpg_sign () { + must_fail= will=will + if test "x$1" = "x!" + then + must_fail=test_must_fail + will="will not" + shift + fi + conf=$1 + shift + + test_expect_success GPG "split $* with commit.gpgsign=$conf $will sign rewritten history" " + test_when_finished 'rm -rf repo' && + git init repo && + ( + cd repo && + test_commit initial && + touch bar foo && + git add . && + git commit -m split-me && + test_commit tip && + + git config commit.gpgsign $conf && + set_fake_editor 'first' 'second' && + git history split $* HEAD~ <<-EOF && + y + n + EOF + + $must_fail git verify-commit HEAD~2 && + $must_fail git verify-commit HEAD~ && + $must_fail git verify-commit HEAD + ) + " +} + test_expect_success 'refuses to work with merge commits' ' test_when_finished "rm -rf repo" && git init repo &&
@@ -141,6 +178,13 @@ test_expect_success 'can split up tip commit' ' ) ' +test_split_gpg_sign ! false +test_split_gpg_sign true +test_split_gpg_sign false --gpg-sign +test_split_gpg_sign ! true --no-gpg-sign +test_split_gpg_sign ! true --gpg-sign --no-gpg-sign +test_split_gpg_sign false --no-gpg-sign --gpg-sign + test_expect_success 'can split up root commit' ' test_when_finished "rm -rf repo" && git init repo &&
diff --git a/t/t3453-history-fixup.sh b/t/t3453-history-fixup.sh
index 868298e248..cd20a23115 100755
--- a/t/t3453-history-fixup.sh
+++ b/t/t3453-history-fixup.sh@@ -3,6 +3,7 @@ test_description='tests for git-history fixup subcommand' . ./test-lib.sh +. "$TEST_DIRECTORY/lib-gpg.sh" fixup_with_message () { cat >message &&
@@ -21,6 +22,37 @@ expect_changes () { test_cmp expect actual } +test_fixup_gpg_sign () { + must_fail= will=will + if test "x$1" = "x!" + then + must_fail=test_must_fail + will="will not" + shift + fi + conf=$1 + shift + + test_expect_success GPG "fixup $* with commit.gpgsign=$conf $will sign rewritten history" " + test_when_finished 'rm -rf repo' && + git init repo && + ( + cd repo && + test_commit first && + test_commit second && + test_commit third && + + git config commit.gpgsign $conf && + echo fix >>second.t && + git add second.t && + git history fixup $* HEAD~ && + + $must_fail git verify-commit HEAD~ && + $must_fail git verify-commit HEAD + ) + " +} + test_expect_success 'errors on missing commit argument' ' test_when_finished "rm -rf repo" && git init repo &&
@@ -229,6 +261,13 @@ test_expect_success 'preserves commit message and authorship' ' ) ' +test_fixup_gpg_sign ! false +test_fixup_gpg_sign true +test_fixup_gpg_sign false --gpg-sign +test_fixup_gpg_sign ! true --no-gpg-sign +test_fixup_gpg_sign ! true --gpg-sign --no-gpg-sign +test_fixup_gpg_sign false --no-gpg-sign --gpg-sign + test_expect_success 'updates all descendant branches by default' ' test_when_finished "rm -rf repo" && git init repo --initial-branch=main &&
--
2.55.0