Пример #1
0
        public void CanResetTheIndexWhenARenameExists()
        {
            using (var repo = new Repository(SandboxStandardTestRepo()))
            {
                repo.Move("branch_file.txt", "renamed_branch_file.txt");
                repo.Reset(repo.Lookup <Commit>("32eab9c"));

                RepositoryStatus status = repo.RetrieveStatus();
                Assert.Equal(0, status.Where(IsStaged).Count());
            }
        }
Пример #2
0
        public void CanResetTheIndexWhenARenameExists()
        {
            using (var repo = new Repository(SandboxStandardTestRepo()))
            {
                Commands.Move(repo, "branch_file.txt", "renamed_branch_file.txt");
                repo.Index.Replace(repo.Lookup <Commit>("32eab9c"));

                RepositoryStatus status = repo.RetrieveStatus();
                Assert.Empty(status.Where(IsStaged));
            }
        }
Пример #3
0
        public void ResetTheIndexWithTheHeadUnstagesEverything()
        {
            TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath);

            using (var repo = new Repository(path.DirectoryPath))
            {
                RepositoryStatus oldStatus = repo.Index.RetrieveStatus();
                Assert.Equal(3, oldStatus.Where(IsStaged).Count());

                repo.Reset();

                RepositoryStatus newStatus = repo.Index.RetrieveStatus();
                Assert.Equal(0, newStatus.Where(IsStaged).Count());
            }
        }
Пример #4
0
        public void CanResetTheIndexToTheContentOfACommitWithCommittishAsArgument()
        {
            string path = SandboxStandardTestRepo();

            using (var repo = new Repository(path))
            {
                repo.Reset("be3563a");

                RepositoryStatus newStatus = repo.RetrieveStatus();

                var expected = new[] { "1.txt", Path.Combine("1", "branch_file.txt"), "deleted_staged_file.txt",
                                       "deleted_unstaged_file.txt", "modified_staged_file.txt", "modified_unstaged_file.txt" };

                Assert.Equal(expected.Length, newStatus.Where(IsStaged).Count());
                Assert.Equal(expected, newStatus.Removed.Select(s => s.FilePath));
            }
        }
Пример #5
0
        public void CanResetTheIndexToTheContentOfACommitWithCommitAsArgument()
        {
            TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath);

            using (var repo = new Repository(path.DirectoryPath))
            {
                repo.Reset(repo.Lookup <Commit>("be3563a"));

                RepositoryStatus newStatus = repo.Index.RetrieveStatus();

                var expected = new[] { "1.txt", Path.Combine("1", "branch_file.txt"), "deleted_staged_file.txt",
                                       "deleted_unstaged_file.txt", "modified_staged_file.txt", "modified_unstaged_file.txt" };

                Assert.Equal(expected.Length, newStatus.Where(IsStaged).Count());
                Assert.Equal(expected, newStatus.Removed);
            }
        }
Пример #6
0
        public void ResetTheIndexWithTheHeadUnstagesEverything()
        {
            string path = SandboxStandardTestRepo();

            using (var repo = new Repository(path))
            {
                RepositoryStatus oldStatus = repo.RetrieveStatus();
                Assert.Equal(3, oldStatus.Where(IsStaged).Count());

                var reflogEntriesCount = repo.Refs.Log(repo.Refs.Head).Count();

                repo.Reset();

                RepositoryStatus newStatus = repo.RetrieveStatus();
                Assert.Equal(0, newStatus.Where(IsStaged).Count());

                // Assert that no reflog entry is created
                Assert.Equal(reflogEntriesCount, repo.Refs.Log(repo.Refs.Head).Count());
            }
        }
Пример #7
0
 /// <summary>
 /// Helper function to query changes in the git repo.
 /// </summary>
 /// <param name="status">The status of the repository.</param>
 /// <returns></returns>
 private IEnumerable <StatusEntry> QueryChanges(RepositoryStatus status)
 {
     return(status.Where(s => s.State != FileStatus.Ignored));
 }