Fix git tag pruning when fetching with specific refspecs #5254
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-tagsdoesn'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-tagsflag, leading to errors like:This happens because git's
--prune-tagsflag 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 originbefore 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
GitRemotePrunemethod to bothGitCommandManager(interface + implementation) andGitCliManagerGitFetchmethods in both classes to callGitRemotePrunebefore fetch when:refSpecis not null and has items)fetchTagsis true)--prune-tags)GitRemotePruneis called for PR buildsBehavior
git remote prune originbeforegit fetchto clean up conflicting tag refsgit remote prunefails, 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.iodotnet build(dns block)055vsblobprodwcus02.vsblob.vsassets.iodotnet build(dns block)1g1vsblobprodwcus01.vsblob.vsassets.iodotnet build(dns block)3eavsblobprodwcus03.vsblob.vsassets.iodotnet build(dns block)3zgvsblobprodwcus024.vsblob.vsassets.iodotnet build(dns block)40qvsblobprodwcus022.vsblob.vsassets.iodotnet build(dns block)4fdvsblobprodwcus012.vsblob.vsassets.iodotnet build(dns block)5tbvsblobprodwcus06.vsblob.vsassets.iodotnet build(dns block)61cvsblobprodwcus010.vsblob.vsassets.iodotnet build(dns block)73dvsblobprodwcus07.vsblob.vsassets.iodotnet build(dns block)8usvsblobprodwcus011.vsblob.vsassets.iodotnet build(dns block)9owvsblobprodwcus020.vsblob.vsassets.iodotnet build(dns block)arpvsblobprodwcus017.vsblob.vsassets.iodotnet build(dns block)crcvsblobprodwcus021.vsblob.vsassets.iodotnet build(dns block)fslvsblobprodwcus015.vsblob.vsassets.iodotnet build(dns block)grnvsblobprodwcus04.vsblob.vsassets.iodotnet build(dns block)uubvsblobprodwcus018.vsblob.vsassets.iodotnet build(dns block)vwmvsblobprodwcus016.vsblob.vsassets.iodotnet 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.