Skip to content

Commit 84b3c19

Browse files
author
Edward Thomson
committed
Merge pull request #1291 from libgit2/cmn/stage-command
Move Stage and Remove to commands
2 parents 2850cc5 + 78be980 commit 84b3c19

37 files changed

+866
-583
lines changed

LibGit2Sharp.Tests/AttributesFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ private static void AssertNormalization(IRepository repo, string filename, bool
2929

3030
Touch(repo.Info.WorkingDirectory, filename, sb.ToString());
3131

32-
repo.Stage(filename);
32+
Commands.Stage(repo, filename);
3333

3434
IndexEntry entry = repo.Index[filename];
3535
Assert.NotNull(entry);

LibGit2Sharp.Tests/BlobFixture.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void CanGetBlobAsTextWithVariousEncodings(string encodingName, int expect
6363
var bomPath = Touch(repo.Info.WorkingDirectory, bomFile, content, encoding);
6464
Assert.Equal(expectedContentBytes, File.ReadAllBytes(bomPath).Length);
6565

66-
repo.Stage(bomFile);
66+
Commands.Stage(repo, bomFile);
6767
var commit = repo.Commit("bom", Constants.Signature, Constants.Signature);
6868

6969
var blob = (Blob)commit.Tree[bomFile].Target;
@@ -190,7 +190,7 @@ public void CanStageAFileGeneratedFromABlobContentStream()
190190
File.AppendAllText(Path.Combine(repo.Info.WorkingDirectory, "small.txt"), sb.ToString());
191191
}
192192

193-
repo.Stage("small.txt");
193+
Commands.Stage(repo, "small.txt");
194194
IndexEntry entry = repo.Index["small.txt"];
195195
Assert.Equal("baae1fb3760a73481ced1fa03dc15614142c19ef", entry.Id.Sha);
196196

@@ -202,7 +202,7 @@ public void CanStageAFileGeneratedFromABlobContentStream()
202202
CopyStream(stream, file);
203203
}
204204

205-
repo.Stage("small.fromblob.txt");
205+
Commands.Stage(repo, "small.fromblob.txt");
206206
IndexEntry newentry = repo.Index["small.fromblob.txt"];
207207

208208
Assert.Equal("baae1fb3760a73481ced1fa03dc15614142c19ef", newentry.Id.Sha);

LibGit2Sharp.Tests/BranchFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ public void TrackedBranchExistsFromDefaultConfigInEmptyClone()
11371137
Assert.Equal("origin", repo.Head.RemoteName);
11381138

11391139
Touch(repo.Info.WorkingDirectory, "a.txt", "a");
1140-
repo.Stage("a.txt");
1140+
Commands.Stage(repo, "a.txt");
11411141
repo.Commit("A file", Constants.Signature, Constants.Signature);
11421142

11431143
Assert.NotNull(repo.Head.Tip);

LibGit2Sharp.Tests/CheckoutFixture.cs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public void CheckoutAddsMissingFilesInWorkingDirectory()
156156
// Remove the file in master branch
157157
// Verify it exists after checking out otherBranch.
158158
string fileFullPath = Path.Combine(repo.Info.WorkingDirectory, originalFilePath);
159-
repo.Remove(fileFullPath);
159+
Commands.Remove(repo, fileFullPath);
160160
repo.Commit("2nd commit", Constants.Signature, Constants.Signature);
161161

162162
// Checkout other_branch
@@ -184,7 +184,7 @@ public void CheckoutRemovesExtraFilesInWorkingDirectory()
184184
string newFileFullPath = Touch(
185185
repo.Info.WorkingDirectory, "b.txt", "hello from master branch!\n");
186186

187-
repo.Stage(newFileFullPath);
187+
Commands.Stage(repo, newFileFullPath);
188188
repo.Commit("2nd commit", Constants.Signature, Constants.Signature);
189189

190190
// Checkout other_branch
@@ -212,7 +212,7 @@ public void CheckoutUpdatesModifiedFilesInWorkingDirectory()
212212
string fullPath = Touch(
213213
repo.Info.WorkingDirectory, originalFilePath, "Update : hello from master branch!\n");
214214

