Skip to content

Move Stage and Remove to commands #1291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LibGit2Sharp.Tests/AttributesFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private static void AssertNormalization(IRepository repo, string filename, bool

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

repo.Stage(filename);
Commands.Stage(repo, filename);

IndexEntry entry = repo.Index[filename];
Assert.NotNull(entry);
Expand Down
6 changes: 3 additions & 3 deletions LibGit2Sharp.Tests/BlobFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void CanGetBlobAsTextWithVariousEncodings(string encodingName, int expect
var bomPath = Touch(repo.Info.WorkingDirectory, bomFile, content, encoding);
Assert.Equal(expectedContentBytes, File.ReadAllBytes(bomPath).Length);

repo.Stage(bomFile);
Commands.Stage(repo, bomFile);
var commit = repo.Commit("bom", Constants.Signature, Constants.Signature);

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

repo.Stage("small.txt");
Commands.Stage(repo, "small.txt");
IndexEntry entry = repo.Index["small.txt"];
Assert.Equal("baae1fb3760a73481ced1fa03dc15614142c19ef", entry.Id.Sha);

Expand All @@ -202,7 +202,7 @@ public void CanStageAFileGeneratedFromABlobContentStream()
CopyStream(stream, file);
}

repo.Stage("small.fromblob.txt");
Commands.Stage(repo, "small.fromblob.txt");
IndexEntry newentry = repo.Index["small.fromblob.txt"];

Assert.Equal("baae1fb3760a73481ced1fa03dc15614142c19ef", newentry.Id.Sha);
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp.Tests/BranchFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ public void TrackedBranchExistsFromDefaultConfigInEmptyClone()
Assert.Equal("origin", repo.Head.RemoteName);

Touch(repo.Info.WorkingDirectory, "a.txt", "a");
repo.Stage("a.txt");
Commands.Stage(repo, "a.txt");
repo.Commit("A file", Constants.Signature, Constants.Signature);

Assert.NotNull(repo.Head.Tip);
Expand Down
42 changes: 21 additions & 21 deletions LibGit2Sharp.Tests/CheckoutFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public void CheckoutAddsMissingFilesInWorkingDirectory()
// Remove the file in master branch
// Verify it exists after checking out otherBranch.
string fileFullPath = Path.Combine(repo.Info.WorkingDirectory, originalFilePath);
repo.Remove(fileFullPath);
Commands.Remove(repo, fileFullPath);
repo.Commit("2nd commit", Constants.Signature, Constants.Signature);

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

repo.Stage(newFileFullPath);
Commands.Stage(repo, newFileFullPath);
repo.Commit("2nd commit", Constants.Signature, Constants.Signature);

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

repo.Stage(fullPath);
Commands.Stage(repo, fullPath);
repo.Commit("2nd commit", Constants.Signature, Constants.Signature);

// Checkout other_branch
Expand Down Expand Up @@ -254,15 +254,15 @@ public void CanForcefullyCheckoutWithConflictingStagedChanges()
// Add change to master.
Touch(repo.Info.WorkingDirectory, originalFilePath, originalFileContent);

repo.Stage(originalFilePath);
Commands.Stage(repo, originalFilePath);
repo.Commit("change in master", Constants.Signature, Constants.Signature);

// Checkout otherBranch.
repo.Checkout(otherBranchName);

// Add change to otherBranch.
Touch(repo.Info.WorkingDirectory, originalFilePath, alternateFileContent);
repo.Stage(originalFilePath);
Commands.Stage(repo, originalFilePath);

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

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

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

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

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

repo.Stage(relativePath);
Commands.Stage(repo, relativePath);
repo.Commit("Initial commit", Constants.Signature, Constants.Signature);

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

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

