Skip to content

feat(zerogit): auto-create a conventional branch before push/pr on default branch#671

Open
euxaristia wants to merge 5 commits into
Gitlawb:mainfrom
euxaristia:euxaristia/auto-branch-naming-for-changes-workflow
Open

feat(zerogit): auto-create a conventional branch before push/pr on default branch#671
euxaristia wants to merge 5 commits into
Gitlawb:mainfrom
euxaristia:euxaristia/auto-branch-naming-for-changes-workflow

Conversation

@euxaristia

@euxaristia euxaristia commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Summary

  • zero changes push and zero changes pr currently refuse to push straight to the default branch (main/master) but don't offer any alternative, so hitting that guard is a dead end.
  • Added CreateBranch, IsDefaultBranch, CurrentGitUser, SlugifyBranchComponent, and BuildBranchName to internal/zerogit.
  • push/pr now call a new ensureFeatureBranch step: if the current branch is the default branch and neither --yes nor --dry-run was passed, it generates a short slug for the diff (via the configured LLM provider, falling back to a deterministic slug derived from the changed files if no provider is configured) and checks out <git user>/<slug> before pushing. --yes and --dry-run bypass this entirely, preserving the existing refuse/preview behavior.

Linked issue

None. This came out of a direct discussion about zero having no defined branch-naming convention, not a filed issue.

Test plan

  • go build ./...
  • go vet ./...
  • go test ./... (all green except a pre-existing, unrelated failure in internal/contextreport that also fails on unmodified main)
  • gofmt -l clean on all changed files
  • New unit tests in internal/zerogit/zerogit_test.go (CreateBranch, IsDefaultBranch, CurrentGitUser, SlugifyBranchComponent, BuildBranchName)
  • New CLI-level tests in internal/cli/workflow_test.go covering ensureFeatureBranch directly (default-branch creation with/without a provider, skip when already off default, skip on --yes/--dry-run) and end-to-end through zero changes push

Summary by CodeRabbit

  • New Features
    • changes push and changes pr now auto-create and use a non-default feature branch when run from the default branch.
    • Branch names are now generated with consistent sanitization (kebab-case, safe formatting like user/slug) and optional AI-assisted naming for push/pr when enabled.
    • --message validation is improved, and --auto is supported for commit, push, and pr.
  • Bug Fixes
    • Default-branch verification is stricter (fails closed) and safer when the remote can’t be verified; --yes and dry-run behavior are respected.
  • Tests
    • Expanded CLI and git-helper test coverage for branch naming, skip/gating rules, and dry-run/--yes edge cases.

…fault branch

zero changes push/pr refused to push straight to the default branch but
never offered an alternative, unlike other agent tooling that names and
checks out a feature branch automatically. Add CreateBranch, IsDefaultBranch,
CurrentGitUser, and branch-name slugify/build helpers to zerogit, and wire
push/pr to auto-create a "<user>/<slug>" branch (slug from an LLM when a
provider is configured, otherwise a deterministic fallback from the diff)
whenever the current branch is the default one and --yes/--dry-run weren't
passed.
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e76de349-0d25-4ef0-9bb5-181bea72410b

📥 Commits

Reviewing files that changed from the base of the PR and between 68bcce3 and f6f2a6c.

📒 Files selected for processing (1)
  • internal/zerogit/zerogit_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/zerogit/zerogit_test.go

Walkthrough

Adds Git branch-management APIs and wires them into CLI workflows so changes push and changes pr can create conventionally named feature branches using deterministic or LLM-generated slugs, with expanded validation and test coverage.

Changes

Automatic feature branch routing

