fix(gastown): handle empty repos in git-manager to prevent mayor crashes#1758
Open
fix(gastown): handle empty repos in git-manager to prevent mayor crashes#1758
Conversation
…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
Contributor
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (1 files)
Reviewed by gpt-5.4-20260305 · 341,818 tokens |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes empty repository handling in
cloudflare-gastown/container/src/git-manager.tsto prevent mayor crashes when connecting repos with zero commits (GitHub issue #1610).Three functions are hardened:
cloneRepoInner: Removes--branch <defaultBranch>fromgit clone(fails on empty repos with "Remote branch not found"). After cloning, detects empty repos viagit rev-parse HEADand creates an initial empty commit with--allow-empty, pushes it, and fetches soorigin/<defaultBranch>is available for downstream operations.setupBrowseWorktreeInner: Guards against missingorigin/<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
validateBranchNamecalled beforedefaultBranchis interpolated into git commands), error handling patterns consistent with existing code, no injection vectors.Visual Changes
N/A
Reviewer Notes
--branchremoval fromgit cloneis safe — downstream code already handles branch tracking viaorigin/<defaultBranch>refs rather than relying on the clone's initial branch.HEAD:<defaultBranch>refspec so it works even when the local branch name doesn't match the remote default branch.