From 99bcd7460f84df8c6c0320728720918aa1a40ebc Mon Sep 17 00:00:00 2001 From: Sven van Heugten Date: Wed, 4 Mar 2026 07:37:09 +0100 Subject: [PATCH 1/2] Add failing test to check if the worktree is restored after failure This test currently doesn't pass: ```git-check-assertions run ./test/git-check-assertions.bats assert_failure assert_output --partial "file is greater than 0 byte" ``` --- test/git-check-assertions.bats | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/git-check-assertions.bats b/test/git-check-assertions.bats index 2e45490..1755820 100755 --- a/test/git-check-assertions.bats +++ b/test/git-check-assertions.bats @@ -99,6 +99,16 @@ commit_with_assertion() { assert_size_zero ../test } +@test "should restore worktree after a failure" { + git checkout -b feature + commit_with_assertion $'echo blah >> readme\nexit 3' + + run git-check-assertions + + assert_failure + assert_size_zero readme +} + @test "assertions should run against the version of the code inside of the commit" { git checkout -b feature echo commit1 >readme From 2299ee34072315c6957061cf0b68274c83c76689 Mon Sep 17 00:00:00 2001 From: Sven van Heugten Date: Wed, 4 Mar 2026 07:39:07 +0100 Subject: [PATCH 2/2] Restore the worktree after a failure ```git-check-assertions run ./test/git-check-assertions.bats assert_success ``` --- bin/git-check-assertions | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/git-check-assertions b/bin/git-check-assertions index 5501358..4ebc513 100755 --- a/bin/git-check-assertions +++ b/bin/git-check-assertions @@ -84,6 +84,7 @@ for commit_hash in "${commits[@]}"; do printf '%s\n' "$block" | sed 's/^/> /' if ! bash -euo pipefail -c "$block"; then echo "git-check-assertions block failed in $commit_hash" >&2 + git restore -q . echo "Returning to $orig_ref" git checkout -q "$orig_ref" exit 1