Fix git tag pruning when fetching with specific refspecs #5254
+92
−0
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.
This PR addresses a bug where
--prune-tags
doesn't work properly when git fetch is executed with specific refspecs (like in PR builds), causing conflicts when old and new tags have conflicting filesystem paths.Problem
When PR builds fetch with refspecs like
+refs/heads/*:refs/remotes/origin/* +refs/pull/<number>/merge:refs/remotes/pull/<number>/merge
, git doesn't prune conflicting tag refs even with the--prune-tags
flag, leading to errors like:This happens because git's
--prune-tags
flag only works on refs that match the provided refspecs. Since PR build refspecs target branches and pull request refs (not tags), tag pruning doesn't happen even though new tags are still fetched.Solution
Add
git remote prune origin
before fetching when we have specific refspecs and fetchTags is enabled, to clean up conflicting tag refs that would prevent new tags from being created.Changes Made
GitRemotePrune
method to bothGitCommandManager
(interface + implementation) andGitCliManager
GitFetch
methods in both classes to callGitRemotePrune
before fetch when:refSpec
is not null and has items)fetchTags
is true)--prune-tags
)GitRemotePrune
is called for PR buildsBehavior
git remote prune origin
beforegit fetch
to clean up conflicting tag refsgit remote prune
fails, it logs the exit code but continues with fetch (non-breaking)This is a minimal, surgical fix that addresses the specific git behavior while maintaining full backward compatibility.
Fixes #5170.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
03nvsblobprodwcus014.vsblob.vsassets.io
dotnet build
(dns block)055vsblobprodwcus02.vsblob.vsassets.io
dotnet build
(dns block)1g1vsblobprodwcus01.vsblob.vsassets.io
dotnet build
(dns block)3eavsblobprodwcus03.vsblob.vsassets.io
dotnet build
(dns block)3zgvsblobprodwcus024.vsblob.vsassets.io
dotnet build
(dns block)40qvsblobprodwcus022.vsblob.vsassets.io
dotnet build
(dns block)4fdvsblobprodwcus012.vsblob.vsassets.io
dotnet build
(dns block)5tbvsblobprodwcus06.vsblob.vsassets.io
dotnet build
(dns block)61cvsblobprodwcus010.vsblob.vsassets.io
dotnet build
(dns block)73dvsblobprodwcus07.vsblob.vsassets.io
dotnet build
(dns block)8usvsblobprodwcus011.vsblob.vsassets.io
dotnet build
(dns block)9owvsblobprodwcus020.vsblob.vsassets.io
dotnet build
(dns block)arpvsblobprodwcus017.vsblob.vsassets.io
dotnet build
(dns block)crcvsblobprodwcus021.vsblob.vsassets.io
dotnet build
(dns block)fslvsblobprodwcus015.vsblob.vsassets.io
dotnet build
(dns block)grnvsblobprodwcus04.vsblob.vsassets.io
dotnet build
(dns block)uubvsblobprodwcus018.vsblob.vsassets.io
dotnet build
(dns block)vwmvsblobprodwcus016.vsblob.vsassets.io
dotnet build
(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.