fix: resolve branch upstream in shallow clones via git config fallback#304980
Open
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
Open
fix: resolve branch upstream in shallow clones via git config fallback#304980yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
Conversation
When a repository is cloned with --depth 1, git for-each-ref returns empty upstream fields because the tracking info is not fully available locally. This causes the branch upstream to be undefined, breaking features like sync, status bar upstream info, and PR creation. Add a fallback that reads branch.<name>.remote and branch.<name>.merge from git config when for-each-ref returns no upstream information. Closes microsoft#248328
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.
What kind of change does this PR introduce?
Bug fix
What is the current behavior?
When a repository is cloned with
git clone --depth 1(shallow clone), the branch'supstreamproperty isundefined. This is becausegit for-each-refwith%(upstream:short),%(upstream:track),%(upstream:remotename), and%(upstream:remoteref)format fields returns empty values in shallow clones, even when the branch tracking configuration exists in.git/config.This causes multiple issues:
Closes #248328
What is the new behavior?
After parsing
for-each-refoutput, if the upstream is still undefined for a local branch, the code now falls back to reading the branch tracking configuration directly using:git config --get branch.<name>.remotegit config --get branch.<name>.mergeThis correctly resolves the upstream even in shallow clones where
for-each-refupstream fields are empty.Additional context
Root cause was identified by @lszomoru in the issue comments. The
for-each-refcommand with upstream format fields relies on local reference data that is not available in shallow clones. However, the branch tracking config (branch.<name>.remoteandbranch.<name>.merge) is always written bygit cloneregardless of depth, making it a reliable fallback source.