Merge pull request 'Check initial state before running' (#11) from check-initial-state into main
Reviewed-on: https://codeberg.org/svenvanheugten/git-check-assertions/pulls/11
This commit is contained in:
commit
b3db4fcf2b
2 changed files with 32 additions and 0 deletions
|
|
@ -63,6 +63,10 @@ assert_output() {
|
|||
export -f run assert_success assert_failure assert_output
|
||||
|
||||
# main flow
|
||||
if [ ! -z "$(git status --porcelain)" ]; then
|
||||
echo "Uncommitted changes. Refusing to run." >&2
|
||||
exit 1
|
||||
fi
|
||||
orig_ref="$(git symbolic-ref --quiet --short HEAD || git rev-parse HEAD)"
|
||||
if git show-ref --verify --quiet refs/heads/main; then
|
||||
base_branch=main
|
||||
|
|
|
|||
|
|
@ -46,6 +46,34 @@ commit_with_assertion() {
|
|||
assert_file_not_exists ../test
|
||||
}
|
||||
|
||||
@test "should refuse to run when the index has changes" {
|
||||
echo "staged" >>readme
|
||||
git add readme
|
||||
|
||||
run git-check-assertions
|
||||
|
||||
assert_failure
|
||||
assert_output --partial "Uncommitted changes. Refusing to run."
|
||||
}
|
||||
|
||||
@test "should refuse to run when the working tree has changes" {
|
||||
echo "unstaged" >>readme
|
||||
|
||||
run git-check-assertions
|
||||
|
||||
assert_failure
|
||||
assert_output --partial "Uncommitted changes. Refusing to run."
|
||||
}
|
||||
|
||||
@test "should refuse to run when there are untracked files" {
|
||||
echo "new" >untracked
|
||||
|
||||
run git-check-assertions
|
||||
|
||||
assert_failure
|
||||
assert_output --partial "Uncommitted changes. Refusing to run."
|
||||
}
|
||||
|
||||
@test "should not run any assertion blocks from main when on a feature branch" {
|
||||
commit_with_assertion "touch ../test"
|
||||
git checkout -b feature
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue