Skip to content

repository: fix the testing branch error message - #225

Merged
nlewo merged 1 commit into
nlewo:mainfrom
RyoKusnadi:fix/testing-branch-error-message
Nov 5, 2026
Merged

nlewo merged 1 commit into
nlewo:mainfrom
RyoKusnadi:fix/testing-branch-error-message

Conversation

@RyoKusnadi

Copy link
Copy Markdown
Contributor

How it happens: comin is configured with a testing branch. Someone force-pushes that branch to a commit that does not contain the current main commit (for example after main moved on and testing was not rebased). comin status then shows "this branch has been hard reset", which is wrong because hard resetting the testing branch is allowed.

Problem

For a testing branch, the status error says "this branch has been hard reset: its head ... is not on top of ...". Hard resets of the testing branch are allowed, so the message points at the wrong cause. The real rule is that testing must be on top of the main branch.

Cause

hasNotBeenHardReset in internal/repository/git.go builds one message for both branches. Update in internal/repository/repository.go calls it for the main branch and for the testing branch.

Fix

getHeadFromRemoteAndBranch and hasNotBeenHardReset now get an isTesting flag. For testing the error is "this branch is not on top of the main branch: its head 'X' is not on top of 'Y'". The main branch message is unchanged, since a hard reset of main is really not allowed. I chose a flag over a second function to keep the shared ancestor check in one place.

Scope

Only the message text and the two call sites changed. No behavior change in which branch gets selected.

Testing

TestTestingHardReset now resets testing to a commit that is not on top of main and checks the message.

  • Before the fix it fails: "this branch has been hard reset: ..." does not contain "not on top of the main branch".
  • After the fix it passes.
  • Ran: go vet ./internal/repository/ && go test ./internal/repository/ (both pass), gofmt -l on touched files (clean).
  • Not run: the other packages, the Nix build and tests.

Fixes #220

A testing branch can be hard reset as long as it stays on top of the
main branch, so the error no longer says it has been hard reset.

Signed-off-by: Ryo Kusnadi <ryokusnadi@gmail.com>
@nlewo
nlewo merged commit 004a55c into nlewo:main Nov 5, 2026
2 checks passed
@RyoKusnadi
RyoKusnadi deleted the fix/testing-branch-error-message branch November 5, 2026 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix the testing hard reset error message

2 participants