fix(git): create a branch from a detached HEAD - #4955
Open
kabishou11 wants to merge 1 commit into
Open
kabishou11 wants to merge 1 commit into
kabishou11 wants to merge 1 commit into
Conversation
git_create_branch without base_branch used repo.active_branch, which raises TypeError when HEAD is detached. Branch from the current commit instead, like git switch -c does.
|
This branch has not been deployed
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.
Description
git_create_branchwithoutbase_branchfails whenever the repository has a detached HEAD (after checking out a commit or tag, or in the middle of a rebase). It usesrepo.active_branchas the start point, and GitPython raisesTypeError: HEAD is a detached symbolic reference as it points to '<sha>'when there is no active branch. Creating a branch from a detached HEAD is exactly how you keep that work (git switch -c <name>), so the tool fails on a normal workflow.This change branches from the current commit when HEAD is detached. The result message reports the commit SHA. Behaviour with a
base_branch, or on a normal branch, is unchanged.Server Details
git_create_branch)Motivation and Context
How Has This Been Tested?
test_git_create_branch_detached_head. It fails onmainwith theTypeErrorand passes with this change.uv run pytestinsrc/git: 48 passed.uv run pyright src: 0 errors.ruff check: clean.Breaking Changes
None.
Types of changes
Checklist
Additional context
#4943 changes the same function for annotated tags given as
base_branch. That is a different code path and the two changes don't overlap.