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()); } }
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)); } }
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()); } }
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)); } }
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); } }
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()); } }
/// <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)); }