🐛 Skip branch push when a run produces no commits - #114
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThe harness now records the stage’s initial commit, skips pushes when no new commits exist, returns push status, and reports no-op or partial outcomes. Git tests cover lifecycle, new-commit, empty-push, and staged-push behavior. A changelog entry documents the fix. ChangesEmpty push handling
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| func HeadSHA(repo *gogit.Repository) (string, error) { | ||
| head, err := repo.Head() | ||
| if err != nil { | ||
| return "", fmt.Errorf("resolve HEAD: %w", err) |
There was a problem hiding this comment.
Nit: this check looks redundant with the NoErrAlreadyUpToDate swallow below, but it's actually the only guard that prevents empty branch creation on the remote. When the branch doesn't exist yet, go-git's PushContext generates a push command (ZeroHash → local HEAD), so NoErrAlreadyUpToDate never fires.
A short comment above the if baseSHA != "" block explaining this distinction would prevent a future maintainer from removing it as belt-and-suspenders.
There was a problem hiding this comment.
Good call — comment added in b7c7c7e capturing exactly that: on a missing remote branch PushContext sends a create command (ZeroHash → HEAD), so NoErrAlreadyUpToDate never fires and this guard is the only thing preventing empty branch creation.
|
Misleading status notices on no-op runs When Consider having |
Review follow-ups from konveyor#114: Push now returns whether it actually pushed, and the run notices use it so a skipped push reads "no changes to push" instead of claiming results landed on the branch. The failure/cancel notices only mention partial work when a push happened. A comment above the baseSHA guard records why it is not redundant with the NoErrAlreadyUpToDate swallow: on a missing remote branch PushContext sends a create command, so that error never fires and the guard is the only thing preventing empty branch creation. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: ibolton336 <[email protected]>
|
Fixed in b7c7c7e — |
savitharaghunathan
left a comment
There was a problem hiding this comment.
Clean, well-scoped bugfix. The approach is sound:
- Base SHA captured immediately after clone/checkout, before any harness work
- Empty
baseSHA(fromHeadSHAfailure) fails open — never blocks a real push - The guard at
git.go:205-210correctly handles the case where the remote branch doesn't exist yet (go-git sends a create command rather than reporting up-to-date, soNoErrAlreadyUpToDatealone wouldn't prevent empty branch creation) - Exit notices now branch on the
pushedbool so messages are honest about what happened
Tests cover the three key scenarios: no-op skip, normal push, and multi-stage workflow where a later stage adds no new commits.
No bugs found. LGTM.
The harness pushed the target branch ref unconditionally on exit, so no-op, refused, and skill-less runs littered real repositories with one empty branch per run — multiplied by bulk workflow fan-out. Push now compares HEAD against the SHA captured after clone/checkout and skips, with an explicit log line, when the run produced nothing. Signed-off-by: ibolton336 <[email protected]> Co-Authored-By: Claude Fable 5 <[email protected]>
Review follow-ups from konveyor#114: Push now returns whether it actually pushed, and the run notices use it so a skipped push reads "no changes to push" instead of claiming results landed on the branch. The failure/cancel notices only mention partial work when a push happened. A comment above the baseSHA guard records why it is not redundant with the NoErrAlreadyUpToDate swallow: on a missing remote branch PushContext sends a create command, so that error never fires and the guard is the only thing preventing empty branch creation. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: ibolton336 <[email protected]>
b7c7c7e to
06e1ab7
Compare
The harness pushed the target branch ref unconditionally on exit, so no-op, refused, and skill-less runs each left an empty branch on the real repository — observed live as a stray
konveyor/migration-…branch on konveyor/analyzer-lsp, and about to be multiplied by bulk workflow fan-out (one run per application).Pushnow takes the base SHA captured immediately after clone/checkout and skips — with an explicitno commits produced; skipping push of <branch>log line — when HEAD still equals it. An empty base fails open: an unknown base must never block a push of real work. The watcher push path is covered too; it fires on filesystem events even with zero commits, so it was a second litter vector.Deliberate caveats:
Tests: skip-on-no-commits (remote branch creation proven before the fix), push-with-commits byte-identical, and the workflow-stage case (a later stage adding no new commits skips; remote tip asserted unchanged). Harness module green under
-race.🤖 Generated with Claude Code
Summary by CodeRabbit