Layer / File(s) Summary
Git branch management APIs
internal/zerogit/zerogit.go, internal/zerogit/zerogit_test.go
Adds default-branch detection, branch creation, Git-user lookup, slugification, protected-branch safeguards, and corresponding unit tests.
CLI Git dependency wiring
internal/cli/app.go
Adds injectable branch-management dependencies and fills them from zerogit by default.
Feature branch generation
internal/cli/workflows.go, internal/cli/workflow_test.go
Adds default-branch checks, deterministic or provider-generated slugs, clean-tree commit fallback naming, argument validation, and branch-creation tests.
Push and PR workflow integration
internal/cli/workflows.go, internal/cli/workflow_test.go
Passes ensured branch names and resolved remotes into push and PR flows, including --yes, dry-run, and default-branch scenarios.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant runChangesPush
  participant ensureFeatureBranch
  participant zerogit
  participant pushChanges
  User->>runChangesPush: invoke changes push
  runChangesPush->>ensureFeatureBranch: determine branch target
  ensureFeatureBranch->>zerogit: resolve default branch and Git user
  ensureFeatureBranch->>zerogit: create computed feature branch
  runChangesPush->>pushChanges: push to ensured branch and remote
Loading

Possibly related PRs

  • Gitlawb/zero#391: Adds the changes push/PR handlers and zerogit push/PR APIs that these workflows now route through feature-branch creation.
  • Gitlawb/zero#423: Updates --auto handling for changes commit, which this PR extends to push and PR branch naming.

Suggested reviewers: vasanthdev2004

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: automatically creating a feature branch before push/pr on the default branch.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (4)
internal/zerogit/zerogit_test.go (2)

836-848: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

CurrentGitUser's fallback branches (OS username, literal "user") are untested.

Only the git config user.name success path is covered. The two fallback tiers (L715-718 in zerogit.go) have no coverage, at least a case where the fake runner errors/returns empty output to exercise the OS-username path.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/zerogit/zerogit_test.go` around lines 836 - 848, Extend
TestCurrentGitUser to cover CurrentGitUser’s fallback behavior when git config
returns an error or empty output, asserting the OS-username fallback and command
invocation; also add coverage for the final literal "user" fallback when no OS
username is available.

731-792: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Missing coverage for CreateBranch failing to check out (e.g. branch already exists).

All three subtests exercise success/dry-run/empty-name paths; none exercise the git checkout -b failure branch (L700-702 in zerogit.go), which is exactly the scenario that occurs on a name collision. Worth adding a subtest that returns a non-nil error/non-zero exit from the checkout call and asserts the wrapped error message.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/zerogit/zerogit_test.go` around lines 731 - 792, The
TestCreateBranch coverage should include checkout failure, such as an existing
branch name. Add a subtest alongside HappyPath and DryRunDoesNotCheckout using
fakeRunner to return a non-zero/error result for the checkout invocation, then
assert CreateBranch returns an error containing the wrapped checkout failure
message.
internal/cli/workflows.go (1)

1029-1060: 🚀 Performance & Scalability | 🔵 Trivial

Extra LLM round-trip added to every default-branch push/PR without --yes.

When on the default branch (and no --yes/dry-run), ensureFeatureBranch now performs its own StreamCompletion call to name the branch, on top of any existing commit-message-generation LLM call in the same flow. That's an additional ~60s-capped network round trip and provider cost on a very common path (any push straight from main). Worth being aware of for latency/cost budgeting, and consider whether the fallback slug is "good enough" to skip the LLM call by default (e.g., behind a flag) rather than always attempting it whenever a provider is configured.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/cli/workflows.go` around lines 1029 - 1060, The ensureFeatureBranch
flow should not automatically perform an LLM request on every default-branch
push or PR. Use fallbackBranchSlug(summary) by default and gate
generateAutoBranchSlug behind an explicit opt-in configuration or flag,
preserving the existing branch-generation behavior when that opt-in is enabled.
internal/cli/workflow_test.go (1)

918-980: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

No CLI-level test for runChangesPR + ensureFeatureBranch integration.

Coverage is added for ensureFeatureBranch in isolation and for runChangesPush (Lines 918-980), but runChangesPR also now routes through ensureFeatureBranch and forwards the ensured branch into PushOptions.Branch (workflows.go Lines 924-928, 937). Given pr hardcodes dryRun=false unlike push, this path deserves its own targeted test (e.g. mirroring TestRunChangesPushCreatesFeatureBranchWhenOnDefault for changes pr on the default branch) to lock in the new behavior before it ships.

