From e495aa826efdbe4cede399ef401ad3c6af8f6d9b Mon Sep 17 00:00:00 2001 From: Sven van Heugten Date: Wed, 4 Mar 2026 07:56:22 +0100 Subject: [PATCH] Add a failing test to show that `master` isn't supported ```git-check-assertions run ./test/git-check-assertions.bats assert_failure assert_output --partial "fatal: Not a valid object name main" ``` --- test/git-check-assertions.bats | 36 ++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/test/git-check-assertions.bats b/test/git-check-assertions.bats index 1755820..beb29ca 100755 --- a/test/git-check-assertions.bats +++ b/test/git-check-assertions.bats @@ -1,5 +1,19 @@ #!/usr/bin/env bats +init_repo() { + local repo_dir="$1" + local main_branch="$2" + + mkdir "$repo_dir" + cd "$repo_dir" + git init -b "$main_branch" + git config user.email "john.doe@example.com" + git config user.name "John Doe" + touch readme + git add readme + git commit -m "initial" +} + setup() { set -euo pipefail @@ -10,14 +24,7 @@ setup() { DIR="$(cd "$(dirname "$BATS_TEST_FILENAME")" >/dev/null 2>&1 && pwd)" PATH="$DIR/../bin:$PATH" - mkdir "$BATS_TEST_TMPDIR/repo" - cd "$BATS_TEST_TMPDIR/repo" - git init -b main - git config user.email "john.doe@example.com" - git config user.name "John Doe" - touch readme - git add readme - git commit -m "initial" + init_repo "$BATS_TEST_TMPDIR/repo" main } commit_with_assertion() { @@ -50,6 +57,19 @@ commit_with_assertion() { assert_file_not_exists ../test } +@test "should not run any assertion blocks from master when on a feature branch" { + init_repo "$BATS_TEST_TMPDIR/repo-master" master + + commit_with_assertion "touch ../test" + git checkout -b feature + git commit --allow-empty -m "feature" + + run git-check-assertions + + assert_success + assert_file_not_exists ../test +} + @test "should run all succeeding assertion blocks on the feature branch and finally return to the original branch" { git checkout -b feature commit_with_assertion "touch ../test1"