Skip to content

Raise instead of guessing main when no default branch is detectable - #1341

Open
itsnevu wants to merge 2 commits into
akashgit:mainfrom
itsnevu:fix/detect-default-branch-no-silent-main
Open

Raise instead of guessing main when no default branch is detectable#1341
itsnevu wants to merge 2 commits into
akashgit:mainfrom
itsnevu:fix/detect-default-branch-no-silent-main

Conversation

@itsnevu

@itsnevu itsnevu commented Aug 20, 2026

Copy link
Copy Markdown

detect_default_branch cascaded through origin/HEAD, a main/master probe, the current HEAD and the symbolic HEAD, then fell back to a hardcoded "main". That last step ran only after the main/master probe had already failed, so "main" was guaranteed not to exist. The bogus branch was handed to create_worktree, which ran git rev-parse and surfaced an opaque "returned non-zero exit status 128" error with no hint about the cause or the fix.

Replace the fallback with a RuntimeError that explains no default branch could be detected and points at the two workarounds: set target_branch in .factory/config.json, or check out a branch.

Adds a test covering a detached HEAD with no main/master and no origin, where detection now raises rather than returning a nonexistent branch.

Fixes #1034

detect_default_branch cascaded through origin/HEAD, a main/master probe, the current HEAD and the symbolic HEAD, then fell back to a hardcoded "main". That last step ran only after the main/master probe had already failed, so "main" was guaranteed not to exist, and the bogus branch was handed to create_worktree, which surfaced an opaque non-zero exit status 128 error. Replace the fallback with a RuntimeError that explains no default branch could be detected.

Fixes akashgit#1034
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.

create_worktree crashes with raw CalledProcessError when detect_default_branch falls back to a nonexistent main

1 participant