Skip to content

Commit b581a4a

Browse files
committed
cleanup
1 parent 4adf783 commit b581a4a

File tree

7 files changed

+177
-136
lines changed

7 files changed

+177
-136
lines changed

src/GitVersionCore.Tests/IntegrationTests/ReleaseBranchScenarios.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ public void CommitBeetweenMergeReleaseToDevelopShouldNotResetCount()
454454
fixture.Repository.MakeACommit();
455455
fixture.AssertFullSemver("2.0.0-beta.2", config);
456456

457-
// Merge release to develop - emulate commit beetween other person release commit push and this commit merge to develop
457+
// Merge release to develop - emulate commit between other person release commit push and this commit merge to develop
458458
Commands.Checkout(fixture.Repository, "develop");
459459
fixture.Repository.Merge(commit1, Generate.SignatureNow(), new MergeOptions { FastForwardStrategy = FastForwardStrategy.NoFastForward });
460460
fixture.Repository.MergeNoFF("release-2.0.0", Generate.SignatureNow());

src/GitVersionCore.Tests/Mocks/MockTag.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ namespace GitVersionCore.Tests.Mocks
44
{
55
public class MockTag : Tag
66
{
7-
87
public string NameEx;
98
public override string FriendlyName => NameEx;
109

src/GitVersionCore/Core/Abstractions/IRepositoryMetadataProvider.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public interface IRepositoryMetadataProvider
2121
Branch GetTargetBranch(string targetBranch);
2222
Branch FindBranch(string branchName);
2323
Branch GetChosenBranch(Config configuration);
24-
List<Branch> GetBranchesForCommit(GitObject commit);
24+
List<Branch> GetBranchesForCommit(Commit commit);
2525
List<Branch> GetExcludedInheritBranches(Config configuration);
2626
IEnumerable<Branch> GetReleaseBranches(IEnumerable<KeyValuePair<string, BranchConfig>> releaseBranchConfig);
2727
IEnumerable<Branch> ExcludingBranches(IEnumerable<Branch> branchesToExclude);
@@ -34,14 +34,14 @@ public interface IRepositoryMetadataProvider
3434
/// </summary>
3535
BranchCommit FindCommitBranchWasBranchedFrom(Branch branch, Config configuration, params Branch[] excludedBranches);
3636

37-
SemanticVersion GetCurrentCommitTaggedVersion(GitObject commit, EffectiveConfiguration config);
37+
SemanticVersion GetCurrentCommitTaggedVersion(Commit commit, EffectiveConfiguration config);
3838
SemanticVersion MaybeIncrement(BaseVersion baseVersion, GitVersionContext context);
3939
IEnumerable<SemanticVersion> GetVersionTagsOnBranch(Branch branch, string tagPrefixRegex);
4040
IEnumerable<Tuple<Tag, SemanticVersion>> GetValidVersionTags(string tagPrefixRegex, DateTimeOffset? olderThan = null);
4141

4242
CommitCollection GetCommitLog(Commit baseVersionSource, Commit currentCommit);
4343
bool GetMatchingCommitBranch(Commit baseVersionSource, Branch branch, Commit firstMatchingCommit);
44-
string ShortenObjectId(GitObject commit);
44+
string ShortenObjectId(Commit commit);
4545
VersionField? DetermineIncrementedField(BaseVersion baseVersion, GitVersionContext context);
4646

4747
int GetNumberOfUncommittedChanges();

src/GitVersionCore/Core/GitModel.cs

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,148 +18,148 @@ protected Branch()
1818
{
1919
}
2020

21-
public static implicit operator LibGit2Sharp.Branch(Branch d) => d.innerBranch;
21+
public static implicit operator LibGit2Sharp.Branch(Branch d) => d?.innerBranch;
2222
public static explicit operator Branch(LibGit2Sharp.Branch b) => b is null ? null : new Branch(b);
2323

24-
public virtual string CanonicalName => innerBranch.CanonicalName;
25-
public virtual string FriendlyName => innerBranch.FriendlyName;
26-
public virtual Commit Tip => innerBranch.Tip;
27-
public virtual bool IsRemote => innerBranch.IsRemote;
28-
public virtual CommitCollection Commits => CommitCollection.FromCommitLog(innerBranch.Commits);
29-
public virtual bool IsTracking => innerBranch.IsTracking;
24+
public virtual string CanonicalName => innerBranch?.CanonicalName;
25+
public virtual string FriendlyName => innerBranch?.FriendlyName;
26+
public virtual Commit Tip => innerBranch?.Tip;
27+
public virtual CommitCollection Commits => CommitCollection.FromCommitLog(innerBranch?.Commits);
28+
public virtual bool IsRemote => innerBranch != null && innerBranch.IsRemote;
29+
public virtual bool IsTracking => innerBranch != null && innerBranch.IsTracking;
3030
}
3131

3232
public class BranchCollection : IEnumerable<Branch>
3333
{
34-
private readonly LibGit2Sharp.BranchCollection innerBranchCollection;
35-
private BranchCollection(LibGit2Sharp.BranchCollection branchCollection) => innerBranchCollection = branchCollection;
34+
private readonly LibGit2Sharp.BranchCollection innerCollection;
35+
private BranchCollection(LibGit2Sharp.BranchCollection collection) => innerCollection = collection;
3636

3737
protected BranchCollection()
3838
{
3939
}
4040

41-
public static implicit operator LibGit2Sharp.BranchCollection(BranchCollection d) => d.innerBranchCollection;
41+
public static implicit operator LibGit2Sharp.BranchCollection(BranchCollection d) => d.innerCollection;
4242
public static explicit operator BranchCollection(LibGit2Sharp.BranchCollection b) => b is null ? null : new BranchCollection(b);
4343

4444
public virtual IEnumerator<Branch> GetEnumerator()
4545
{
46-
foreach (var branch in innerBranchCollection)
46+
foreach (var branch in innerCollection)
4747
yield return (Branch)branch;
4848
}
4949

5050
public virtual Branch Add(string name, Commit commit)
5151
{
52-
return (Branch)innerBranchCollection.Add(name, commit);
52+
return (Branch)innerCollection.Add(name, commit);
5353
}
5454

5555
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
56-
public virtual Branch this[string friendlyName] => (Branch)innerBranchCollection[friendlyName];
56+
public virtual Branch this[string friendlyName] => (Branch)innerCollection[friendlyName];
5757

5858
public void Update(Branch branch, params Action<BranchUpdater>[] actions)
5959
{
60-
innerBranchCollection.Update(branch, actions);
60+
innerCollection.Update(branch, actions);
6161
}
6262
}
6363

6464
public class TagCollection : IEnumerable<Tag>
6565
{
66-
private readonly LibGit2Sharp.TagCollection innerTagCollection;
67-
private TagCollection(LibGit2Sharp.TagCollection branchCollection) => innerTagCollection = branchCollection;
66+
private readonly LibGit2Sharp.TagCollection innerCollection;
67+
private TagCollection(LibGit2Sharp.TagCollection collection) => innerCollection = collection;
6868

6969
protected TagCollection()
7070
{
7171
}
7272

73-
public static implicit operator LibGit2Sharp.TagCollection(TagCollection d) => d.innerTagCollection;
73+
public static implicit operator LibGit2Sharp.TagCollection(TagCollection d) => d.innerCollection;
7474
public static explicit operator TagCollection(LibGit2Sharp.TagCollection b) => b is null ? null : new TagCollection(b);
7575

7676
public virtual IEnumerator<Tag> GetEnumerator()
7777
{
78-
foreach (var branch in innerTagCollection)
78+
foreach (var branch in innerCollection)
7979
yield return branch;
8080
}
8181

8282
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
83-
public virtual Tag this[string name] => innerTagCollection[name];
83+
public virtual Tag this[string name] => innerCollection[name];
8484
}
8585

8686
public class ReferenceCollection : IEnumerable<Reference>
8787
{
88-
private readonly LibGit2Sharp.ReferenceCollection innerReferenceCollection;
89-
private ReferenceCollection(LibGit2Sharp.ReferenceCollection branchCollection) => innerReferenceCollection = branchCollection;
88+
private readonly LibGit2Sharp.ReferenceCollection innerCollection;
89+
private ReferenceCollection(LibGit2Sharp.ReferenceCollection collection) => innerCollection = collection;
9090

9191
protected ReferenceCollection()
9292
{
9393
}
9494

95-
public static implicit operator LibGit2Sharp.ReferenceCollection(ReferenceCollection d) => d.innerReferenceCollection;
95+
public static implicit operator LibGit2Sharp.ReferenceCollection(ReferenceCollection d) => d.innerCollection;
9696
public static explicit operator ReferenceCollection(LibGit2Sharp.ReferenceCollection b) => b is null ? null : new ReferenceCollection(b);
9797

9898
public IEnumerator<Reference> GetEnumerator()
9999
{
100-
foreach (var reference in innerReferenceCollection)
100+
foreach (var reference in innerCollection)
101101
yield return reference;
102102
}
103103

104104
public virtual Reference Add(string name, string canonicalRefNameOrObjectish)
105105
{
106-
return innerReferenceCollection.Add(name, canonicalRefNameOrObjectish);
106+
return innerCollection.Add(name, canonicalRefNameOrObjectish);
107107
}
108108

109109
public virtual DirectReference Add(string name, ObjectId targetId)
110110
{
111-
return innerReferenceCollection.Add(name, targetId);
111+
return innerCollection.Add(name, targetId);
112112
}
113113

114114
public virtual DirectReference Add(string name, ObjectId targetId, bool allowOverwrite)
115115
{
116-
return innerReferenceCollection.Add(name, targetId, allowOverwrite);
116+
return innerCollection.Add(name, targetId, allowOverwrite);
117117
}
118118

119119
public virtual Reference UpdateTarget(Reference directRef, ObjectId targetId)
120120
{
121-
return innerReferenceCollection.UpdateTarget(directRef, targetId);
121+
return innerCollection.UpdateTarget(directRef, targetId);
122122
}
123123

124124
public virtual ReflogCollection Log(string canonicalName)
125125
{
126-
return innerReferenceCollection.Log(canonicalName);
126+
return innerCollection.Log(canonicalName);
127127
}
128128

129129
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
130-
public virtual Reference this[string name] => innerReferenceCollection[name];
130+
public virtual Reference this[string name] => innerCollection[name];
131131
public virtual Reference Head => this["HEAD"];
132132

133133
public virtual IEnumerable<Reference> FromGlob(string pattern)
134134
{
135-
return innerReferenceCollection.FromGlob(pattern);
135+
return innerCollection.FromGlob(pattern);
136136
}
137137
}
138138

139139
public class CommitCollection : IEnumerable<Commit>
140140
{
141-
private readonly ICommitLog innerCommitCollection;
142-
private CommitCollection(ICommitLog branchCollection) => innerCommitCollection = branchCollection;
141+
private readonly ICommitLog innerCollection;
142+
private CommitCollection(ICommitLog collection) => innerCollection = collection;
143143

144144
protected CommitCollection()
145145
{
146146
}
147147

148-
public static ICommitLog ToCommitLog(CommitCollection d) => d.innerCommitCollection;
148+
public static ICommitLog ToCommitLog(CommitCollection d) => d.innerCollection;
149149

150150
public static CommitCollection FromCommitLog(ICommitLog b) => b is null ? null : new CommitCollection(b);
151151

152152
public virtual IEnumerator<Commit> GetEnumerator()
153153
{
154-
foreach (var branch in innerCommitCollection)
155-
yield return branch;
154+
foreach (var commit in innerCollection)
155+
yield return commit;
156156
}
157157

158158
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
159159

160160
public virtual CommitCollection QueryBy(CommitFilter commitFilter)
161161
{
162-
var commitLog = ((IQueryableCommitLog) innerCommitCollection).QueryBy(commitFilter);
162+
var commitLog = ((IQueryableCommitLog)innerCollection).QueryBy(commitFilter);
163163
return FromCommitLog(commitLog);
164164
}
165165
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using LibGit2Sharp;
4+
5+
namespace GitVersion
6+
{
7+
public static class RepositoryExtensions
8+
{
9+
public static bool GetMatchingCommitBranch(this IGitRepository repository, Commit baseVersionSource, Branch branch, Commit firstMatchingCommit)
10+
{
11+
var filter = new CommitFilter
12+
{
13+
IncludeReachableFrom = (LibGit2Sharp.Branch)branch,
14+
ExcludeReachableFrom = baseVersionSource,
15+
FirstParentOnly = true,
16+
};
17+
var commitCollection = repository.Commits.QueryBy(filter);
18+
19+
return commitCollection.Contains(firstMatchingCommit);
20+
}
21+
22+
public static IEnumerable<Commit> GetCommitsReacheableFrom(this IGitRepository repository, Commit commit, Branch branch)
23+
{
24+
var filter = new CommitFilter
25+
{
26+
IncludeReachableFrom = (LibGit2Sharp.Branch)branch
27+
};
28+
var commitCollection = repository.Commits.QueryBy(filter);
29+
30+
return commitCollection.Where(c => c.Sha == commit.Sha);
31+
}
32+
33+
public static List<Commit> GetCommitsReacheableFromHead(this IGitRepository repository, Commit headCommit)
34+
{
35+
var filter = new CommitFilter
36+
{
37+
IncludeReachableFrom = headCommit,
38+
SortBy = CommitSortStrategies.Topological | CommitSortStrategies.Reverse
39+
};
40+
41+
var commitCollection = repository.Commits.QueryBy(filter);
42+
43+
return commitCollection.ToList();
44+
}
45+
46+
public static Commit GetForwardMerge(this IGitRepository repository, Commit commitToFindCommonBase, Commit findMergeBase)
47+
{
48+
var filter = new CommitFilter
49+
{
50+
IncludeReachableFrom = commitToFindCommonBase,
51+
ExcludeReachableFrom = findMergeBase
52+
};
53+
var commitCollection = repository.Commits.QueryBy(filter);
54+
55+
var forwardMerge = commitCollection
56+
.FirstOrDefault(c => c.Parents.Contains(findMergeBase));
57+
return forwardMerge;
58+
}
59+
60+
public static IEnumerable<Commit> GetMergeBaseCommits(this IGitRepository repository, Commit mergeCommit, Commit mergedHead, Commit findMergeBase)
61+
{
62+
var filter = new CommitFilter
63+
{
64+
IncludeReachableFrom = mergedHead,
65+
ExcludeReachableFrom = findMergeBase
66+
};
67+
var commitCollection = repository.Commits.QueryBy(filter);
68+
69+
var commits = mergeCommit != null
70+
? new[] { mergeCommit }.Union(commitCollection)
71+
: commitCollection;
72+
return commits.ToList();
73+
}
74+
75+
public static Commit GetBaseVersionSource(this IGitRepository repository, Commit currentBranchTip)
76+
{
77+
var filter = new CommitFilter
78+
{
79+
IncludeReachableFrom = currentBranchTip
80+
};
81+
var commitCollection = repository.Commits.QueryBy(filter);
82+
83+
var baseVersionSource = commitCollection.First(c => !c.Parents.Any());
84+
return baseVersionSource;
85+
}
86+
87+
public static List<Commit> GetMainlineCommitLog(this IGitRepository repository, Commit baseVersionSource, Commit mainlineTip)
88+
{
89+
var filter = new CommitFilter
90+
{
91+
IncludeReachableFrom = mainlineTip,
92+
ExcludeReachableFrom = baseVersionSource,
93+
SortBy = CommitSortStrategies.Reverse,
94+
FirstParentOnly = true
95+
};
96+
var commitCollection = repository.Commits.QueryBy(filter);
97+
98+
var mainlineCommitLog = commitCollection.ToList();
99+
return mainlineCommitLog;
100+
}
101+
102+
public static CommitCollection GetCommitLog(this IGitRepository repository, Commit baseVersionSource, Commit currentCommit)
103+
{
104+
var filter = new CommitFilter
105+
{
106+
IncludeReachableFrom = currentCommit,
107+
ExcludeReachableFrom = baseVersionSource,
108+
SortBy = CommitSortStrategies.Topological | CommitSortStrategies.Time
109+
};
110+
111+
var commitCollection = repository.Commits.QueryBy(filter);
112+
113+
return commitCollection;
114+
}
115+
}
116+
}

0 commit comments

Comments
 (0)