Want me to draft that test?

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/cli/workflow_test.go` around lines 918 - 980, The CLI tests cover
feature-branch creation for runChangesPush but not the equivalent runChangesPR
flow. Add a targeted test for changes pr on the default branch, verifying
ensureFeatureBranch creates the expected branch and that runChangesPR forwards
it through PushOptions.Branch, while preserving the existing dryRun=false
behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/cli/workflows.go`:
- Around line 1087-1116: Update generateAutoBranchSlug to normalize
collected.Text before passing it to zerogit.SlugifyBranchComponent: select the
first non-empty line, trim surrounding whitespace and quotes, then slugify that
single-line value. Preserve the existing empty-slug error handling and provider
error propagation.

In `@internal/zerogit/zerogit.go`:
- Around line 637-662: Bound the remote lookup performed by IsDefaultBranch,
especially the isDefaultBranch call that may execute git ls-remote, with a short
context timeout even when the caller supplies context.Background(). On timeout
or remote lookup failure, preserve the existing local main/master fallback so
changes push/pr do not stall.
- Around line 677-704: Update CreateBranch to handle an already-existing local
branch before treating branch creation as failed: detect whether the requested
name exists locally, check it out and return the same BranchResult when it does,
while retaining checkout -b for new branches and preserving DryRun behavior.

---

Nitpick comments:
In `@internal/cli/workflow_test.go`:
- Around line 918-980: The CLI tests cover feature-branch creation for
runChangesPush but not the equivalent runChangesPR flow. Add a targeted test for
changes pr on the default branch, verifying ensureFeatureBranch creates the
expected branch and that runChangesPR forwards it through PushOptions.Branch,
while preserving the existing dryRun=false behavior.

In `@internal/cli/workflows.go`:
- Around line 1029-1060: The ensureFeatureBranch flow should not automatically
perform an LLM request on every default-branch push or PR. Use
fallbackBranchSlug(summary) by default and gate generateAutoBranchSlug behind an
explicit opt-in configuration or flag, preserving the existing branch-generation
behavior when that opt-in is enabled.

In `@internal/zerogit/zerogit_test.go`:
- Around line 836-848: Extend TestCurrentGitUser to cover CurrentGitUser’s
fallback behavior when git config returns an error or empty output, asserting
the OS-username fallback and command invocation; also add coverage for the final
literal "user" fallback when no OS username is available.
- Around line 731-792: The TestCreateBranch coverage should include checkout
failure, such as an existing branch name. Add a subtest alongside HappyPath and
DryRunDoesNotCheckout using fakeRunner to return a non-zero/error result for the
checkout invocation, then assert CreateBranch returns an error containing the
wrapped checkout failure message.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f58092c2-d708-4e9f-b966-136d674d41ae

📥 Commits

Reviewing files that changed from the base of the PR and between 80c39aa and 39cfc2e.

📒 Files selected for processing (5)
  • internal/cli/app.go
  • internal/cli/workflow_test.go
  • internal/cli/workflows.go
  • internal/zerogit/zerogit.go
  • internal/zerogit/zerogit_test.go

Comment thread internal/cli/workflows.go
Comment thread internal/zerogit/zerogit.go Outdated
Comment thread internal/zerogit/zerogit.go
… existing branches

Address CodeRabbit's review on the auto-branch-naming PR:

- generateAutoBranchSlug now takes the first non-empty, quote-trimmed
  line of the model's response before slugifying, instead of folding
  any preamble or wrapping quotes into the branch name.
- isDefaultBranch's ls-remote lookup is now bounded by a 5s timeout so
  a slow or unreachable remote can't stall push/pr; falls back to the
  local main/master heuristic as before.
- CreateBranch checks whether the target branch already exists locally
  and checks it out instead of failing checkout -b on the collision.

Also add regression coverage: CurrentGitUser's OS-username fallback
tier, CreateBranch's existing-branch and generic checkout-failure
paths, a CLI-level test for changes pr (previously untested) mirroring
the existing changes push coverage, and a messy-LLM-response case for
the slug normalization fix.
@euxaristia

Copy link
Copy Markdown
Contributor Author

Addressed the review, including the nitpicks.

Actionable:

  • generateAutoBranchSlug now takes the first non-empty, quote-trimmed line of the model's response before slugifying, instead of folding any preamble or wrapping quotes into the branch name.
  • isDefaultBranch's ls-remote lookup is now bounded by a 5s timeout, so a slow or unreachable remote can't stall push/pr; falls back to the local main/master heuristic as before.
  • CreateBranch now checks whether the target branch already exists locally and checks it out instead of failing checkout -b on the collision.

Nitpicks fixed:

  • Added coverage for CurrentGitUser's OS-username fallback tier (the third "literal user" tier isn't independently testable without adding an injection seam to os/user.Current, noted in the test comment).
  • Added coverage for CreateBranch's new existing-branch path and a genuine checkout -b failure.
  • Added a CLI-level test for changes pr + ensureFeatureBranch (there was no changes pr coverage at all before this), mirroring the existing changes push test.

One nitpick I'm leaving as-is: the extra LLM round-trip on every default-branch push without --yes. That's the intended behavior, not a bug: the LLM slug is the actual point of this feature, --yes/--dry-run already bypass it for anyone who wants to skip it, and gating it behind a further flag is new config surface for a cost/latency observation rather than a correctness issue.

go vet, go build ./..., and go test -race -count=1 ./internal/zerogit/... ./internal/cli/... are all clean.

@jatmn jatmn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found issues that need to be addressed before this is ready.

Findings

  • [P1] Keep branch generation from selecting an unrelated local branch
    internal/cli/workflows.go:1042-1063, internal/zerogit/zerogit.go:709-718
    changes push normally runs after changes commit, so the working tree inspected here is clean and the fallback name is always user/changes (the provider path likewise receives an empty diff). On a later push, or whenever a low-entropy fallback/LLM name already exists locally, CreateBranch checks out that arbitrary existing ref instead of creating a branch at the current default-branch HEAD. The subsequent push/PR then publishes the stale branch while leaving the user's new commit on main. Do not treat a name collision as a retry unless its history is proven to be the intended current work; use a unique name or fail visibly, and cover the ordinary commit-then-push sequence.

  • [P1] Preserve and use the actual target remote throughout auto-branching
    internal/cli/workflows.go:866-878, internal/cli/workflows.go:924-940, internal/cli/workflows.go:1034, internal/zerogit/zerogit.go:574-585
    The preflight always checks origin, while the original push may target --remote or the current branch's configured upstream. After creating a branch, that new branch has no tracking configuration, so Push falls back to origin as well. In a fork/upstream setup this can either leave the advertised default-branch dead end intact (the target remote identifies the branch as default after the origin preflight skipped creation) or push/create the PR against origin rather than the source branch's upstream. Resolve the remote once before branching, pass it to IsDefaultBranch, and pass the same resolved remote to Push; add non-origin/upstream coverage.

  • [P1] Do not fail open when default-branch lookup times out
    internal/zerogit/zerogit.go:616-629
    The new five-second deadline applies to the existing guard in Push as well as the new preflight. If ls-remote --symref takes longer than five seconds for a repository whose default is trunk/develop, the fallback only recognizes main and master; Push then proceeds without --yes. Before this change it waited for the remote answer and preserved the confirmation guard. A lookup timeout needs to fail closed (or use a trusted local default reference), not be treated as evidence that an arbitrary branch is unprotected.

  • [P1] Do not upload a diff during ordinary push/PR without an explicit opt-in
    internal/cli/workflows.go:1048-1055
    A configured provider now causes every default-branch changes push/changes pr to send the full change diff to that provider. These commands were previously git-only; the existing LLM behavior is explicitly requested through changes commit --auto. redactChangeSummary removes secret-shaped values but intentionally retains ordinary source code, so this silently exports proprietary code (and JSON mode gives no notice). Keep the deterministic local naming path by default and require an explicit LLM opt-in before constructing this completion request.