// Checkout branch2
Expand Down Expand Up @@ -453,23 +453,23 @@ public void CheckingOutCallsCheckoutNotify(CheckoutNotifyFlags notifyFlags, stri

const string relativePathUpdated = "updated.txt";
Touch(repo.Info.WorkingDirectory, relativePathUpdated, "updated file text A");
repo.Stage(relativePathUpdated);
Commands.Stage(repo, relativePathUpdated);
repo.Commit("Commit initial update file", Constants.Signature, Constants.Signature);

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

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

// Make an edit to conflict.txt and update.txt
Touch(repo.Info.WorkingDirectory, relativePathUpdated, "updated file text BB");
repo.Stage(relativePathUpdated);
Commands.Stage(repo, relativePathUpdated);
Touch(repo.Info.WorkingDirectory, relativePathConflict, "conflict file text BB");
repo.Stage(relativePathConflict);
Commands.Stage(repo, relativePathConflict);

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

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

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

// make conflicting change to conflict.txt
Touch(repo.Info.WorkingDirectory, relativePathConflict, "conflict file text DDDD");
repo.Stage(relativePathConflict);
Commands.Stage(repo, relativePathConflict);

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

// Generate a staged change.
string fullPathFileA = Touch(repo.Info.WorkingDirectory, originalFilePath, alternateFileContent);
repo.Stage(fullPathFileA);
Commands.Stage(repo, fullPathFileA);

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

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

Assert.False(repo.Info.IsHeadDetached);
Expand Down Expand Up @@ -1038,10 +1038,10 @@ private void PopulateBasicRepository(IRepository repo)
{
// Generate a .gitignore file.
string gitIgnoreFilePath = Touch(repo.Info.WorkingDirectory, ".gitignore", "bin");
repo.Stage(gitIgnoreFilePath);
Commands.Stage(repo, gitIgnoreFilePath);

string fullPathFileA = Touch(repo.Info.WorkingDirectory, originalFilePath, originalFileContent);
repo.Stage(fullPathFileA);
Commands.Stage(repo, fullPathFileA);

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

Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp.Tests/CherryPickFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private Commit AddFileCommitToRepo(IRepository repository, string filename, stri
{
Touch(repository.Info.WorkingDirectory, filename, content);

repository.Stage(filename);
Commands.Stage(repository, filename);

return repository.Commit("New commit", Constants.Signature, Constants.Signature);
}
Expand Down
26 changes: 13 additions & 13 deletions LibGit2Sharp.Tests/CommitFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -552,10 +552,10 @@ public void CanCommitWithSignatureFromConfig()

const string relativeFilepath = "new.txt";
string filePath = Touch(repo.Info.WorkingDirectory, relativeFilepath, "null");
repo.Stage(relativeFilepath);
Commands.Stage(repo, relativeFilepath);

File.AppendAllText(filePath, "token\n");
repo.Stage(relativeFilepath);
Commands.Stage(repo, relativeFilepath);

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

Expand Down Expand Up @@ -614,7 +614,7 @@ public void CommitCleansUpMergeMetadata()

const string relativeFilepath = "new.txt";
Touch(repo.Info.WorkingDirectory, relativeFilepath, "this is a new file");
repo.Stage(relativeFilepath);
Commands.Stage(repo, relativeFilepath);

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

const string relativeFilepath = "new.txt";
string filePath = Touch(repo.Info.WorkingDirectory, relativeFilepath, "null");
repo.Stage(relativeFilepath);
Commands.Stage(repo, relativeFilepath);
File.AppendAllText(filePath, "token\n");
repo.Stage(relativeFilepath);
Commands.Stage(repo, relativeFilepath);

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

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

File.WriteAllText(filePath, "nulltoken commits!\n");
repo.Stage(relativeFilepath);
Commands.Stage(repo, relativeFilepath);

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

var author3 = new Signature("David Fowler", "david.fowler@microsoft.com", author.When.AddSeconds(2));
repo.Stage(relativeFilepath);
Commands.Stage(repo, relativeFilepath);

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

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

var author = new Signature("nulltoken", "emeric.fermas@gmail.com", DateTimeOffset.Parse("Wed, Dec 14 2011 08:29:03 +0100"));
repo.Commit("Initial commit", author, author);
Expand Down Expand Up @@ -825,7 +825,7 @@ private static void CreateAndStageANewFile(IRepository repo)
{
string relativeFilepath = string.Format("new-file-{0}.txt", Path.GetRandomFileName());
Touch(repo.Info.WorkingDirectory, relativeFilepath, "brand new content\n");
repo.Stage(relativeFilepath);
Commands.Stage(repo, relativeFilepath);
}

private static void AssertCommitHasBeenAmended(IRepository repo, Commit amendedCommit, Commit originalCommit)
Expand Down Expand Up @@ -914,7 +914,7 @@ public void CanCommitOnOrphanedBranch()

const string relativeFilepath = "test.txt";
Touch(repo.Info.WorkingDirectory, relativeFilepath, "test\n");
repo.Stage(relativeFilepath);
Commands.Stage(repo, relativeFilepath);

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

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

Touch(repo.Info.WorkingDirectory, "new.txt", "content\n");
repo.Stage("new.txt");
Commands.Stage(repo, "new.txt");

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

repo.Remove("new.txt");
Commands.Remove(repo, "new.txt");

Assert.Throws<EmptyCommitException>(() => repo.Commit("Oops", Constants.Signature, Constants.Signature,
new CommitOptions { AmendPreviousCommit = true }));
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp.Tests/ConflictFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void CanResolveConflictsByRemovingFromTheIndex(
Assert.NotNull(repo.Index.Conflicts[filename]);
Assert.Equal(0, repo.Index.Conflicts.ResolvedConflicts.Count());

repo.Remove(filename, removeFromWorkdir);
Commands.Remove(repo, filename, removeFromWorkdir);

Assert.Null(repo.Index.Conflicts[filename]);
Assert.Equal(count - removedIndexEntries, repo.Index.Count);
Expand Down
10 changes: 5 additions & 5 deletions LibGit2Sharp.Tests/DiffTreeToTargetFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ private static void SetUpSimpleDiffContext(IRepository repo)
{
var fullpath = Touch(repo.Info.WorkingDirectory, "file.txt", "hello\n");

repo.Stage(fullpath);
Commands.Stage(repo, fullpath);
repo.Commit("Initial commit", Constants.Signature, Constants.Signature);

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

repo.Stage(fullpath);
Commands.Stage(repo,fullpath);

File.AppendAllText(fullpath, "!!!\n");
}
Expand Down Expand Up @@ -159,7 +159,7 @@ public void ShowcaseTheDifferenceBetweenTheTwoKindOfComparison()

var fullpath = Path.Combine(repo.Info.WorkingDirectory, "file.txt");
File.Move(fullpath, fullpath + ".bak");
repo.Stage(fullpath);
Commands.Stage(repo, fullpath);
File.Move(fullpath + ".bak", fullpath);

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

repo.Stage("file.txt");
Commands.Stage(repo, "file.txt");
repo.Commit("Add file without line ending", Constants.Signature, Constants.Signature);

File.AppendAllText(fullpath, "\n");
repo.Stage("file.txt");
Commands.Stage(repo, "file.txt");

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