215-
repo.Stage(fullPath);
215+
Commands.Stage(repo, fullPath);
216216
repo.Commit("2nd commit", Constants.Signature, Constants.Signature);
217217

218218
// Checkout other_branch
@@ -254,15 +254,15 @@ public void CanForcefullyCheckoutWithConflictingStagedChanges()
254254
// Add change to master.
255255
Touch(repo.Info.WorkingDirectory, originalFilePath, originalFileContent);
256256

257-
repo.Stage(originalFilePath);
257+
Commands.Stage(repo, originalFilePath);
258258
repo.Commit("change in master", Constants.Signature, Constants.Signature);
259259

260260
// Checkout otherBranch.
261261
repo.Checkout(otherBranchName);
262262

263263
// Add change to otherBranch.
264264
Touch(repo.Info.WorkingDirectory, originalFilePath, alternateFileContent);
265-
repo.Stage(originalFilePath);
265+
Commands.Stage(repo, originalFilePath);
266266

267267
// Assert that normal checkout throws exception
268268
// for the conflict.
@@ -287,15 +287,15 @@ public void CheckingOutWithMergeConflictsThrows()
287287
using (var repo = new Repository(repoPath))
288288
{
289289
Touch(repo.Info.WorkingDirectory, originalFilePath, "Hello\n");
290-
repo.Stage(originalFilePath);
290+
Commands.Stage(repo, originalFilePath);
291291
repo.Commit("Initial commit", Constants.Signature, Constants.Signature);
292292

293293
// Create 2nd branch
294294
repo.CreateBranch("branch2");
295295

296296
// Update file in main
297297
Touch(repo.Info.WorkingDirectory, originalFilePath, "Hello from master!\n");
298-
repo.Stage(originalFilePath);
298+
Commands.Stage(repo, originalFilePath);
299299
repo.Commit("2nd commit", Constants.Signature, Constants.Signature);
300300

301301
// Checkout branch2
@@ -307,7 +307,7 @@ public void CheckingOutWithMergeConflictsThrows()
307307
Assert.Throws<CheckoutConflictException>(() => repo.Checkout("master"));
308308

309309
// And when there are staged commits
310-
repo.Stage(originalFilePath);
310+
Commands.Stage(repo, originalFilePath);
311311
Assert.Throws<CheckoutConflictException>(() => repo.Checkout("master"));
312312
}
313313
}
@@ -322,15 +322,15 @@ public void CanCancelCheckoutThroughNotifyCallback()
322322
const string relativePath = "a.txt";
323323
Touch(repo.Info.WorkingDirectory, relativePath, "Hello\n");
324324

325-
repo.Stage(relativePath);
325+
Commands.Stage(repo, relativePath);
326326
repo.Commit("Initial commit", Constants.Signature, Constants.Signature);
327327

328328
// Create 2nd branch
329329
repo.CreateBranch("branch2");
330330

331331
// Update file in main
332332
Touch(repo.Info.WorkingDirectory, relativePath, "Hello from master!\n");
333-
repo.Stage(relativePath);
333+
Commands.Stage(repo, relativePath);
334334
repo.Commit("2nd commit", Constants.Signature, Constants.Signature);
335335

