Raise instead of guessing main when no default branch is detectable - #1341
Open
itsnevu wants to merge 2 commits into
Open
Raise instead of guessing main when no default branch is detectable#1341itsnevu wants to merge 2 commits into
itsnevu wants to merge 2 commits into
Conversation
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
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.
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