Skip to content

Commit 7f4a17f

Browse files
committed
Move some versions of Checkout to Commands
1 parent 4038caf commit 7f4a17f

21 files changed

+354
-210
lines changed

LibGit2Sharp.Tests/BranchFixture.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public void CanCreateBranchFromImplicitHead(string headCommitOrBranchSpec)
121121
{
122122
EnableRefLog(repo);
123123

124-
repo.Checkout(headCommitOrBranchSpec);
124+
Commands.Checkout(repo, headCommitOrBranchSpec);
125125

126126
const string name = "unit_test";
127127

@@ -154,7 +154,7 @@ public void CanCreateBranchFromExplicitHead(string headCommitOrBranchSpec)
154154
{
155155
EnableRefLog(repo);
156156

157-
repo.Checkout(headCommitOrBranchSpec);
157+
Commands.Checkout(repo, headCommitOrBranchSpec);
158158

159159
const string name = "unit_test";
160160

@@ -1092,7 +1092,7 @@ public void DetachedHeadIsNotATrackingBranch()
10921092
repo.RemoveUntrackedFiles();
10931093

10941094
string headSha = repo.Head.Tip.Sha;
1095-
repo.Checkout(headSha);
1095+
Commands.Checkout(repo, headSha);
10961096

10971097
Assert.False(repo.Head.IsTracking);
10981098
Assert.Null(repo.Head.TrackedBranch);

LibGit2Sharp.Tests/CheckoutFixture.cs

Lines changed: 56 additions & 56 deletions
Large diffs are not rendered by default.

LibGit2Sharp.Tests/CherryPickFixture.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public void CanCherryPick(bool fromDetachedHead)
1919
{
2020
if (fromDetachedHead)
2121
{
22-
repo.Checkout(repo.Head.Tip.Id.Sha);
22+
Commands.Checkout(repo, repo.Head.Tip.Id.Sha);
2323
}
2424

2525
Commit commitToMerge = repo.Branches["fast_forward"].Tip;
@@ -46,7 +46,7 @@ public void CherryPickWithConflictDoesNotCommit()
4646
using (var repo = new Repository(path))
4747
{
4848
var firstBranch = repo.CreateBranch("FirstBranch");
49-
repo.Checkout(firstBranch);
49+
Commands.Checkout(repo, firstBranch);
5050

5151
// Commit with ONE new file to both first & second branch (SecondBranch is created on this commit).
5252
AddFileCommitToRepo(repo, sharedBranchFileName);
@@ -56,7 +56,7 @@ public void CherryPickWithConflictDoesNotCommit()
5656
AddFileCommitToRepo(repo, firstBranchFileName);
5757
AddFileCommitToRepo(repo, sharedBranchFileName, "The first branches comment"); // Change file in first branch
5858

59-
repo.Checkout(secondBranch);
59+
Commands.Checkout(repo, secondBranch);
6060
// Commit with ONE new file to second branch (FirstBranch and SecondBranch now point to separate commits that both have the same parent commit).
6161
AddFileCommitToRepo(repo, secondBranchFileName);
6262
AddFileCommitToRepo(repo, sharedBranchFileName, "The second branches comment"); // Change file in second branch

LibGit2Sharp.Tests/CommitFixture.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ public void CanCorrectlyCountCommitsWhenSwitchingToAnotherBranch()
3434
repo.Reset(ResetMode.Hard);
3535
repo.RemoveUntrackedFiles();
3636

37-
repo.Checkout("test");
37+
Commands.Checkout(repo, "test");
3838
Assert.Equal(2, repo.Commits.Count());
3939
Assert.Equal("e90810b8df3e80c413d903f631643c716887138d", repo.Commits.First().Id.Sha);
4040

41-
repo.Checkout("master");
41+
Commands.Checkout(repo, "master");
4242
Assert.Equal(9, repo.Commits.Count());
4343
Assert.Equal("32eab9cb1f450b5fe7ab663462b77d7f4b703344", repo.Commits.First().Id.Sha);
4444
}
@@ -274,7 +274,7 @@ public void CanEnumerateFromDetachedHead()
274274
repoClone.RemoveUntrackedFiles();
275275

276276
string headSha = repoClone.Head.Tip.Sha;
277-
repoClone.Checkout(headSha);
277+
Commands.Checkout(repoClone, headSha);
278278

279279
AssertEnumerationOfCommitsInRepo(repoClone,
280280
repo => new CommitFilter { IncludeReachableFrom = repo.Head },
@@ -708,7 +708,7 @@ public void CanCommitALittleBit()
708708
Assert.Equal(reflogEntry.To, repo.Refs.Log("HEAD").First().From);
709709

710710
Branch firstCommitBranch = repo.CreateBranch("davidfowl-rules", commit);
711-
repo.Checkout(firstCommitBranch);
711+
Commands.Checkout(repo, firstCommitBranch);
712712

713713
File.WriteAllText(filePath, "davidfowl commits!\n");
714714

LibGit2Sharp.Tests/DescribeFixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ public void CanFollowFirstParent()
6464
repo.ApplyTag("firstParentTag");
6565

6666
// Make a later tag on branch
67-
repo.Checkout(branch);
67+
Commands.Checkout(repo, branch);
6868
repo.Commit("B", Constants.Signature, Constants.Signature, new CommitOptions { AllowEmptyCommit = true });
6969
repo.ApplyTag("mostRecentTag");
7070

71-
repo.Checkout("master");
71+
Commands.Checkout(repo, "master");
7272
repo.Commit("C", Constants.Signature, Constants.Signature, new CommitOptions { AllowEmptyCommit = true });
7373
repo.Merge(branch, Constants.Signature, new MergeOptions() { FastForwardStrategy = FastForwardStrategy.NoFastForward });
7474

LibGit2Sharp.Tests/FileHistoryFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public void CanFollowBranches(string specificRepoPath)
9494
dummy, master9);
9595

9696
repo.CreateBranch("master", master10);
97-
repo.Checkout("master", new CheckoutOptions { CheckoutModifiers = CheckoutModifiers.Force });
97+
Commands.Checkout(repo, "master", new CheckoutOptions { CheckoutModifiers = CheckoutModifiers.Force });
9898

9999
// Test --date-order.
100100
var timeHistory = repo.Commits.QueryBy(path,

LibGit2Sharp.Tests/FilterFixture.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public void CanFilterLargeFiles()
284284
Commands.Stage(repo, contentFile.Name);
285285
repo.Commit("test", Constants.Signature, Constants.Signature);
286286
contentFile.Delete();
287-
repo.Checkout("HEAD", new CheckoutOptions() { CheckoutModifiers = CheckoutModifiers.Force });
287+
Commands.Checkout(repo, "HEAD", new CheckoutOptions() { CheckoutModifiers = CheckoutModifiers.Force });
288288
}
289289

290290
contentFile = new FileInfo(filePath);
@@ -392,17 +392,17 @@ private FileInfo CheckoutFileForSmudge(string repoPath, string branchName, strin
392392

393393
expectedPath = CommitFileOnBranch(repo, branchName, content);
394394

395-
repo.Checkout("master");
395+
Commands.Checkout(repo, "master");
396396

397-
repo.Checkout(branchName);
397+
Commands.Checkout(repo, branchName);
398398
}
399399
return expectedPath;
400400
}
401401

402402
private static FileInfo CommitFileOnBranch(Repository repo, string branchName, String content)
403403
{
404404
var branch = repo.CreateBranch(branchName);
405-
repo.Checkout(branch.FriendlyName);
405+
Commands.Checkout(repo, branch.FriendlyName);
406406

407407
FileInfo expectedPath = StageNewFile(repo, content);
408408
repo.Commit("Commit", Constants.Signature, Constants.Signature);

LibGit2Sharp.Tests/FilterSubstitutionCipherFixture.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ public void SmugdeIsNotCalledForFileWhichDoesNotMatchAnAttributeEntry()
3434
Assert.Equal(0, filter.SmudgeCalledCount);
3535

3636
var branch = repo.CreateBranch("delete-files");
37-
repo.Checkout(branch.FriendlyName);
37+
Commands.Checkout(repo, branch.FriendlyName);
3838

3939
DeleteFile(repo, fileName);
4040

41-
repo.Checkout("master");
41+
Commands.Checkout(repo, "master");
4242

4343
var fileContents = ReadTextFromFile(repo, fileName);
4444
Assert.Equal(1, filter.SmudgeCalledCount);
@@ -73,11 +73,11 @@ public void CorrectlyEncodesAndDecodesInput()
7373
Assert.Equal(0, filter.SmudgeCalledCount);
7474

7575
var branch = repo.CreateBranch("delete-files");
76-
repo.Checkout(branch.FriendlyName);
76+
Commands.Checkout(repo, branch.FriendlyName);
7777

7878
DeleteFile(repo, fileName);
7979

80-
repo.Checkout("master");
80+
Commands.Checkout(repo, "master");
8181

8282
var fileContents = ReadTextFromFile(repo, fileName);
8383
Assert.Equal(1, filter.SmudgeCalledCount);
@@ -176,11 +176,11 @@ public void SmudgeIsCalledIfAttributeEntryMatches(string filterAttribute, string
176176
CommitOnBranchAndReturnDatabaseBlob(repo, fileName, decodedInput);
177177

178178
var branch = repo.CreateBranch("delete-files");
179-
repo.Checkout(branch.FriendlyName);
179+
Commands.Checkout(repo, branch.FriendlyName);
180180

181181
DeleteFile(repo, fileName);
182182

183-
repo.Checkout("master");
183+
Commands.Checkout(repo, "master");
184184

185185
Assert.Equal(smudgeCount, filter.SmudgeCalledCount);
186186
}

LibGit2Sharp.Tests/MergeFixture.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void CanMergeRepoNonFastForward(bool shouldMergeOccurInDetachedHeadState)
9393
using (var repo = new Repository(path))
9494
{
9595
var firstBranch = repo.CreateBranch("FirstBranch");
96-
repo.Checkout(firstBranch);
96+
Commands.Checkout(repo, firstBranch);
9797
var originalTreeCount = firstBranch.Tip.Tree.Count;
9898

9999
// Commit with ONE new file to both first & second branch (SecondBranch is created on this commit).
@@ -106,11 +106,11 @@ public void CanMergeRepoNonFastForward(bool shouldMergeOccurInDetachedHeadState)
106106
if (shouldMergeOccurInDetachedHeadState)
107107
{
108108
// Detaches HEAD
109-
repo.Checkout(secondBranch.Tip);
109+
Commands.Checkout(repo, secondBranch.Tip);
110110
}
111111
else
112112
{
113-
repo.Checkout(secondBranch);
113+
Commands.Checkout(repo, secondBranch);
114114
}
115115

116116
// Commit with ONE new file to second branch (FirstBranch and SecondBranch now point to separate commits that both have the same parent commit).
@@ -142,14 +142,14 @@ public void IsUpToDateMerge()
142142
using (var repo = new Repository(path))
143143
{
144144
var firstBranch = repo.CreateBranch("FirstBranch");
145-
repo.Checkout(firstBranch);
145+
Commands.Checkout(repo, firstBranch);
146146

147147
// Commit with ONE new file to both first & second branch (SecondBranch is created on this commit).
148148
AddFileCommitToRepo(repo, sharedBranchFileName);
149149

150150
var secondBranch = repo.CreateBranch("SecondBranch");
151151

152-
repo.Checkout(secondBranch);
152+
Commands.Checkout(repo, secondBranch);
153153

154154
MergeResult mergeResult = repo.Merge(repo.Branches["FirstBranch"].Tip, Constants.Signature);
155155

@@ -175,7 +175,7 @@ public void CanFastForwardRepos(bool shouldMergeOccurInDetachedHeadState)
175175
repo.RemoveUntrackedFiles();
176176

177177
var firstBranch = repo.CreateBranch("FirstBranch");
178-
repo.Checkout(firstBranch);
178+
Commands.Checkout(repo, firstBranch);
179179

180180
// Commit with ONE new file to both first & second branch (SecondBranch is created on this commit).
181181
AddFileCommitToRepo(repo, sharedBranchFileName);
@@ -188,11 +188,11 @@ public void CanFastForwardRepos(bool shouldMergeOccurInDetachedHeadState)
188188
if (shouldMergeOccurInDetachedHeadState)
189189
{
190190
// Detaches HEAD
191-
repo.Checkout(secondBranch.Tip);
191+
Commands.Checkout(repo, secondBranch.Tip);
192192
}
193193
else
194194
{
195-
repo.Checkout(secondBranch);
195+
Commands.Checkout(repo, secondBranch);
196196
}
197197

198198
Assert.Equal(shouldMergeOccurInDetachedHeadState, repo.Info.IsHeadDetached);
@@ -226,7 +226,7 @@ public void ConflictingMergeRepos()
226226
using (var repo = new Repository(path))
227227
{
228228
var firstBranch = repo.CreateBranch("FirstBranch");
229-
repo.Checkout(firstBranch);
229+
Commands.Checkout(repo, firstBranch);
230230

231231
// Commit with ONE new file to both first & second branch (SecondBranch is created on this commit).
232232
AddFileCommitToRepo(repo, sharedBranchFileName);
@@ -236,7 +236,7 @@ public void ConflictingMergeRepos()
236236
AddFileCommitToRepo(repo, firstBranchFileName);
237237
AddFileCommitToRepo(repo, sharedBranchFileName, "The first branches comment"); // Change file in first branch
238238

239-
repo.Checkout(secondBranch);
239+
Commands.Checkout(repo, secondBranch);
240240
// Commit with ONE new file to second branch (FirstBranch and SecondBranch now point to separate commits that both have the same parent commit).
241241
AddFileCommitToRepo(repo, secondBranchFileName);
242242
AddFileCommitToRepo(repo, sharedBranchFileName, "The second branches comment"); // Change file in second branch
@@ -266,7 +266,7 @@ public void ConflictingMergeReposBinary()
266266
using (var repo = new Repository(path))
267267
{
268268
var firstBranch = repo.CreateBranch("FirstBranch");
269-
repo.Checkout(firstBranch);
269+
Commands.Checkout(repo, firstBranch);
270270

271271
// Commit with ONE new file to both first & second branch (SecondBranch is created on this commit).
272272
AddFileCommitToRepo(repo, sharedBranchFileName);
@@ -276,7 +276,7 @@ public void ConflictingMergeReposBinary()
276276
AddFileCommitToRepo(repo, firstBranchFileName);
277277
AddFileCommitToRepo(repo, sharedBranchFileName, "\0The first branches comment\0"); // Change file in first branch
278278

279-
repo.Checkout(secondBranch);
279+
Commands.Checkout(repo, secondBranch);
280280
// Commit with ONE new file to second branch (FirstBranch and SecondBranch now point to separate commits that both have the same parent commit).
281281
AddFileCommitToRepo(repo, secondBranchFileName);
282282
AddFileCommitToRepo(repo, sharedBranchFileName, "\0The second branches comment\0"); // Change file in second branch
@@ -325,7 +325,7 @@ public void CanFastForwardCommit(bool fromDetachedHead, FastForwardStrategy fast
325325
{
326326
if(fromDetachedHead)
327327
{
328-
repo.Checkout(repo.Head.Tip.Id.Sha);
328+
Commands.Checkout(repo, repo.Head.Tip.Id.Sha);
329329
}
330330

331331
Commit commitToMerge = repo.Branches["fast_forward"].Tip;
@@ -351,7 +351,7 @@ public void CanNonFastForwardMergeCommit(bool fromDetachedHead, FastForwardStrat
351351
{
352352
if (fromDetachedHead)
353353
{
354-
repo.Checkout(repo.Head.Tip.Id.Sha);
354+
Commands.Checkout(repo, repo.Head.Tip.Id.Sha);
355355
}
356356

357357
Commit commitToMerge = repo.Branches["normal_merge"].Tip;
@@ -469,7 +469,7 @@ public void MergeCanDetectRenames()
469469
string repoPath = SandboxMergeTestRepo();
470470
using (var repo = new Repository(repoPath))
471471
{
472-
Branch currentBranch = repo.Checkout("rename_source");
472+
Branch currentBranch = Commands.Checkout(repo, "rename_source");
473473
Assert.NotNull(currentBranch);
474474

475475
Branch branchToMerge = repo.Branches["rename"];

0 commit comments

Comments
 (0)