Add support for multiple git-check-assertions blocks
This commit is contained in:
parent
80ff74cdf9
commit
7e483b8a7f
4 changed files with 31 additions and 6 deletions
|
|
@ -106,11 +106,11 @@ for commit_hash in "${commits[@]}"; do
|
||||||
echo "Checking out $commit_hash"
|
echo "Checking out $commit_hash"
|
||||||
git -c advice.detachedHead=false checkout -q "$commit_hash"
|
git -c advice.detachedHead=false checkout -q "$commit_hash"
|
||||||
commit_msg="$(git log -1 --format=%B "$commit_hash")"
|
commit_msg="$(git log -1 --format=%B "$commit_hash")"
|
||||||
# shellcheck disable=SC2016
|
mapfile -d '' -t blocks < <(
|
||||||
block="$(printf '%s\n' "$commit_msg" |
|
printf '%s\n' "$commit_msg" |
|
||||||
sed -n '/^```git-check-assertions[[:space:]]*$/,/^```[[:space:]]*$/p' |
|
perl -0777 -ne 'while (/^```git-check-assertions\s*\n(.*?)^```\s*$/msg){ print $1, "\0" }'
|
||||||
sed '1d;$d')"
|
)
|
||||||
if [ -n "$block" ]; then
|
for block in "${blocks[@]}"; do
|
||||||
echo "git-check-assertions block in $commit_hash:"
|
echo "git-check-assertions block in $commit_hash:"
|
||||||
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
|
||||||
|
|
@ -121,7 +121,7 @@ for commit_hash in "${commits[@]}"; do
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
restore
|
restore
|
||||||
fi
|
done
|
||||||
printf '%s\n' "$commit_hash" >>.git-check-assertions-cache
|
printf '%s\n' "$commit_hash" >>.git-check-assertions-cache
|
||||||
echo
|
echo
|
||||||
done
|
done
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
gitMinimal,
|
gitMinimal,
|
||||||
resholve,
|
resholve,
|
||||||
shfmt,
|
shfmt,
|
||||||
|
perl,
|
||||||
}:
|
}:
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
@ -40,6 +41,7 @@ resholve.mkDerivation {
|
||||||
]))
|
]))
|
||||||
gitMinimal
|
gitMinimal
|
||||||
shfmt
|
shfmt
|
||||||
|
perl
|
||||||
];
|
];
|
||||||
|
|
||||||
checkPhase = ''
|
checkPhase = ''
|
||||||
|
|
@ -66,6 +68,7 @@ resholve.mkDerivation {
|
||||||
gitMinimal
|
gitMinimal
|
||||||
gnused
|
gnused
|
||||||
bash
|
bash
|
||||||
|
perl
|
||||||
];
|
];
|
||||||
execer = [
|
execer = [
|
||||||
# Not true at all, but ¯\_(ツ)_/¯
|
# Not true at all, but ¯\_(ツ)_/¯
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@
|
||||||
p.bats-support
|
p.bats-support
|
||||||
p.bats-file
|
p.bats-file
|
||||||
]))
|
]))
|
||||||
|
pkgs.perl
|
||||||
pkgs.shfmt
|
pkgs.shfmt
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -124,6 +124,27 @@ commit_with_assertion() {
|
||||||
assert_output "feature"
|
assert_output "feature"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "multiple git-check-assertions blocks in one commit message run in order" {
|
||||||
|
git checkout -b feature
|
||||||
|
git commit --allow-empty -F - <<-EOF
|
||||||
|
test
|
||||||
|
|
||||||
|
\`\`\`git-check-assertions
|
||||||
|
touch ../test1
|
||||||
|
\`\`\`
|
||||||
|
|
||||||
|
\`\`\`git-check-assertions
|
||||||
|
touch ../test2
|
||||||
|
\`\`\`
|
||||||
|
EOF
|
||||||
|
|
||||||
|
run git-check-assertions
|
||||||
|
|
||||||
|
assert_success
|
||||||
|
assert_file_exists ../test1
|
||||||
|
assert_file_exists ../test2
|
||||||
|
}
|
||||||
|
|
||||||
@test "should stop at the first failing assertion block and return to the original branch" {
|
@test "should stop at the first failing assertion block and return to the original branch" {
|
||||||
git checkout -b feature
|
git checkout -b feature
|
||||||
commit_with_assertion "touch ../test1 && exit 3"
|
commit_with_assertion "touch ../test1 && exit 3"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue