Merge pull request 'Add support for when the base branch is called master' (#9) from support-base-branch-master into main

Reviewed-on: https://codeberg.org/svenvanheugten/git-check-assertions/pulls/9
This commit is contained in:
Sven van Heugten 2026-03-04 08:01:49 +01:00
commit 8de5bee57f
2 changed files with 37 additions and 9 deletions

View file

@ -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"

View file

@ -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"