private Branch GetMainline(Commit baseVersionSource)
        {
            var mainlineBranchConfigs = context.FullConfiguration.Branches.Where(b => b.Value.IsMainline == true).ToList();
            var mainlineBranches      = repositoryMetadataProvider.GetMainlineBranches(context.CurrentCommit, mainlineBranchConfigs);

            var allMainlines = mainlineBranches.Values.SelectMany(branches => branches.Select(b => b.FriendlyName));

            log.Info("Found possible mainline branches: " + string.Join(", ", allMainlines));

            // Find closest mainline branch
            var firstMatchingCommit      = context.CurrentBranch.Commits.First(c => mainlineBranches.ContainsKey(c.Sha));
            var possibleMainlineBranches = mainlineBranches[firstMatchingCommit.Sha];

            if (possibleMainlineBranches.Count == 1)
            {
                var mainlineBranch = possibleMainlineBranches[0];
                log.Info("Mainline for current branch is " + mainlineBranch.FriendlyName);
                return(mainlineBranch);
            }

            // prefer current branch, if it is a mainline branch
            if (possibleMainlineBranches.Any(context.CurrentBranch.IsSameBranch))
            {
                log.Info($"Choosing {context.CurrentBranch.FriendlyName} as mainline because it is the current branch");
                return(context.CurrentBranch);
            }

            // prefer a branch on which the merge base was a direct commit, if there is such a branch
            var firstMatchingCommitBranch = possibleMainlineBranches.FirstOrDefault(b => repositoryMetadataProvider.GetMatchingCommitBranch(baseVersionSource, b, firstMatchingCommit));

            if (firstMatchingCommitBranch != null)
            {
                var message = string.Format(
                    "Choosing {0} as mainline because {1}'s merge base was a direct commit to {0}",
                    firstMatchingCommitBranch.FriendlyName,
                    context.CurrentBranch.FriendlyName);
                log.Info(message);

                return(firstMatchingCommitBranch);
            }

            var chosenMainline = possibleMainlineBranches[0];

            log.Info($"Multiple mainlines ({string.Join(", ", possibleMainlineBranches.Select(b => b.FriendlyName))}) have the same merge base for the current branch, choosing {chosenMainline.FriendlyName} because we found that branch first...");
            return(chosenMainline);
        }