Skip to content

Commit edf3593

Browse files
committed
moved IGitRepositoryCommands into IGitRepository
1 parent 5eb9751 commit edf3593

File tree

7 files changed

+39
-67
lines changed

7 files changed

+39
-67
lines changed

src/GitVersionCore.Tests/Core/RepositoryExtensionsTests.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ private static void EnsureLocalBranchExistsForCurrentBranch(IGitRepository repo,
6161
repo.Refs.UpdateTarget(localRef, repoTipId);
6262
}
6363

64-
repo.Commands.Checkout(localCanonicalName);
64+
repo.Checkout(localCanonicalName);
6565
}
6666

6767
[Test]
@@ -77,8 +77,6 @@ public void EnsureLocalBranchExistsForCurrentBranch_CaseInsensitivelyMatchesBran
7777
private static IGitRepository MockRepository()
7878
{
7979
var repository = Substitute.For<IGitRepository>();
80-
var commands = Substitute.For<IGitRepositoryCommands>();
81-
repository.Commands.Returns(commands);
8280
return repository;
8381
}
8482

src/GitVersionCore.Tests/Mocks/MockRepository.cs

+12-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ namespace GitVersionCore.Tests.Mocks
88
public class MockRepository : IGitRepository
99
{
1010
private CommitCollection commits;
11-
public IGitRepositoryCommands Commands { get; }
12-
1311
public MockRepository()
1412
{
1513
Tags = new MockTagCollection();
@@ -75,6 +73,18 @@ public CommitCollection GetCommitLog(Commit baseVersionSource, Commit currentCom
7573
{
7674
throw new NotImplementedException();
7775
}
76+
public void Checkout(string committishOrBranchSpec)
77+
{
78+
throw new NotImplementedException();
79+
}
80+
public void Checkout(Branch branch)
81+
{
82+
throw new NotImplementedException();
83+
}
84+
public void Fetch(string remote, IEnumerable<string> refspecs, AuthenticationInfo auth, string logMessage)
85+
{
86+
throw new NotImplementedException();
87+
}
7888
public Remote EnsureOnlyOneRemoteIsDefined(ILog log) => throw new NotImplementedException();
7989
public void Dispose() => throw new NotImplementedException();
8090
}

src/GitVersionCore/Core/Abstractions/IGitRepository.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ public interface IGitRepository : IDisposable
99
string Path { get; }
1010
string WorkingDirectory { get; }
1111
bool IsHeadDetached { get; }
12-
IGitRepositoryCommands Commands { get; }
1312
Branch Head { get; }
1413
CommitCollection Commits { get; }
1514
BranchCollection Branches { get; }
@@ -31,5 +30,9 @@ public interface IGitRepository : IDisposable
3130
Commit GetBaseVersionSource(Commit currentBranchTip);
3231
List<Commit> GetMainlineCommitLog(Commit baseVersionSource, Commit mainlineTip);
3332
CommitCollection GetCommitLog(Commit baseVersionSource, Commit currentCommit);
33+
34+
void Checkout(string committishOrBranchSpec);
35+
void Checkout(Branch branch);
36+
void Fetch(string remote, IEnumerable<string> refspecs, AuthenticationInfo auth, string logMessage);
3437
}
3538
}

src/GitVersionCore/Core/Abstractions/IGitRepositoryCommands.cs

-14
This file was deleted.

