diff options
author | Alexandru Dima <alexdima@microsoft.com> | 2014-09-01 21:29:48 +0400 |
---|---|---|
committer | Alexandru Dima <alexdima@microsoft.com> | 2014-09-01 21:35:07 +0400 |
commit | 92b0e4e18bf496e73a0b83355ce1745b13b51ae5 (patch) | |
tree | 2f667b0c977fe94cdefb3bb0c5205b4fa8382cbc /LibGit2Sharp.Tests | |
parent | 8d8fbb1198d566e3e922a24808594b40b6dd75b6 (diff) |
Introduce low level Index/Tree operations
Diffstat (limited to 'LibGit2Sharp.Tests')
-rw-r--r-- | LibGit2Sharp.Tests/IndexFixture.cs | 62 | ||||
-rw-r--r-- | LibGit2Sharp.Tests/ObjectDatabaseFixture.cs | 34 |
2 files changed, 96 insertions, 0 deletions
diff --git a/LibGit2Sharp.Tests/IndexFixture.cs b/LibGit2Sharp.Tests/IndexFixture.cs index f6c1690a..1b401bc7 100644 --- a/LibGit2Sharp.Tests/IndexFixture.cs +++ b/LibGit2Sharp.Tests/IndexFixture.cs @@ -278,5 +278,67 @@ namespace LibGit2Sharp.Tests Assert.Equal(2, repoRead.Index.Count); } } + + [Fact] + public void CanResetFullyMergedIndexFromTree() + { + string path = CloneStandardTestRepo(); + + const string testFile = "new_tracked_file.txt"; + + // It is sufficient to check just one of the stage area changes, such as the added file, + // to verify that the index has indeed been read from the tree. + using (var repo = new Repository(path)) + { + const string headIndexTreeSha = "e5d221fc5da11a3169bf503d76497c81be3207b6"; + + Assert.True(repo.Index.IsFullyMerged); + Assert.Equal(FileStatus.Added, repo.Index.RetrieveStatus(testFile)); + + var headIndexTree = repo.Lookup<Tree>(headIndexTreeSha); + Assert.NotNull(headIndexTree); + repo.Index.Reset(headIndexTree); + + Assert.True(repo.Index.IsFullyMerged); + Assert.Equal(FileStatus.Untracked, repo.Index.RetrieveStatus(testFile)); + } + + // Check that the index was persisted to disk. + using (var repo = new Repository(path)) + { + Assert.Equal(FileStatus.Untracked, repo.Index.RetrieveStatus(testFile)); + } + } + + [Fact] + public void CanResetIndexWithUnmergedEntriesFromTree() + { + string path = CloneMergedTestRepo(); + + const string testFile = "one.txt"; + + // It is sufficient to check just one of the stage area changes, such as the modified file, + // to verify that the index has indeed been read from the tree. + using (var repo = new Repository(path)) + { + const string headIndexTreeSha = "1cb365141a52dfbb24933515820eb3045fbca12b"; + + Assert.False(repo.Index.IsFullyMerged); + Assert.Equal(FileStatus.Staged, repo.Index.RetrieveStatus(testFile)); + + var headIndexTree = repo.Lookup<Tree>(headIndexTreeSha); + Assert.NotNull(headIndexTree); + repo.Index.Reset(headIndexTree); + + Assert.True(repo.Index.IsFullyMerged); + Assert.Equal(FileStatus.Modified, repo.Index.RetrieveStatus(testFile)); + } + + // Check that the index was persisted to disk. + using (var repo = new Repository(path)) + { + Assert.Equal(FileStatus.Modified, repo.Index.RetrieveStatus(testFile)); + } + } } } diff --git a/LibGit2Sharp.Tests/ObjectDatabaseFixture.cs b/LibGit2Sharp.Tests/ObjectDatabaseFixture.cs index c6e724c1..622891aa 100644 --- a/LibGit2Sharp.Tests/ObjectDatabaseFixture.cs +++ b/LibGit2Sharp.Tests/ObjectDatabaseFixture.cs @@ -361,6 +361,40 @@ namespace LibGit2Sharp.Tests } [Fact] + public void CreatingATreeFromIndexWithUnmergedEntriesThrows() + { + using (var repo = new Repository(MergedTestRepoWorkingDirPath)) + { + Assert.False(repo.Index.IsFullyMerged); + + Assert.Throws<UnmergedIndexEntriesException>( + () => repo.ObjectDatabase.CreateTree(repo.Index)); + } + } + + [Fact] + public void CanCreateATreeFromIndex() + { + string path = CloneStandardTestRepo(); + + using (var repo = new Repository(path)) + { + const string expectedIndexTreeSha = "0fe0fd1943a1b63ecca36fa6bbe9bbe045f791a4"; + + // The tree representing the index is not in the db. + Assert.Null(repo.Lookup(expectedIndexTreeSha)); + + var tree = repo.ObjectDatabase.CreateTree(repo.Index); + Assert.NotNull(tree); + Assert.Equal(expectedIndexTreeSha, tree.Id.Sha); + + // The tree representing the index is now in the db. + tree = repo.Lookup<Tree>(expectedIndexTreeSha); + Assert.NotNull(tree); + } + } + + [Fact] public void CanCreateACommit() { string path = CloneBareTestRepo(); |