Bugfixing primary repository detection #4217
Open
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 is a new pull request replacing the old pull request #3473 which included two changes. Both these changes of the old pull request have been splitted up according to the suggestion by @ismayilov-ismayil (the other new pull request being #4216). This pull request contains the primary repository detection problem fixes. It also already contains the change of the "Find" to the "FirstOrDefault" calls on the Repositories lists as suggested by @Roman-Shchukin in the old pull request.
Bug fixed:
Assignment of primary repository fixed
The setting of the RepositoryUtil.IsPrimaryRepository flag for the primary repository was not implemented correctly. It was always set for the repository that is first checked out. Now while this will normaly be the self repository, it doesn't have to be. In fact, if you really need to know the first repository that has been checked out, that information has its own job-flag/property called WellKnownJobSettings.FirstRepositoryCheckedOut. If the self repository is checked out as the second repository it should still be marked as the primary repository. The RepositoryUtil.IsPrimaryRepositoryName method shows the way here, always looking for the repository with alias "self", therefore clearly stating that the self repository is the primary repository. However, the RepositoryUtil.GetPrimaryRepository first uses the RepositoryUtil.IsPrimaryRepository flag to check for the primary repository and only if it doesn't find it set for any repository will look for the repository with the alias "self". So if the wrong repository has been set the IsPrimaryRepositoryName flag the RepositoryUtil.GetPrimaryRepository method will return the wrong repository. And the result of the RepositoryUtil.GetPrimaryRepository method and the RepositoryUtil.IsPrimaryRepositoryName method will not be consinstent though they should clearly provide they same kind of information according to their name.
This bug lead to some strange behaviour, for example:
I added UnitTests to test for the correct setting of the RepositoryUtil.IsPrimaryRepository flag in the future, even under circumstances which resulted in the wrong repository with this flag set in the past.
I also added UnitTests to test for the correct effects of this flag on the tracking configuration and Build.Repository.LocalPath build variable.