Skip to content

Add failing test for missing source-branch config #2348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

michaelnoonan
Copy link
Contributor

@michaelnoonan michaelnoonan commented Jul 7, 2020

Description

We ran into a case where we added a source-branch that wasn't configured.
This ultimately led to a failure way down in the RepositoryMetadataProvider.
From the best I can tell this is due to having no main branch configuration.

    System.Collections.Generic.KeyNotFoundException: The given key 'main' was not present in the dictionary.
13:04:34
       at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
13:04:34
       at GitVersion.RepositoryMetadataProvider.<>c__DisplayClass33_0.<GetMergeCommitsForBranch>b__0(String sb) in D:\a\GitVersion\GitVersion\src\GitVersionCore\Core\RepositoryMetadataProvider.cs:line 475
13:04:34
       at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
13:04:34
       at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
13:04:34
       at GitVersion.RepositoryMetadataProvider.<>c__DisplayClass33_0.<GetMergeCommitsForBranch>b__1(Branch b) in D:\a\GitVersion\GitVersion\src\GitVersionCore\Core\RepositoryMetadataProvider.cs:line 480
13:04:34
       at System.Linq.Utilities.<>c__DisplayClass1_0`1.<CombinePredicates>b__0(TSource x)
13:04:34
       at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
13:04:34
       at System.Linq.Enumerable.WhereEnumerableIterator`1.ToArray()
13:04:34
       at System.Linq.OrderedEnumerable`1.ToList()
13:04:34
       at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
13:04:34
       at GitVersion.RepositoryMetadataProvider.GetMergeCommitsForBranch(Branch branch, Config configuration, IEnumerable`1 excludedBranches) in D:\a\GitVersion\GitVersion\src\GitVersionCore\Core\RepositoryMetadataProvider.cs:line 476
13:04:34
       at GitVersion.RepositoryMetadataProvider.FindCommitBranchWasBranchedFrom(Branch branch, Config configuration, Branch[] excludedBranches) in D:\a\GitVersion\GitVersion\src\GitVersionCore\Core\RepositoryMetadataProvider.cs:line 333
13:04:34
       at GitVersion.Configuration.BranchConfigurationCalculator.InheritBranchConfiguration(Branch targetBranch, BranchConfig branchConfiguration, Commit currentCommit, Config configuration, IList`1 excludedInheritBranches) in D:\a\GitVersion\GitVersion\src\GitVersionCore\Configuration\BranchConfigurationCalculator.cs:line 80
13:04:34
       at GitVersion.Configuration.BranchConfigurationCalculator.GetBranchConfiguration(Branch targetBranch, Commit currentCommit, Config configuration, IList`1 excludedInheritBranches) in D:\a\GitVersion\GitVersion\src\GitVersionCore\Configuration\BranchConfigurationCalculator.cs:line 48

Related Issue

#2349

Motivation and Context

This will help other people discover misconfiguration early.

How Has This Been Tested?

I'm depending on the failing test I've written.

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

We ran into a case where we added a source-branch that wasn't configured.
This ultimately led to a failure way down in the RepositoryMetadataProvider.
From the best I can tell this is due to having no `main` branch configuration.

```
    System.Collections.Generic.KeyNotFoundException: The given key 'main' was not present in the dictionary.
13:04:34
       at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
13:04:34
       at GitVersion.RepositoryMetadataProvider.<>c__DisplayClass33_0.<GetMergeCommitsForBranch>b__0(String sb) in D:\a\GitVersion\GitVersion\src\GitVersionCore\Core\RepositoryMetadataProvider.cs:line 475
13:04:34
       at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
13:04:34
       at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
13:04:34
       at GitVersion.RepositoryMetadataProvider.<>c__DisplayClass33_0.<GetMergeCommitsForBranch>b__1(Branch b) in D:\a\GitVersion\GitVersion\src\GitVersionCore\Core\RepositoryMetadataProvider.cs:line 480
13:04:34
       at System.Linq.Utilities.<>c__DisplayClass1_0`1.<CombinePredicates>b__0(TSource x)
13:04:34
       at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
13:04:34
       at System.Linq.Enumerable.WhereEnumerableIterator`1.ToArray()
13:04:34
       at System.Linq.OrderedEnumerable`1.ToList()
13:04:34
       at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
13:04:34
       at GitVersion.RepositoryMetadataProvider.GetMergeCommitsForBranch(Branch branch, Config configuration, IEnumerable`1 excludedBranches) in D:\a\GitVersion\GitVersion\src\GitVersionCore\Core\RepositoryMetadataProvider.cs:line 476
13:04:34
       at GitVersion.RepositoryMetadataProvider.FindCommitBranchWasBranchedFrom(Branch branch, Config configuration, Branch[] excludedBranches) in D:\a\GitVersion\GitVersion\src\GitVersionCore\Core\RepositoryMetadataProvider.cs:line 333
13:04:34
       at GitVersion.Configuration.BranchConfigurationCalculator.InheritBranchConfiguration(Branch targetBranch, BranchConfig branchConfiguration, Commit currentCommit, Config configuration, IList`1 excludedInheritBranches) in D:\a\GitVersion\GitVersion\src\GitVersionCore\Configuration\BranchConfigurationCalculator.cs:line 80
13:04:34
       at GitVersion.Configuration.BranchConfigurationCalculator.GetBranchConfiguration(Branch targetBranch, Commit currentCommit, Config configuration, IList`1 excludedInheritBranches) in D:\a\GitVersion\GitVersion\src\GitVersionCore\Configuration\BranchConfigurationCalculator.cs:line 48
```
Copy link
Member

@asbjornu asbjornu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks good, I'm just wondering how this affects standard branches such as master and develop.

config.Branches.ContainsKey(x) does a fuzzy-ish match.
In https://github.com/GitTools/GitVersion/blob/master/src/GitVersionCore/Core/RepositoryMetadataProvider.cs#L475 it does a dictionary index lookup.
I've changed the test to use the same approach which is more strict.
These two tests work together to prove success and failure scenarios work as expected.
@asbjornu asbjornu merged commit f1869c0 into GitTools:master Jul 8, 2020
@asbjornu
Copy link
Member

asbjornu commented Jul 8, 2020

Thanks for your contributions, @michaelnoonan! 🙏

@michaelnoonan
Copy link
Contributor Author

🙇‍♂️ Thanks for your feedback also! I think this is a nice small improvement.

@michaelnoonan michaelnoonan deleted the michaelnoonan/missing-source-branch branch July 9, 2020 05:19
michaelnoonan added a commit to OctopusDeploy/ServerExtensibility that referenced this pull request Jul 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants