Skip to content

commitchecker: refactor ancestry-path handling and add stale-branch detection#1

Merged
tmshort merged 6 commits intotmshort:debug-ancestry-pathfrom
sanchezl:debug-ancestry-path-review
Mar 25, 2026
Merged

commitchecker: refactor ancestry-path handling and add stale-branch detection#1
tmshort merged 6 commits intotmshort:debug-ancestry-pathfrom
sanchezl:debug-ancestry-path-review

Conversation

@sanchezl
Copy link
Copy Markdown

@sanchezl sanchezl commented Mar 25, 2026

Summary

Review feedback for openshift#114. Split into 6 commits for easier review:

  1. fix .gitignore/commitchecker pattern was matching test files in subdirectories
  2. remove dead code — always-false if err != nil in NewCommitFromOnelineLog
  3. refactor CommitsBetween — split into AllCommitsBetween (no --ancestry-path) and DirectCommitsBetween (with --ancestry-path), both calling a shared gitLog() helper. Restructure main() into explicit calls with listCommits()/validateCommits() helpers
  4. fail on stale branches — when all reachable commits exist but none are on the direct ancestry path, fail with a clear error instead of silently passing. Remove now-unused SameCommit, ErrNoCommitsFound, CheckMode
  5. add testsTestStaleBranch and TestUpToDateBranch create temporary git repos to verify the --ancestry-path behavior
  6. documentation — README limitations section + ancestry-path.md deep-dive

The pattern `commitchecker` matches any file starting with that prefix,
including test files like commits_test.go in subdirectories. Use
`/commitchecker` to only match the built binary at the directory root.
The `if err != nil` check was always false because `err` was declared
as `var err error` and never assigned before the check.
…ectCommitsBetween

Split CommitsBetween (which always used --ancestry-path) into two
explicit functions:
- AllCommitsBetween: finds all non-merge commits reachable from end
  but not start
- DirectCommitsBetween: same, but restricted to the direct ancestry
  path via --ancestry-path

Both call a shared private gitLog() helper. The caller in main() is
updated to call each explicitly instead of looping over CheckMode
values, with shared error handling extracted into listCommits() and
validation into validateCommits().

The error message for git log failures now includes the full command
for easier copy-paste debugging.
When all reachable commits are found but none are on the direct ancestry
path, fail with an error telling the user to rebase. This prevents false
positive passes when a PR branch has fallen behind main.

Also removes SameCommit, ErrNoCommitsFound, and CheckMode which are no
longer used after the refactor.
TestStaleBranch creates a DAG where a PR branch forks from an early
commit, main advances, then the PR is merged. Verifies that
AllCommitsBetween finds the PR commits but DirectCommitsBetween does
not, confirming the --ancestry-path behavior.

TestUpToDateBranch verifies both functions return the same commits on
a linear history.
Add a Limitations section to the README explaining stale-branch
detection, the error message users will see, how to read CI logs,
and how to fix it (rebase the PR).

Add ancestry-path.md with a detailed explanation of --ancestry-path
git semantics, why the commitchecker needs it, and how it can drop
commits on stale branches.
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.

2 participants