public void ShouldReturnUnreachableCommitHashesAfterRewind() { using (var tempFolder = new TemporaryFolder()) { var tempRepository = new TemporaryRepository(tempFolder); var executor = new GitCommandExecutor(tempFolder.Path); var log = new LogRetriever(executor); tempRepository.RunCommand("init"); tempRepository.TouchFileAndCommit(); var firstCommitHash = log.GetRecentCommits(1).Single().Hash; tempRepository.TouchFileAndCommit(); var secondCommitHash = log.GetRecentCommits(1).Single().Hash; tempRepository.RunCommand("reset --hard " + firstCommitHash); var orphanedHashes = log.GetRecentUnreachableCommitHashes(); CollectionAssert.AreEqual(new[] { secondCommitHash }, orphanedHashes); } }
public void ShouldReturnSameDataForSpecificCommitsAsWhenRetrievedViaRecentCommits() { using (var tempFolder = new TemporaryFolder()) { var tempRepository = new TemporaryRepository(tempFolder); tempRepository.RunCommand("init"); tempRepository.TouchFileAndCommit(); tempRepository.TouchFileAndCommit(); var executor = new GitCommandExecutor(tempFolder.Path); var logRetriever = new LogRetriever(executor); var recentCommits = logRetriever.GetRecentCommits().ToArray(); var recentCommitHashes = recentCommits.Select(c => c.Hash); var specificCommits = logRetriever.GetSpecificCommits(recentCommitHashes); CollectionAssert.AreEqual(recentCommits, specificCommits, new SerializedObjectComparer()); } }
public void ShouldLimitNumberOfUnreachableCommitHashesRetrieved() { using (var tempFolder = new TemporaryFolder()) { var tempRepository = new TemporaryRepository(tempFolder); var executor = new GitCommandExecutor(tempFolder.Path); var log = new LogRetriever(executor); tempRepository.RunCommand("init"); tempRepository.TouchFileAndCommit(); var firstCommitHash = log.GetRecentCommits(1).Single().Hash; for (var i = 0; i < 20; i++) { tempRepository.TouchFileAndCommit(); } tempRepository.RunCommand("reset --hard " + firstCommitHash); var orphanedHashes = log.GetRecentUnreachableCommitHashes(10); Assert.AreEqual(10, orphanedHashes.Count()); } }