Merge pull request 'Restore the index after every commit' (#10) from restore-index into main
Reviewed-on: https://codeberg.org/svenvanheugten/git-check-assertions/pulls/10
This commit is contained in:
commit
3ce1ea5e4b
2 changed files with 37 additions and 2 deletions
|
|
@ -72,6 +72,9 @@ else
|
||||||
echo "No main or master branch found." >&2
|
echo "No main or master branch found." >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
restore() {
|
||||||
|
git restore -q --staged --worktree .
|
||||||
|
}
|
||||||
base="$(git merge-base "$base_branch" HEAD)"
|
base="$(git merge-base "$base_branch" HEAD)"
|
||||||
mapfile -t commits < <(git rev-list --reverse "${base}..HEAD")
|
mapfile -t commits < <(git rev-list --reverse "${base}..HEAD")
|
||||||
|
|
||||||
|
|
@ -92,12 +95,12 @@ for commit_hash in "${commits[@]}"; do
|
||||||
printf '%s\n' "$block" | sed 's/^/> /'
|
printf '%s\n' "$block" | sed 's/^/> /'
|
||||||
if ! bash -euo pipefail -c "$block"; then
|
if ! bash -euo pipefail -c "$block"; then
|
||||||
echo "git-check-assertions block failed in $commit_hash" >&2
|
echo "git-check-assertions block failed in $commit_hash" >&2
|
||||||
git restore -q .
|
restore
|
||||||
echo "Returning to $orig_ref"
|
echo "Returning to $orig_ref"
|
||||||
git checkout -q "$orig_ref"
|
git checkout -q "$orig_ref"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
git restore -q .
|
restore
|
||||||
fi
|
fi
|
||||||
echo
|
echo
|
||||||
done
|
done
|
||||||
|
|
|
||||||
|
|
@ -129,6 +129,37 @@ commit_with_assertion() {
|
||||||
assert_size_zero readme
|
assert_size_zero readme
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "should restore index when finished" {
|
||||||
|
git checkout -b feature
|
||||||
|
commit_with_assertion $'echo blah >> readme\ngit add readme'
|
||||||
|
|
||||||
|
run git-check-assertions
|
||||||
|
|
||||||
|
assert_success
|
||||||
|
assert_size_zero readme
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "should restore index between commits" {
|
||||||
|
git checkout -b feature
|
||||||
|
commit_with_assertion $'echo blah >> readme\ngit add readme'
|
||||||
|
commit_with_assertion 'cp readme ../test'
|
||||||
|
|
||||||
|
run git-check-assertions
|
||||||
|
|
||||||
|
assert_success
|
||||||
|
assert_size_zero ../test
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "should restore index after a failure" {
|
||||||
|
git checkout -b feature
|
||||||
|
commit_with_assertion $'echo blah >> readme\ngit add 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" {
|
@test "assertions should run against the version of the code inside of the commit" {
|
||||||
git checkout -b feature
|
git checkout -b feature
|
||||||
echo commit1 >readme
|
echo commit1 >readme
|
||||||
|
|
@ -157,6 +188,7 @@ commit_with_assertion() {
|
||||||
run git-check-assertions
|
run git-check-assertions
|
||||||
|
|
||||||
assert_success
|
assert_success
|
||||||
|
assert_file_contains src goodbye
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "assert_success should succeed if the executed command succeeded" {
|
@test "assert_success should succeed if the executed command succeeded" {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue