Skip to content

fix(gastown): handle empty repos in git-manager to prevent mayor crashes#1758

Open
jrf0110 wants to merge 1 commit intomainfrom
gt/birch/04eb503a
Open

fix(gastown): handle empty repos in git-manager to prevent mayor crashes#1758
jrf0110 wants to merge 1 commit intomainfrom
gt/birch/04eb503a

Conversation

@jrf0110
Copy link
Copy Markdown
Contributor

@jrf0110 jrf0110 commented Mar 31, 2026

Summary

Fixes empty repository handling in cloudflare-gastown/container/src/git-manager.ts to prevent mayor crashes when connecting repos with zero commits (GitHub issue #1610).

Three functions are hardened:

  • cloneRepoInner: Removes --branch <defaultBranch> from git clone (fails on empty repos with "Remote branch not found"). After cloning, detects empty repos via git rev-parse HEAD and creates an initial empty commit with --allow-empty, pushes it, and fetches so origin/<defaultBranch> is available for downstream operations.
  • setupBrowseWorktreeInner: Guards against missing origin/<defaultBranch> ref before creating the tracking branch. Returns early with a log message if the ref doesn't exist (e.g., if the push in cloneRepoInner failed).
  • createWorktreeInner: Checks HEAD existence before creating branches. Throws a clear error if the repo has no commits.

Verification

  • Polecat reports typecheck, lint, and format all pass.
  • Code review: validated input sanitization (validateBranchName called before defaultBranch is interpolated into git commands), error handling patterns consistent with existing code, no injection vectors.

Visual Changes

N/A

Reviewer Notes

  • The --branch removal from git clone is safe — downstream code already handles branch tracking via origin/<defaultBranch> refs rather than relying on the clone's initial branch.
  • The empty commit push uses HEAD:<defaultBranch> refspec so it works even when the local branch name doesn't match the remote default branch.
  • All three defensive checks are independently useful: cloneRepoInner prevents the root cause, while setupBrowseWorktreeInner and createWorktreeInner handle the edge case where the initial push fails.

…o and createWorktree

On repos with zero commits, git clone --branch fails because no branch
exists. This caused mayor crashes when connecting empty repos to a rig.

- cloneRepoInner: omit --branch flag, detect empty repo via rev-parse,
  create and push an initial empty commit on the default branch
- setupBrowseWorktreeInner: check origin/<defaultBranch> exists before
  creating tracking branch, skip gracefully if missing
- createWorktreeInner: verify HEAD exists before creating branches,
  throw clear error if repo has no commits

Closes #1610
@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot bot commented Mar 31, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (1 files)
  • cloudflare-gastown/container/src/git-manager.ts

Reviewed by gpt-5.4-20260305 · 341,818 tokens

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.

1 participant