From e495aa826efdbe4cede399ef401ad3c6af8f6d9b Mon Sep 17 00:00:00 2001 From: Sven van Heugten Date: Wed, 4 Mar 2026 07:56:22 +0100 Subject: [PATCH 1/2] 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" From 9ecec1ee6deec6be5bbd3b44abb8651c5f1a7da9 Mon Sep 17 00:00:00 2001 From: Sven van Heugten Date: Wed, 4 Mar 2026 07:58:37 +0100 Subject: [PATCH 2/2] Add support for when the base branch is called `master` ```git-check-assertions run ./test/git-check-assertions.bats assert_success ``` --- bin/git-check-assertions | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/bin/git-check-assertions b/bin/git-check-assertions index 4ebc513..53fc277 100755 --- a/bin/git-check-assertions +++ b/bin/git-check-assertions @@ -64,7 +64,15 @@ export -f run assert_success assert_failure assert_output # main flow orig_ref="$(git symbolic-ref --quiet --short HEAD || git rev-parse HEAD)" -base="$(git merge-base main HEAD)" +if git show-ref --verify --quiet refs/heads/main; then + base_branch=main +elif git show-ref --verify --quiet refs/heads/master; then + base_branch=master +else + echo "No main or master branch found." >&2 + exit 1 +fi +base="$(git merge-base "$base_branch" HEAD)" mapfile -t commits < <(git rev-list --reverse "${base}..HEAD") echo "Base: $base"