Skip to content

Commit 3f98794

Browse files
committed
Rewrite the InheritBranchConfiguration() logic so it also works in the crazy scenario when master hasn't been checked out locally (i.e. only exists in origin).
1 parent ddd4e81 commit 3f98794

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/GitVersionCore/BranchConfigurationCalculator.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,15 @@ static KeyValuePair<string, BranchConfig> InheritBranchConfiguration(bool onlyEv
118118
else
119119
errorMessage = "Failed to inherit Increment branch configuration, ended up with: " + string.Join(", ", possibleParents.Select(p => p.Name));
120120

121-
var developBranch = repository.Branches.FirstOrDefault(b => Regex.IsMatch(b.Name, "^develop", RegexOptions.IgnoreCase));
122-
var branchName = developBranch != null ? developBranch.Name : "master";
121+
var chosenBranch = repository.Branches.FirstOrDefault(b => Regex.IsMatch(b.Name, "^develop", RegexOptions.IgnoreCase)
122+
|| Regex.IsMatch(b.Name, "master$", RegexOptions.IgnoreCase));
123+
if (chosenBranch == null)
124+
throw new InvalidOperationException("Could not find a 'develop' or 'master' branch, neither locally nor remotely.");
123125

126+
var branchName = chosenBranch.Name;
124127
Logger.WriteWarning(errorMessage + Environment.NewLine + Environment.NewLine + "Falling back to " + branchName + " branch config");
125-
currentBranch = repository.Branches[branchName];
126128

127-
if (currentBranch == null)
128-
{
129-
throw new InvalidOperationException(String.Format("Could not find the branch '{0}'.", branchName));
130-
}
131-
132-
var value = GetBranchConfiguration(currentCommit, repository, onlyEvaluateTrackedBranches, config, currentBranch).Value;
129+
var value = GetBranchConfiguration(currentCommit, repository, onlyEvaluateTrackedBranches, config, chosenBranch).Value;
133130
return new KeyValuePair<string, BranchConfig>(
134131
keyValuePair.Key,
135132
new BranchConfig(branchConfiguration)

0 commit comments

Comments
 (0)