Add origin remote if it's not already set on the mirror repo #1685
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.
Problem
We've hit an issue a couple times where agents with a shared git mirror repo fail when trying to set the remote url for origin. The agents sharing the repo will fail consistently but can be recovered by manually running
git --git-dir <mirrorDir> remote add origin <url>
on the host.The root cause for the repo getting into this state isn't known yet. From scanning the logs I haven't found any errors or abnormal operation. The only thing I see is that all the agents start picking up jobs at the same time so it could be due to another git operation running without a lock somewhere else.
Proposed Solution
This PR just checks if there's not already a url for origin and runs
git remote add
if there isn't. This code runs within the update lock so there won't be any issue with multiple agents checking and branching based on the git remote get-url result.Tests
There aren't any unit tests for this part of the code as far as I've seen. This doesn't reproduce often but we want to have a fix in to avoid issues in the future.