Cache successful commits

```git-check-assertions
run test/git-check-assertions.bats
assert_success

git checkout HEAD~1 bin
run test/git-check-assertions.bats
assert_failure
assert_output --partial "file exists, but it was expected to be absent"
```
This commit is contained in:
Sven van Heugten 2026-03-10 06:38:45 +01:00
parent fea90637e3
commit e647b2599b
No known key found for this signature in database
GPG key ID: D612F88666F4F660
4 changed files with 80 additions and 1 deletions

View file

@ -87,7 +87,22 @@ echo "Base: $base"
echo "Commits to visit: ${#commits[@]}"
echo
declare -A cached_commits=()
if [ -f .git-check-assertions-cache ]; then
while IFS= read -r cached_commit; do
if [ -n "$cached_commit" ]; then
cached_commits["$cached_commit"]=1
fi
done < .git-check-assertions-cache
fi
for commit_hash in "${commits[@]}"; do
if [ -n "${cached_commits[$commit_hash]+x}" ]; then
echo "Skipping $commit_hash (cached)"
echo
continue
fi
echo "Checking out $commit_hash"
git -c advice.detachedHead=false checkout -q "$commit_hash"
commit_msg="$(git log -1 --format=%B "$commit_hash")"
@ -107,6 +122,7 @@ for commit_hash in "${commits[@]}"; do
fi
restore
fi
printf '%s\n' "$commit_hash" >>.git-check-assertions-cache
echo
done