…ail-closed, and opt-in for LLM naming

- CreateBranch never checks out an existing branch on a name collision: it
  picks a unique suffixed name off the current HEAD (name-2 .. name-9) and
  fails visibly when the namespace is exhausted, so a stale branch with
  unrelated history can no longer be published while the new commit stays
  behind on the default branch.
- ensureFeatureBranch resolves the remote once (explicit --remote, then the
  original branch's configured upstream, then origin) via IsDefaultBranch,
  which now reports the resolved remote, and push/pr thread that remote into
  Push, so a freshly created branch without tracking configuration no longer
  falls back to origin in fork setups.
- The default-branch check fails closed: main and master count as default
  with no network, an unreachable remote falls back to the local
  refs/remotes/<remote>/HEAD record, and when neither answers the push is
  refused with guidance instead of silently dropping the confirmation guard
  for repositories whose default is trunk or develop.
- LLM branch naming is now opt-in via --auto on push/pr, matching commit
  --auto: a configured provider alone no longer causes the change diff to be
  uploaded during ordinary git-only pushes.
- After the ordinary commit-then-push sequence the tree is clean, so the
  fallback name comes from the HEAD commit subject instead of the constant
  user/changes.
@euxaristia

Copy link
Copy Markdown
Contributor Author

Pushed e3ec76f (plus gofmt fixup 68bcce3) for all four findings.

  • Branch collisions: CreateBranch no longer checks out an existing branch under the generated name. It picks a unique suffixed name at the current HEAD (name-2 through name-9) and fails visibly when the namespace is exhausted, so an old branch with unrelated history can no longer be published while the new commit stays behind on main. The ordinary commit-then-push sequence is also covered now: with a clean tree the fallback name comes from the HEAD commit subject instead of the constant user/changes, so repeat pushes stop colliding on the same low-entropy name in the first place. Covered by TestCreateBranch/SuffixesNameInsteadOfCheckingOutExistingBranch, FailsVisiblyWhenSuffixNamespaceExhausted, and TestEnsureFeatureBranchNamesFromHeadCommitAfterCommit.
  • Remote resolution: IsDefaultBranch now resolves the remote the same way Push does (explicit --remote, then the branch's configured upstream, then origin) and reports it; ensureFeatureBranch resolves it once against the original branch and push/pr thread it into Push, so a freshly created branch with no tracking configuration no longer silently retargets origin in fork setups. Covered by TestIsDefaultBranch/ResolvesRemoteFromBranchUpstream and TestRunChangesPushUsesResolvedRemoteForNewBranch.
  • Fail closed: main and master count as default with no network at all (the safe direction). When the remote lookup fails, the check falls back to the local refs/remotes//HEAD record, which needs no network; if that record is also missing, the check errors with guidance (git remote set-head) instead of silently downgrading to the main/master heuristic and dropping the guard for trunk/develop repositories. Covered by TestIsDefaultBranch/FallsBackToLocalRemoteHeadRecord and FailsClosedWhenDefaultBranchUnknown.
  • LLM opt-in: branch naming only calls the provider when --auto is passed to push/pr, mirroring commit --auto, and only when the diff is non-empty. A configured provider alone no longer causes the change diff to be uploaded during ordinary pushes; without the flag the name is derived from deterministic local information. Covered by TestEnsureFeatureBranchDoesNotCallProviderWithoutAuto; the help text documents the flag's new scope.

go build, go vet, and the zerogit and cli suites pass locally.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
internal/zerogit/zerogit_test.go (1)

527-668: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Missing coverage for Push's new fail-closed error path.

TestPushBranchesToRemote exercises isDefault == true (RejectsDefaultBranch) and isDefault == false (HappyPath, FlagsForceAndDryRun, FallbackRemoteToOrigin), but none of the subtests drive isDefaultBranch into returning an error (remote lookup fails and no local refs/remotes/<remote>/HEAD record) to verify Push's new wrapping at Line 585-587 ("cannot verify %q is not the default/protected branch: %w; use --yes to override"). This is the actual new logic added to Push in this PR and is otherwise only exercised indirectly via IsDefaultBranch's own FailsClosedWhenDefaultBranchUnknown test, which doesn't go through Push.

✅ Suggested additional subtest
t.Run("FailsWhenDefaultBranchCannotBeVerified", func(t *testing.T) {
    root := t.TempDir()
    runner := &fakeRunner{results: []CommandResult{
        {Stdout: root + "\n"},
        {Stdout: "feat/some-feature\n"},
        {Stdout: "origin\n"},
        {ExitCode: 128, Stderr: "fatal:"}, // ls-remote fails
        {ExitCode: 1},                     // no local refs/remotes/origin/HEAD record
    }}

    _, err := Push(context.Background(), PushOptions{
        Cwd:    root,
        RunGit: runner.Run,
    })
    if err == nil || !strings.Contains(err.Error(), "use --yes to override") {
        t.Fatalf("expected fail-closed error, got %v", err)
    }
})
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/zerogit/zerogit_test.go` around lines 527 - 668, Add a
FailsWhenDefaultBranchCannotBeVerified subtest to TestPushBranchesToRemote that
makes ls-remote fail and the local refs/remotes/origin/HEAD lookup fail, then
assert Push returns an error containing “use --yes to override.” Ensure the fake
runner sequence reaches Push’s wrapped isDefaultBranch error path rather than
the existing successful or protected-branch paths.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@internal/zerogit/zerogit_test.go`:
- Around line 527-668: Add a FailsWhenDefaultBranchCannotBeVerified subtest to
TestPushBranchesToRemote that makes ls-remote fail and the local
refs/remotes/origin/HEAD lookup fail, then assert Push returns an error
containing “use --yes to override.” Ensure the fake runner sequence reaches
Push’s wrapped isDefaultBranch error path rather than the existing successful or
protected-branch paths.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 16f16bb3-6e00-490a-b235-ab360363f2d3

📥 Commits

Reviewing files that changed from the base of the PR and between 8fb4f08 and 68bcce3.

📒 Files selected for processing (5)
  • internal/cli/app.go
  • internal/cli/workflow_test.go
  • internal/cli/workflows.go
  • internal/zerogit/zerogit.go
  • internal/zerogit/zerogit_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/cli/app.go
  • internal/cli/workflows.go

@euxaristia

Copy link
Copy Markdown
Contributor Author

Pushed a subtest for CodeRabbit's coverage nitpick: TestPushBranchesToRemote/FailsWhenDefaultBranchCannotBeVerified drives the remote lookup and the local refs/remotes/origin/HEAD record to fail and asserts Push itself refuses with the use --yes guidance, exercising the new fail-closed wrapping directly rather than only through IsDefaultBranch.

@Vasanthdev2004 Vasanthdev2004 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. The feature is well-gated branch creation skips on --yes/--dry-run, and the LLM naming path is opt-in via --auto with the diff redacted before it leaves the machine and I like that you hardened isDefaultBranch to fail closed instead of silently downgrading to the main/master name heuristic when the remote lookup times out. Two small things worth a glance: isDefaultBranch now short-circuits on the literal names main/master before consulting the remote, so a repo whose real default is trunk would treat a local feature branch named main as the default (safe direction it only blocks a push, never permits one but slightly surprising); and if the LLM slug generation fails after printing "Generating branch name using LLM..." it silently falls back to the deterministic slug with no follow-up message, which could confuse a user waiting on the LLM. Neither blocks merge.

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.

3 participants