src/GitVersionCore/Core/GitPreparer.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ private void NormalizeGitDirectory(string gitDirectory, bool noFetch, string cur
157157
else
158158
{
159159
log.Info($"Fetching from remote '{remote.Name}' using the following refspecs: {remote.RefSpecs}.");
160-
repository.Commands.Fetch(remote.Name, new string[0], authentication, null);
160+
repository.Fetch(remote.Name, new string[0], authentication, null);
161161
}
162162

163163
EnsureLocalBranchExistsForCurrentBranch(repository, log, remote, currentBranch);
@@ -198,7 +198,7 @@ private void NormalizeGitDirectory(string gitDirectory, bool noFetch, string cur
198198
if (matchingCurrentBranch != null)
199199
{
200200
log.Info($"Checking out local branch '{currentBranch}'.");
201-
repository.Commands.Checkout(matchingCurrentBranch);
201+
repository.Checkout(matchingCurrentBranch);
202202
}
203203
else if (localBranchesWhereCommitShaIsHead.Count > 1)
204204
{
@@ -211,7 +211,7 @@ private void NormalizeGitDirectory(string gitDirectory, bool noFetch, string cur
211211
if (master != null)
212212
{
213213
log.Warning("Because one of the branches is 'master', will build master." + moveBranchMsg);
214-
repository.Commands.Checkout(master);
214+
repository.Checkout(master);
215215
}
216216
else
217217
{
@@ -220,7 +220,7 @@ private void NormalizeGitDirectory(string gitDirectory, bool noFetch, string cur
220220
{
221221
var branchWithoutSeparator = branchesWithoutSeparators[0];
222222
log.Warning($"Choosing {branchWithoutSeparator.CanonicalName} as it is the only branch without / or - in it. " + moveBranchMsg);
223-
repository.Commands.Checkout(branchWithoutSeparator);
223+
repository.Checkout(branchWithoutSeparator);
224224
}
225225
else
226226
{
@@ -236,7 +236,7 @@ private void NormalizeGitDirectory(string gitDirectory, bool noFetch, string cur
236236
else
237237
{
238238
log.Info($"Checking out local branch 'refs/heads/{localBranchesWhereCommitShaIsHead[0].FriendlyName}'.");
239-
repository.Commands.Checkout(repository.Branches[localBranchesWhereCommitShaIsHead[0].FriendlyName]);
239+
repository.Checkout(repository.Branches[localBranchesWhereCommitShaIsHead[0].FriendlyName]);
240240
}
241241
}
242242
finally
@@ -343,7 +343,7 @@ private static void EnsureLocalBranchExistsForCurrentBranch(IGitRepository repo,
343343
repo.Refs.UpdateTarget(localRef, repoTipId);
344344
}
345345

346-
repo.Commands.Checkout(localCanonicalName);
346+
repo.Checkout(localCanonicalName);
347347
}
348348
}
349349
}

src/GitVersionCore/Core/GitRepository.cs

+16-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ namespace GitVersion
1010
{
1111
public class GitRepository : IGitRepository
1212
{
13-
public IGitRepositoryCommands Commands { get; }
1413
private Lazy<IRepository> repositoryLazy;
1514
private IRepository repositoryInstance => repositoryLazy.Value;
1615

@@ -26,13 +25,11 @@ internal GitRepository(string gitRootDirectory)
2625
internal GitRepository(IRepository repository)
2726
{
2827
repositoryLazy = new Lazy<IRepository>(() => repository);
29-
Commands = new GitRepositoryCommands(repositoryLazy);
3028
}
3129

3230
private GitRepository(Func<string> getGitRootDirectory)
3331
{
3432
repositoryLazy = new Lazy<IRepository>(() => new Repository(getGitRootDirectory()));
35-
Commands = new GitRepositoryCommands(repositoryLazy);
3633
}
3734

3835
public static string Discover(string path) => Repository.Discover(path);
@@ -156,7 +153,7 @@ public void CreateBranchForPullRequestBranch(ILog log, AuthenticationInfo auth)
156153
if (canonicalName.StartsWith("refs/tags"))
157154
{
158155
log.Info($"Checking out tag '{canonicalName}'");
159-
Commands.Checkout(reference.Target.Sha);
156+
Checkout(reference.Target.Sha);
160157
return;
161158
}
162159

@@ -172,7 +169,7 @@ public void CreateBranchForPullRequestBranch(ILog log, AuthenticationInfo auth)
172169
Refs.Add(fakeBranchName, new ObjectId(headTipSha));
173170

174171
log.Info($"Checking local branch '{fakeBranchName}' out.");
175-
Commands.Checkout(fakeBranchName);
172+
Checkout(fakeBranchName);
176173
}
177174
public bool GitRepoHasMatchingRemote(string targetUrl)
178175
{
@@ -362,5 +359,19 @@ public CommitCollection GetCommitLog(Commit baseVersionSource, Commit currentCom
362359

363360
return commitCollection;
364361
}
362+
public void Checkout(string committishOrBranchSpec)
363+
{
364+
Commands.Checkout(repositoryInstance, committishOrBranchSpec);
365+
}
366+
367+
public void Checkout(Branch branch)
368+
{
369+
Commands.Checkout(repositoryInstance, branch);
370+
}
371+
372+
public void Fetch(string remote, IEnumerable<string> refspecs, AuthenticationInfo auth, string logMessage)
373+
{
374+
Commands.Fetch((Repository)repositoryInstance, remote, refspecs, GitRepository.GetFetchOptions(auth), logMessage);
375+
}
365376
}
366377
}

src/GitVersionCore/Core/GitRepositoryCommands.cs

-36
This file was deleted.

0 commit comments

Comments
 (0)