8000 Deprecate Branch.Checkout() · GiTechLab/libgit2sharp@19cd9f5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 19cd9f5

Browse files
committed
Deprecate Branch.Checkout()
1 parent 03e2bb2 commit 19cd9f5

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

LibGit2Sharp.Tests/CheckoutFixture.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public void CheckoutAddsMissingFilesInWorkingDirectory()
162162
// Checkout other_branch
163163
Branch otherBranch = repo.Branches[otherBranchName];
164164
Assert.NotNull(otherBranch);
165-
otherBranch.Checkout();
165+
repo.Checkout(otherBranch);
166166

167167
// Verify working directory is updated
168168
Assert.False(repo.RetrieveStatus().IsDirty);
@@ -190,7 +190,7 @@ public void CheckoutRemovesExtraFilesInWorkingDirectory()
190190
// Checkout other_branch
191191
Branch otherBranch = repo.Branches[otherBranchName];
192192
Assert.NotNull(otherBranch);
193-
otherBranch.Checkout();
193+
repo.Checkout(otherBranch);
194194

195195
// Verify working directory is updated
196196
Assert.False(repo.RetrieveStatus().IsDirty);
@@ -218,7 +218,7 @@ public void CheckoutUpdatesModifiedFilesInWorkingDirectory()
218218
// Checkout other_branch
219219
Branch otherBranch = repo.Branches[otherBranchName];
220220
Assert.NotNull(otherBranch);
221-
otherBranch.Checkout();
221+
repo.Checkout(otherBranch);
222222

223223
// Verify working directory is updated
224224
Assert.False(repo.RetrieveStatus().IsDirty);
@@ -410,7 +410,8 @@ public void CheckingOutThroughBranchCallsCheckoutProgress()
410410
bool wasCalled = false;
411411

412412
Branch branch = repo.Branches[otherBranchName];
413-
branch.Checkout(new CheckoutOptions() { OnCheckoutProgress = (path, completed, total) => wasCalled = true});
413+
repo.Checkout(branch,
414+
new CheckoutOptions { OnCheckoutProgress = (path, completed, total) => wasCalled = true});
414415

415416
Assert.True(wasCalled);
416417
}
@@ -684,7 +685,7 @@ public void CheckoutBranchSnapshot()
684685

685686
Assert.False(repo.Info.IsHeadDetached);
686687

687-
initial.Checkout();
688+
repo.Checkout(initial);
688689

689690
// Head should point at initial commit.
690691
Assert.Equal(repo.Head.Tip, initialCommit);

LibGit2Sharp.Tests/CherryPickFixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void CherryPickWithConflictDoesNotCommit()
4646
using (var repo = new Repository(path))
4747
{
4848
var firstBranch = repo.CreateBranch("FirstBranch");
49-
firstBranch.Checkout();
49+
repo.Checkout(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-
secondBranch.Checkout();
59+
repo.Checkout(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/MergeFixture.cs

Lines changed: 10 additions & 10 deletions
282
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public void CanMergeRepoNonFastForward(bool shouldMergeOccurInDetachedHeadState)
9494
using (var repo = new Repository(path))
9595
{
9696
var firstBranch = repo.CreateBranch("FirstBranch");
97-
firstBranch.Checkout();
97+
repo.Checkout(firstBranch);
9898
var originalTreeCount = firstBranch.Tip.Tree.Count;
9999

100100
// Commit with ONE new file to both first & second branch (SecondBranch is created on this commit).
@@ -111,7 +111,7 @@ public void CanMergeRepoNonFastForward(bool shouldMergeOccurInDetachedHeadState)
111111
}
112112
else
113113
{
114-
secondBranch.Checkout();
114+
repo.Checkout(secondBranch);
115115
}
116116

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

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

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

153-
secondBranch.Checkout();
153+
repo.Checkout(secondBranch);
154154

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

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

178178
var firstBranch = repo.CreateBranch("FirstBranch");
179-
firstBranch.Checkout();
179+
repo.Checkout(firstBranch);
180180

181181
// Commit with ONE new file to both first & second branch (SecondBranch is created on this commit).
182182
AddFileCommitToRepo(repo, sharedBranchFileName);
@@ -193,7 +193,7 @@ public void CanFastForwardRepos(bool shouldMergeOccurInDetachedHeadState)
193193
}
194194
else
195195
{
196-
secondBranch.Checkout();
196+
repo.Checkout(secondBranch);
197197
}
198198

199199
Assert.Equal(shouldMergeOccurInDetachedHeadState, repo.Info.IsHeadDetached);
@@ -227,7 +227,7 @@ public void ConflictingMergeRepos()
227227
using (var repo = new Repository(path))
228228
{
229229
var firstBranch = repo.CreateBranch("FirstBranch");
230-
firstBranch.Checkout();
230+
repo.Checkout(firstBranch);
231231

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

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

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

280-
secondBranch.Checkout();
280+
repo.Checkout(secondBranch);
281281
// Commit with ONE new file to second branch (FirstBranch and SecondBranch now point to separate commits that both have the same parent commit).
282
AddFileCommitToRepo(repo, secondBranchFileName);
283283
AddFileCommitToRepo(repo, sharedBranchFileName, "\0The second branches comment\0"); // Change file in second branch

LibGit2Sharp/Branch.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ private string RemoteNameFromRemoteTrackingBranch()
225225
/// the named branch. Otherwise, will checkout the tip commit as a
226226
/// detached HEAD.
227227
/// </summary>
228+
[Obsolete("This method will be removed in the next release. Please use IRepository.Checkout() instead.")]
228229
public virtual void Checkout()
229230
{
230231
repo.Checkout(this);
@@ -239,6 +240,7 @@ public virtual void Checkout()
239240
/// </summary>
240241
/// <param name="options"><see cref="CheckoutOptions"/> controlling checkout behavior.</param>
241242
/// <param name="signature">Identity for use when updating the reflog.</param>
243+
[Obsolete("This method will be removed in the next release. Please use IRepository.Checkout() instead.")]
242244
public virtual void Checkout(CheckoutOptions options, Signature signature = null)
243245
{
244246
Ensure.ArgumentNotNull(options, "options");

0 commit comments

Comments
 (0)
0