-
Notifications
You must be signed in to change notification settings - Fork 654
Context assigns branch configuration #339
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
Changes from all commits
67be1f6
3ecf6fa
3ad8b33
3705f6f
e7a5548
e885ce7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
namespace GitVersion | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text.RegularExpressions; | ||
using LibGit2Sharp; | ||
|
||
/// <summary> | ||
/// Contextual information about where GitVersion is being run | ||
/// </summary> | ||
public class GitVersionContext | ||
{ | ||
readonly bool IsContextForTrackedBranchesOnly; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No idea what this field is, but is it correct that the default changed from true to false? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is always assigned through ctor. The initial value was unused |
||
|
||
public GitVersionContext(IRepository repository, Config configuration, bool isForTrackingBranchOnly = true) | ||
: this(repository, repository.Head, configuration, isForTrackingBranchOnly) | ||
{ | ||
|
@@ -34,16 +38,16 @@ public GitVersionContext(IRepository repository, Branch currentBranch, Config co | |
{ | ||
CurrentBranch = currentBranch; | ||
} | ||
|
||
AssignBranchConfiguration(); | ||
} | ||
|
||
public Config Configuration { get; private set; } | ||
public IRepository Repository { get; private set; } | ||
public Branch CurrentBranch { get; private set; } | ||
public Commit CurrentCommit { get; private set; } | ||
|
||
public BranchConfig CurrentBranchConfig { get; set; } | ||
|
||
readonly bool IsContextForTrackedBranchesOnly = true; | ||
public BranchConfig CurrentBranchConfig { get; private set; } | ||
|
||
|
||
IEnumerable<Branch> GetBranchesContainingCommit(string commitSha) | ||
|
@@ -77,5 +81,24 @@ IEnumerable<Branch> GetBranchesContainingCommit(string commitSha) | |
yield return branch; | ||
} | ||
} | ||
|
||
void AssignBranchConfiguration() | ||
{ | ||
var matchingBranches = Configuration.Branches.Where(b => Regex.IsMatch("^" + CurrentBranch.Name, b.Key)).ToArray(); | ||
|
||
if (matchingBranches.Length == 0) | ||
{ | ||
CurrentBranchConfig = new BranchConfig(); | ||
} | ||
else if (matchingBranches.Length == 1) | ||
{ | ||
CurrentBranchConfig = matchingBranches[0].Value; | ||
} | ||
else | ||
{ | ||
const string format = "Multiple branch configurations match the current branch name of '{0}'. Matching configurations: '{1}'"; | ||
throw new Exception(string.Format(format, CurrentBranch.Name, string.Join(", ", matchingBranches.Select(b => b.Key)))); | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was only for test purpose, not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, test purposes. But is useful if we need to debug issues in the future