336336
// Checkout branch2
@@ -453,23 +453,23 @@ public void CheckingOutCallsCheckoutNotify(CheckoutNotifyFlags notifyFlags, stri
453453

454454
const string relativePathUpdated = "updated.txt";
455455
Touch(repo.Info.WorkingDirectory, relativePathUpdated, "updated file text A");
456-
repo.Stage(relativePathUpdated);
456+
Commands.Stage(repo, relativePathUpdated);
457457
repo.Commit("Commit initial update file", Constants.Signature, Constants.Signature);
458458

459459
// Create conflicting change
460460
const string relativePathConflict = "conflict.txt";
461461
Touch(repo.Info.WorkingDirectory, relativePathConflict, "conflict file text A");
462-
repo.Stage(relativePathConflict);
462+
Commands.Stage(repo, relativePathConflict);
463463
repo.Commit("Initial commit of conflict.txt and update.txt", Constants.Signature, Constants.Signature);
464464

465465
// Create another branch
466466
repo.CreateBranch("newbranch");
467467

468468
// Make an edit to conflict.txt and update.txt
469469
Touch(repo.Info.WorkingDirectory, relativePathUpdated, "updated file text BB");
470-
repo.Stage(relativePathUpdated);
470+
Commands.Stage(repo, relativePathUpdated);
471471
Touch(repo.Info.WorkingDirectory, relativePathConflict, "conflict file text BB");
472-
repo.Stage(relativePathConflict);
472+
Commands.Stage(repo, relativePathConflict);
473473

474474
repo.Commit("2nd commit of conflict.txt and update.txt on master branch", Constants.Signature, Constants.Signature);
475475

@@ -478,14 +478,14 @@ public void CheckingOutCallsCheckoutNotify(CheckoutNotifyFlags notifyFlags, stri
478478

479479
// Make alternate edits to conflict.txt and update.txt
480480
Touch(repo.Info.WorkingDirectory, relativePathUpdated, "updated file text CCC");
481-
repo.Stage(relativePathUpdated);
481+
Commands.Stage(repo, relativePathUpdated);
482482
Touch(repo.Info.WorkingDirectory, relativePathConflict, "conflict file text CCC");
483-
repo.Stage(relativePathConflict);
483+
Commands.Stage(repo, relativePathConflict);
484484
repo.Commit("2nd commit of conflict.txt and update.txt on newbranch", Constants.Signature, Constants.Signature);
485485

486486
// make conflicting change to conflict.txt
487487
Touch(repo.Info.WorkingDirectory, relativePathConflict, "conflict file text DDDD");
488-
repo.Stage(relativePathConflict);
488+
Commands.Stage(repo, relativePathConflict);
489489

490490
// Create ignored change
491491
string relativePathIgnore = Path.Combine("bin", "ignored.txt");
@@ -596,7 +596,7 @@ public void CheckoutRetainsStagedChanges()
596596

597597
// Generate a staged change.
598598
string fullPathFileA = Touch(repo.Info.WorkingDirectory, originalFilePath, alternateFileContent);
599-
repo.Stage(fullPathFileA);
599+
Commands.Stage(repo, fullPathFileA);
600600

601601
// Verify that there is a staged entry.
602602
Assert.Equal(1, repo.RetrieveStatus().Staged.Count());
@@ -680,7 +680,7 @@ public void CheckoutBranchSnapshot()
680680

681681
// Add commit to master
682682
string fullPath = Touch(repo.Info.WorkingDirectory, originalFilePath, "Update : hello from master branch!\n");
683-
repo.Stage(fullPath);
683+
Commands.Stage(repo, fullPath);
684684
repo.Commit("2nd commit", Constants.Signature, Constants.Signature);
685685

686686
Assert.False(repo.Info.IsHeadDetached);
@@ -1038,10 +1038,10 @@ private void PopulateBasicRepository(IRepository repo)
10381038
{
10391039
// Generate a .gitignore file.
10401040
string gitIgnoreFilePath = Touch(repo.Info.WorkingDirectory, ".gitignore", "bin");
1041-
repo.Stage(gitIgnoreFilePath);
1041+
Commands.Stage(repo, gitIgnoreFilePath);
10421042

10431043
string fullPathFileA = Touch(repo.Info.WorkingDirectory, originalFilePath, originalFileContent);
1044-
repo.Stage(fullPathFileA);
1044+
Commands.Stage(repo, fullPathFileA);
10451045

10461046
repo.Commit("Initial commit", Constants.Signature, Constants.Signature);
10471047

LibGit2Sharp.Tests/CherryPickFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ private Commit AddFileCommitToRepo(IRepository repository, string filename, stri
130130
{
131131
Touch(repository.Info.WorkingDirectory, filename, content);
132132

133-
repository.Stage(filename);
133+
Commands.Stage(repository, filename);
134134

135135
return repository.Commit("New commit", Constants.Signature, Constants.Signature);
136136
}

LibGit2Sharp.Tests/CommitFixture.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -552,10 +552,10 @@ public void CanCommitWithSignatureFromConfig()
552552

553553
const string relativeFilepath = "new.txt";
554554
string filePath = Touch(repo.Info.WorkingDirectory, relativeFilepath, "null");
555-
repo.Stage(relativeFilepath);
555+
Commands.Stage(repo, relativeFilepath);
556556

557557
File.AppendAllText(filePath, "token\n");
558-
repo.Stage(relativeFilepath);
558+
Commands.Stage(repo, relativeFilepath);
559559

560560
Assert.Null(repo.Head[relativeFilepath]);
561561

@@ -614,7 +614,7 @@ public void CommitCleansUpMergeMetadata()
614614

615615
const string relativeFilepath = "new.txt";
616616
Touch(repo.Info.WorkingDirectory, relativeFilepath, "this is a new file");
617-
repo.Stage(relativeFilepath);
617+
Commands.Stage(repo, relativeFilepath);
618618

619619
string mergeHeadPath = Touch(repo.Info.Path, "MERGE_HEAD", "abcdefabcdefabcdefabcdefabcdefabcdefabcd");
620620
string mergeMsgPath = Touch(repo.Info.Path, "MERGE_MSG", "This is a dummy merge.\n");
@@ -651,9 +651,9 @@ public void CanCommitALittleBit()
651651

652652
const string relativeFilepath = "new.txt";
653653
string filePath = Touch(repo.Info.WorkingDirectory, relativeFilepath, "null");
654-
repo.Stage(relativeFilepath);
654+
Commands.Stage(repo, relativeFilepath);
655655
File.AppendAllText(filePath, "token\n");
656-
repo.Stage(relativeFilepath);
656+
Commands.Stage(repo, relativeFilepath);
657657

658658
Assert.Null(repo.Head[relativeFilepath]);
659659

@@ -692,7 +692,7 @@ public void CanCommitALittleBit()
692692
Assert.Equal(commit.Id, repo.Refs.Log(targetCanonicalName).First().To);
693693

694694
File.WriteAllText(filePath, "nulltoken commits!\n");
695-
repo.Stage(relativeFilepath);
695+
Commands.Stage(repo, relativeFilepath);
696696

697697
var author2 = new Signature(author.Name, author.Email, author.When.AddSeconds(5));
698698
Commit commit2 = repo.Commit("Are you trying to fork me?", author2, author2);
@@ -713,7 +713,7 @@ public void CanCommitALittleBit()
713713
File.WriteAllText(filePath, "davidfowl commits!\n");
714714

715715
var author3 = new Signature("David Fowler", "[email protected]", author.When.AddSeconds(2));
716-
repo.Stage(relativeFilepath);
716+
Commands.Stage(repo, relativeFilepath);
717717

718718
Commit commit3 = repo.Commit("I'm going to branch you backwards in time!", author3, author3);
719719

@@ -739,7 +739,7 @@ private static void AddCommitToRepo(string path)
739739
{
740740
const string relativeFilepath = "test.txt";
741741
Touch(repo.Info.WorkingDirectory, relativeFilepath, "test\n");
742-
repo.Stage(relativeFilepath);
742+
Commands.Stage(repo, relativeFilepath);
743743

744744
var author = new Signature("nulltoken", "[email protected]", DateTimeOffset.Parse("Wed, Dec 14 2011 08:29:03 +0100"));
745745
repo.Commit("Initial commit", author, author);
@@ -825,7 +825,7 @@ private static void CreateAndStageANewFile(IRepository repo)
825825
{
826826
string relativeFilepath = string.Format("new-file-{0}.txt", Path.GetRandomFileName());
827827
Touch(repo.Info.WorkingDirectory, relativeFilepath, "brand new content\n");
828-
repo.Stage(relativeFilepath);
828+
Commands.Stage(repo, relativeFilepath);
829829
}
830830

831831
private static void AssertCommitHasBeenAmended(IRepository repo, Commit amendedCommit, Commit originalCommit)
@@ -914,7 +914,7 @@ public void CanCommitOnOrphanedBranch()
914914

915915
const string relativeFilepath = "test.txt";
916916
Touch(repo.Info.WorkingDirectory, relativeFilepath, "test\n");
917-
repo.Stage(relativeFilepath);
917+
Commands.Stage(repo, relativeFilepath);
918918

919919
repo.Commit("Initial commit", Constants.Signature, Constants.Signature);
920920
Assert.Equal(1, repo.Head.Commits.Count());
@@ -1030,16 +1030,16 @@ public void CanNotAmendACommitInAWayThatWouldLeadTheNewCommitToBecomeEmpty()
10301030
using (var repo = new Repository(repoPath))
10311031
{
10321032
Touch(repo.Info.WorkingDirectory, "test.txt", "test\n");
1033-
repo.Stage("test.txt");
1033+
Commands.Stage(repo, "test.txt");
10341034

10351035
repo.Commit("Initial commit", Constants.Signature, Constants.Signature);
10361036

10371037
Touch(repo.Info.WorkingDirectory, "new.txt", "content\n");
1038-
repo.Stage("new.txt");
1038+
Commands.Stage(repo, "new.txt");
10391039

10401040
repo.Commit("One commit", Constants.Signature, Constants.Signature);
10411041

1042-
repo.Remove("new.txt");
1042+
Commands.Remove(repo, "new.txt");
10431043

10441044
Assert.Throws<EmptyCommitException>(() => repo.Commit("Oops", Constants.Signature, Constants.Signature,
10451045
new CommitOptions { AmendPreviousCommit = true }));

LibGit2Sharp.Tests/ConflictFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public void CanResolveConflictsByRemovingFromTheIndex(
7777
Assert.NotNull(repo.Index.Conflicts[filename]);
7878
Assert.Equal(0, repo.Index.Conflicts.ResolvedConflicts.Count());
7979

80-
repo.Remove(filename, removeFromWorkdir);
80+
Commands.Remove(repo, filename, removeFromWorkdir);
8181

8282
Assert.Null(repo.Index.Conflicts[filename]);
8383
Assert.Equal(count - removedIndexEntries, repo.Index.Count);

LibGit2Sharp.Tests/DiffTreeToTargetFixture.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ private static void SetUpSimpleDiffContext(IRepository repo)
1212
{
1313
var fullpath = Touch(repo.Info.WorkingDirectory, "file.txt", "hello\n");
1414

15-
repo.Stage(fullpath);
15+
Commands.Stage(repo, fullpath);
1616
repo.Commit("Initial commit", Constants.Signature, Constants.Signature);
1717

1818
File.AppendAllText(fullpath, "world\n");
1919

20-
repo.Stage(fullpath);
20+
Commands.Stage(repo,fullpath);
2121

2222
File.AppendAllText(fullpath, "!!!\n");
2323
}
@@ -159,7 +159,7 @@ public void ShowcaseTheDifferenceBetweenTheTwoKindOfComparison()
159159

160160
var fullpath = Path.Combine(repo.Info.WorkingDirectory, "file.txt");
161161
File.Move(fullpath, fullpath + ".bak");
162-
repo.Stage(fullpath);
162+
Commands.Stage(repo, fullpath);
163163
File.Move(fullpath + ".bak", fullpath);
164164

165165
FileStatus state = repo.RetrieveStatus("file.txt");
@@ -378,11 +378,11 @@ public void CanCopeWithEndOfFileNewlineChanges()
378378
{
379379
var fullpath = Touch(repo.Info.WorkingDirectory, "file.txt", "a");
380380

381-
repo.Stage("file.txt");
381+
Commands.Stage(repo, "file.txt");
382382
repo.Commit("Add file without line ending", Constants.Signature, Constants.Signature);
383383

384384
File.AppendAllText(fullpath, "\n");
385-
repo.Stage("file.txt");
385+
Commands.Stage(repo, "file.txt");
386386

387387
var changes = repo.Diff.Compare<TreeChanges>(repo.Head.Tip.Tree, DiffTargets.Index);
388388
Assert.Equal(1, changes.Modified.Count());

0 commit comments

Comments
 (0)