Skip to content

Commit 094b726

Browse files
committed
Fixed some obsolete warnings
Changed usage of `Branch.Name` to `Branch.FriendlyName` and a few other properties and methods made obsolete by LibGit2Sharp v0.22.0.
1 parent 5209f55 commit 094b726

18 files changed

+67
-57
lines changed

src/GitVersionCore.Tests/Fixtures/RepositoryFixtureBase.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void MakeATaggedCommit(string tag)
8181

8282
public void ApplyTag(string tag)
8383
{
84-
diagramBuilder.AppendLineFormat("{0} -> {0}: tag {1}", GetParticipant(Repository.Head.Name), tag);
84+
diagramBuilder.AppendLineFormat("{0} -> {0}: tag {1}", GetParticipant(Repository.Head.FriendlyName), tag);
8585
Repository.ApplyTag(tag);
8686
}
8787

@@ -93,7 +93,7 @@ public void BranchTo(string branchName, string @as = null)
9393
Participant(branchName, @as);
9494
}
9595

96-
var branch = Repository.Head.Name;
96+
var branch = Repository.Head.FriendlyName;
9797
diagramBuilder.AppendLineFormat("{0} -> {1}: branch from {2}", GetParticipant(branch), GetParticipant(branchName), branch);
9898
Repository.Checkout(Repository.CreateBranch(branchName));
9999
}
@@ -112,13 +112,13 @@ public void BranchToFromTag(string branchName, string fromTag, string onBranch,
112112

113113
public void MakeACommit()
114114
{
115-
diagramBuilder.AppendLineFormat("{0} -> {0}: commit", GetParticipant(Repository.Head.Name));
115+
diagramBuilder.AppendLineFormat("{0} -> {0}: commit", GetParticipant(Repository.Head.FriendlyName));
116116
Repository.MakeACommit();
117117
}
118118

119119
public void MergeNoFF(string mergeTarget)
120120
{
121-
diagramBuilder.AppendLineFormat("{0} -> {1}: merge", GetParticipant(mergeTarget), GetParticipant(Repository.Head.Name));
121+
diagramBuilder.AppendLineFormat("{0} -> {1}: merge", GetParticipant(mergeTarget), GetParticipant(Repository.Head.FriendlyName));
122122
Repository.MergeNoFF(mergeTarget, Constants.SignatureNow());
123123
}
124124

@@ -138,7 +138,7 @@ public void AssertFullSemver(string fullSemver, IRepository repository = null, s
138138
throw;
139139
}
140140
if (commitId == null)
141-
diagramBuilder.AppendLineFormat("note over {0} #D3D3D3: {1}", GetParticipant(Repository.Head.Name), fullSemver);
141+
diagramBuilder.AppendLineFormat("note over {0} #D3D3D3: {1}", GetParticipant(Repository.Head.FriendlyName), fullSemver);
142142
}
143143

144144
string GetParticipant(string branch)

src/GitVersionCore.Tests/Helpers/GitTestExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static void MergeNoFF(this IRepository repository, string branch, Signatu
2222
{
2323
repository.Merge(repository.FindBranch(branch), sig, new MergeOptions
2424
{
25-
FastForwardStrategy = FastForwardStrategy.NoFastFoward
25+
FastForwardStrategy = FastForwardStrategy.NoFastForward
2626
});
2727
}
2828

@@ -54,7 +54,7 @@ public static Commit CreateFileAndCommit(this IRepository repository, string rel
5454
public static Tag MakeATaggedCommit(this IRepository repository, string tag)
5555
{
5656
var commit = repository.MakeACommit();
57-
var existingTag = repository.Tags.SingleOrDefault(t => t.Name == tag);
57+
var existingTag = repository.Tags.SingleOrDefault(t => t.FriendlyName == tag);
5858
if (existingTag != null)
5959
return existingTag;
6060
return repository.Tags.Add(tag, commit);

src/GitVersionCore.Tests/IntegrationTests/HotfixBranchScenarios.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void CanTakeVersionFromHotfixesBranch()
5555

5656
// Merge hotfix branch to support
5757
fixture.Repository.Checkout("master");
58-
fixture.Repository.Checkout(fixture.Repository.CreateBranch("support-1.1", (Commit)fixture.Repository.Tags.Single(t => t.Name == "1.1.0").Target));
58+
fixture.Repository.Checkout(fixture.Repository.CreateBranch("support-1.1", (Commit)fixture.Repository.Tags.Single(t => t.FriendlyName == "1.1.0").Target));
5959
fixture.AssertFullSemver("1.1.0");
6060

6161
// create hotfix branch
@@ -81,7 +81,7 @@ public void PatchOlderReleaseExample()
8181
{
8282
// Merge hotfix branch to support
8383
fixture.Repository.Checkout("master");
84-
fixture.Repository.Checkout(fixture.Repository.CreateBranch("support-1.1", (Commit) fixture.Repository.Tags.Single(t => t.Name == "1.1.0").Target));
84+
fixture.Repository.Checkout(fixture.Repository.CreateBranch("support-1.1", (Commit) fixture.Repository.Tags.Single(t => t.FriendlyName == "1.1.0").Target));
8585
fixture.AssertFullSemver("1.1.0");
8686

8787
// create hotfix branch

src/GitVersionCore.Tests/Mocks/MockBranch.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1+
using System;
12
using System.Collections;
23
using System.Collections.Generic;
34
using System.Linq;
45
using LibGit2Sharp;
56

67
public class MockBranch : Branch, ICollection<Commit>
78
{
8-
public MockBranch(string name)
9+
public MockBranch(string friendlyName)
910
{
10-
this.name = name;
11-
canonicalName = name;
11+
this.friendlyName = friendlyName;
12+
this.canonicalName = friendlyName;
1213
}
13-
public MockBranch(string name, string canonicalName)
14+
public MockBranch(string friendlyName, string canonicalName)
1415
{
15-
this.name = name;
16+
this.friendlyName = friendlyName;
1617
this.canonicalName = canonicalName;
1718
}
1819

@@ -21,9 +22,14 @@ public MockBranch()
2122

2223
}
2324
MockCommitLog commits = new MockCommitLog();
24-
string name;
25+
string friendlyName;
2526
string canonicalName;
26-
public override string Name { get { return name; } }
27+
28+
public override string FriendlyName
29+
{
30+
get { return this.friendlyName; }
31+
}
32+
2733
public override ICommitLog Commits { get { return commits; } }
2834
public override Commit Tip { get { return commits.First(); } }
2935
public override bool IsTracking { get { return true; } }
@@ -35,7 +41,7 @@ public override string CanonicalName
3541

3642
public override int GetHashCode()
3743
{
38-
return name.GetHashCode();
44+
return this.friendlyName.GetHashCode();
3945
}
4046

4147
public override bool Equals(object obj)

src/GitVersionCore.Tests/Mocks/MockBranchCollection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ public override IEnumerator<Branch> GetEnumerator()
1111
return Branches.GetEnumerator();
1212
}
1313

14-
public override Branch this[string name]
14+
public override Branch this[string friendlyName]
1515
{
16-
get { return Branches.FirstOrDefault(x => x.Name == name); }
16+
get { return Branches.FirstOrDefault(x => x.FriendlyName == friendlyName); }
1717
}
1818

1919
public void Add(Branch item)

src/GitVersionCore.Tests/Mocks/MockTag.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
using System;
2+
13
using LibGit2Sharp;
24

35
public class MockTag : Tag
46
{
57

68
public string NameEx;
9+
10+
[Obsolete("This property will be removed in the next release. Please use FriendlyName instead.")]
711
public override string Name
812
{
913
get { return NameEx; }

src/GitVersionCore/BranchConfigurationCalculator.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static KeyValuePair<string, BranchConfig> GetBranchConfiguration(Commit c
3535
}
3636

3737
const string format = "Multiple branch configurations match the current branch branchName of '{0}'. Matching configurations: '{1}'";
38-
throw new Exception(string.Format(format, currentBranch.Name, string.Join(", ", matchingBranches.Select(b => b.Key))));
38+
throw new Exception(string.Format(format, currentBranch.FriendlyName, string.Join(", ", matchingBranches.Select(b => b.Key))));
3939
}
4040

4141
static KeyValuePair<string, BranchConfig>[] LookupBranchConfiguration([NotNull] Config config, [NotNull] Branch currentBranch)
@@ -50,7 +50,7 @@ static KeyValuePair<string, BranchConfig>[] LookupBranchConfiguration([NotNull]
5050
throw new ArgumentNullException("currentBranch");
5151
}
5252

53-
return config.Branches.Where(b => Regex.IsMatch(currentBranch.Name, "^" + b.Key, RegexOptions.IgnoreCase)).ToArray();
53+
return config.Branches.Where(b => Regex.IsMatch(currentBranch.FriendlyName, "^" + b.Key, RegexOptions.IgnoreCase)).ToArray();
5454
}
5555

5656

@@ -104,7 +104,7 @@ static KeyValuePair<string, BranchConfig> InheritBranchConfiguration(bool onlyEv
104104
}
105105
}
106106

107-
Logger.WriteInfo("Found possible parent branches: " + string.Join(", ", possibleParents.Select(p => p.Name)));
107+
Logger.WriteInfo("Found possible parent branches: " + string.Join(", ", possibleParents.Select(p => p.FriendlyName)));
108108

109109
if (possibleParents.Count == 1)
110110
{
@@ -124,14 +124,14 @@ static KeyValuePair<string, BranchConfig> InheritBranchConfiguration(bool onlyEv
124124
if (possibleParents.Count == 0)
125125
errorMessage = "Failed to inherit Increment branch configuration, no branches found.";
126126
else
127-
errorMessage = "Failed to inherit Increment branch configuration, ended up with: " + string.Join(", ", possibleParents.Select(p => p.Name));
127+
errorMessage = "Failed to inherit Increment branch configuration, ended up with: " + string.Join(", ", possibleParents.Select(p => p.FriendlyName));
128128

129-
var chosenBranch = repository.Branches.FirstOrDefault(b => Regex.IsMatch(b.Name, "^develop", RegexOptions.IgnoreCase)
130-
|| Regex.IsMatch(b.Name, "master$", RegexOptions.IgnoreCase));
129+
var chosenBranch = repository.Branches.FirstOrDefault(b => Regex.IsMatch(b.FriendlyName, "^develop", RegexOptions.IgnoreCase)
130+
|| Regex.IsMatch(b.FriendlyName, "master$", RegexOptions.IgnoreCase));
131131
if (chosenBranch == null)
132132
throw new InvalidOperationException("Could not find a 'develop' or 'master' branch, neither locally nor remotely.");
133133

134-
var branchName = chosenBranch.Name;
134+
var branchName = chosenBranch.FriendlyName;
135135
Logger.WriteWarning(errorMessage + Environment.NewLine + Environment.NewLine + "Falling back to " + branchName + " branch config");
136136

137137
var value = GetBranchConfiguration(currentCommit, repository, onlyEvaluateTrackedBranches, config, chosenBranch).Value;
@@ -161,22 +161,22 @@ static Branch[] CalculateWhenMultipleParents(IRepository repository, Commit curr
161161
}
162162
else if (branches.Count > 1)
163163
{
164-
currentBranch = branches.FirstOrDefault(b => b.Name == "master") ?? branches.First();
164+
currentBranch = branches.FirstOrDefault(b => b.FriendlyName == "master") ?? branches.First();
165165
}
166166
else
167167
{
168168
var possibleTargetBranches = repository.Branches.Where(b => !b.IsRemote && b.Tip == parents[0]).ToList();
169169
if (possibleTargetBranches.Count > 1)
170170
{
171-
currentBranch = possibleTargetBranches.FirstOrDefault(b => b.Name == "master") ?? possibleTargetBranches.First();
171+
currentBranch = possibleTargetBranches.FirstOrDefault(b => b.FriendlyName == "master") ?? possibleTargetBranches.First();
172172
}
173173
else
174174
{
175175
currentBranch = possibleTargetBranches.FirstOrDefault() ?? currentBranch;
176176
}
177177
}
178178

179-
Logger.WriteInfo("HEAD is merge commit, this is likely a pull request using " + currentBranch.Name + " as base");
179+
Logger.WriteInfo("HEAD is merge commit, this is likely a pull request using " + currentBranch.FriendlyName + " as base");
180180

181181
return excludedBranches;
182182
}

src/GitVersionCore/BuildServers/GitHelper.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@ public static void NormalizeGitDirectory(string gitDirectory, Authentication aut
6565
const string moveBranchMsg = "Move one of the branches along a commit to remove warning";
6666

6767
Logger.WriteWarning(string.Format("Found more than one local branch pointing at the commit '{0}' ({1}).", headSha, csvNames));
68-
var master = localBranchesWhereCommitShaIsHead.SingleOrDefault(n => n.Name == "master");
68+
var master = localBranchesWhereCommitShaIsHead.SingleOrDefault(n => n.FriendlyName == "master");
6969
if (master != null)
7070
{
7171
Logger.WriteWarning("Because one of the branches is 'master', will build master." + moveBranchMsg);
7272
repo.Checkout(master);
7373
}
7474
else
7575
{
76-
var branchesWithoutSeparators = localBranchesWhereCommitShaIsHead.Where(b => !b.Name.Contains('/') && !b.Name.Contains('-')).ToList();
76+
var branchesWithoutSeparators = localBranchesWhereCommitShaIsHead.Where(b => !b.FriendlyName.Contains('/') && !b.FriendlyName.Contains('-')).ToList();
7777
if (branchesWithoutSeparators.Count == 1)
7878
{
7979
var branchWithoutSeparator = branchesWithoutSeparators[0];
@@ -93,8 +93,8 @@ public static void NormalizeGitDirectory(string gitDirectory, Authentication aut
9393
}
9494
else
9595
{
96-
Logger.WriteInfo(string.Format("Checking out local branch 'refs/heads/{0}'.", localBranchesWhereCommitShaIsHead[0].Name));
97-
repo.Checkout(repo.Branches[localBranchesWhereCommitShaIsHead[0].Name]);
96+
Logger.WriteInfo(string.Format("Checking out local branch 'refs/heads/{0}'.", localBranchesWhereCommitShaIsHead[0].FriendlyName));
97+
repo.Checkout(repo.Branches[localBranchesWhereCommitShaIsHead[0].FriendlyName]);
9898
}
9999
}
100100
}

src/GitVersionCore/GitVersionContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public GitVersionContext(IRepository repository, Branch currentBranch, Config co
6161
.SelectMany(t =>
6262
{
6363
SemanticVersion version;
64-
if (t.PeeledTarget() == CurrentCommit && SemanticVersion.TryParse(t.Name, Configuration.GitTagPrefix, out version))
64+
if (t.PeeledTarget() == CurrentCommit && SemanticVersion.TryParse(t.FriendlyName, Configuration.GitTagPrefix, out version))
6565
return new[] { version };
6666
return new SemanticVersion[0];
6767
})

src/GitVersionCore/GitVersionFinder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class GitVersionFinder
77
{
88
public SemanticVersion FindVersion(GitVersionContext context)
99
{
10-
Logger.WriteInfo(string.Format("Running against branch: {0} ({1})", context.CurrentBranch.Name, context.CurrentCommit.Sha));
10+
Logger.WriteInfo(string.Format("Running against branch: {0} ({1})", context.CurrentBranch.FriendlyName, context.CurrentCommit.Sha));
1111
EnsureMainTopologyConstraints(context);
1212

1313
var filePath = Path.Combine(context.Repository.GetRepositoryDirectory(), "NextVersion.txt");

src/GitVersionCore/IncrementStrategyFinder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ private static IEnumerable<Commit> GetIntermediateCommits(IRepository repo, Comm
8787
{
8888
var filter = new CommitFilter
8989
{
90-
Since = headCommit,
90+
IncludeReachableFrom = headCommit,
9191
SortBy = CommitSortStrategies.Topological | CommitSortStrategies.Reverse
9292
};
9393

src/GitVersionCore/LibGitExtensions.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ public static DateTimeOffset When(this Commit commit)
2020

2121
public static Branch FindBranch(this IRepository repository, string branchName)
2222
{
23-
var exact = repository.Branches.FirstOrDefault(x => x.Name == branchName);
23+
var exact = repository.Branches.FirstOrDefault(x => x.FriendlyName == branchName);
2424
if (exact != null)
2525
{
2626
return exact;
2727
}
2828

29-
return repository.Branches.FirstOrDefault(x => x.Name == "origin/" + branchName);
29+
return repository.Branches.FirstOrDefault(x => x.FriendlyName == "origin/" + branchName);
3030
}
3131

3232
public static SemanticVersion LastVersionTagOnBranch(this Branch branch, IRepository repository, string tagPrefixRegex)
@@ -35,12 +35,12 @@ public static SemanticVersion LastVersionTagOnBranch(this Branch branch, IReposi
3535

3636
return repository.Commits.QueryBy(new CommitFilter
3737
{
38-
Since = branch.Tip
38+
IncludeReachableFrom = branch.Tip
3939
})
4040
.SelectMany(c => tags.Where(t => c.Sha == t.Target.Sha).SelectMany(t =>
4141
{
4242
SemanticVersion semver;
43-
if (SemanticVersion.TryParse(t.Name, tagPrefixRegex, out semver))
43+
if (SemanticVersion.TryParse(t.FriendlyName, tagPrefixRegex, out semver))
4444
return new [] { semver };
4545
return new SemanticVersion[0];
4646
}))
@@ -61,7 +61,7 @@ public static Commit FindCommitBranchWasBranchedFrom([NotNull] this Branch branc
6161
{
6262
if (branch.Tip == null)
6363
{
64-
Logger.WriteWarning(string.Format(missingTipFormat, branch.Name));
64+
Logger.WriteWarning(string.Format(missingTipFormat, branch.FriendlyName));
6565
return null;
6666
}
6767

@@ -73,7 +73,7 @@ public static Commit FindCommitBranchWasBranchedFrom([NotNull] this Branch branc
7373
{
7474
if (otherBranch.Tip == null)
7575
{
76-
Logger.WriteWarning(string.Format(missingTipFormat, otherBranch.Name));
76+
Logger.WriteWarning(string.Format(missingTipFormat, otherBranch.FriendlyName));
7777
return null;
7878
}
7979

@@ -84,10 +84,10 @@ public static Commit FindCommitBranchWasBranchedFrom([NotNull] this Branch branc
8484
commitToFindCommonBase = otherBranch.Tip.Parents.First();
8585
}
8686

87-
var findMergeBase = repository.Commits.FindMergeBase(branch.Tip, commitToFindCommonBase);
87+
var findMergeBase = repository.ObjectDatabase.FindMergeBase(branch.Tip, commitToFindCommonBase);
8888
if (findMergeBase != null)
8989
{
90-
using (Logger.IndentLog(string.Format("Found merge base of {0} against {1}", findMergeBase.Sha, otherBranch.Name)))
90+
using (Logger.IndentLog(string.Format("Found merge base of {0} against {1}", findMergeBase.Sha, otherBranch.FriendlyName)))
9191
{
9292
// We do not want to include merge base commits which got forward merged into the other branch
9393
bool mergeBaseWasFowardMerge;
@@ -102,7 +102,7 @@ public static Commit FindCommitBranchWasBranchedFrom([NotNull] this Branch branc
102102
{
103103
Logger.WriteInfo("Merge base was due to a forward merge, moving to next merge base");
104104
var second = commitToFindCommonBase.Parents.First();
105-
var mergeBase = repository.Commits.FindMergeBase(branch.Tip, second);
105+
var mergeBase = repository.ObjectDatabase.FindMergeBase(branch.Tip, second);
106106
if (mergeBase == findMergeBase) break;
107107
findMergeBase = mergeBase;
108108
}
@@ -127,7 +127,7 @@ public static Commit FindCommitBranchWasBranchedFrom([NotNull] this Branch branc
127127

128128
static bool IsSameBranch(Branch branch, Branch b)
129129
{
130-
return (b.IsRemote ? b.Name.Substring(b.Name.IndexOf("/", StringComparison.Ordinal) + 1) : b.Name) != branch.Name;
130+
return (b.IsRemote ? b.FriendlyName.Substring(b.FriendlyName.IndexOf("/", StringComparison.Ordinal) + 1) : b.FriendlyName) != branch.FriendlyName;
131131
}
132132

133133
public static IEnumerable<Branch> GetBranchesContainingCommit([NotNull] this Commit commit, IRepository repository, IList<Branch> branches, bool onlyTrackedBranches)
@@ -156,7 +156,7 @@ public static IEnumerable<Branch> GetBranchesContainingCommit([NotNull] this Com
156156

157157
foreach (var branch in branches.Where(b => (onlyTrackedBranches && !b.IsTracking)))
158158
{
159-
var commits = repository.Commits.QueryBy(new CommitFilter { Since = branch }).Where(c => c.Sha == commit.Sha);
159+
var commits = repository.Commits.QueryBy(new CommitFilter { IncludeReachableFrom = branch }).Where(c => c.Sha == commit.Sha);
160160

161161
if (!commits.Any())
162162
{

0 commit comments

Comments
 (0)