From 35584c9aa75fc58a56ceeb5ebcf58ff4689e34d9 Mon Sep 17 00:00:00 2001 From: Sven van Heugten Date: Wed, 11 Mar 2026 22:09:39 +0100 Subject: [PATCH] Restore the commit between assertion blocks ```git-check-assertions run ./test/git-check-assertions.bats assert_success git checkout HEAD~ bin run ./test/git-check-assertions.bats assert_failure assert_output --partial "not ok 10 should restore the commit between assertion blocks in one commit message" ``` --- bin/git-check-assertions | 1 + test/git-check-assertions.bats | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/bin/git-check-assertions b/bin/git-check-assertions index 11e0b44..75f9dc1 100755 --- a/bin/git-check-assertions +++ b/bin/git-check-assertions @@ -121,6 +121,7 @@ for commit_hash in "${commits[@]}"; do exit 1 fi restore + git -c advice.detachedHead=false checkout -q "$commit_hash" done printf '%s\n' "$commit_hash" >>.git-check-assertions-cache echo diff --git a/test/git-check-assertions.bats b/test/git-check-assertions.bats index 8805d2f..5ff0798 100755 --- a/test/git-check-assertions.bats +++ b/test/git-check-assertions.bats @@ -145,6 +145,31 @@ commit_with_assertion() { assert_file_exists ../test2 } +@test "should restore the commit between assertion blocks in one commit message" { + git checkout -b feature + echo old >readme + git add readme + git commit -m "old" + + echo new >readme + git add readme + git commit -F - <<-EOF + update + + \`\`\`git-check-assertions + git checkout HEAD~ + \`\`\` + + \`\`\`git-check-assertions + grep new readme + \`\`\` + EOF + + run git-check-assertions + + assert_success +} + @test "should stop at the first failing assertion block and return to the original branch" { git checkout -b feature commit_with_assertion "touch ../test1 && exit 3"