コード例 #1
0
 public void ShouldThrowExceptionForFatalError()
 {
     using (var repo = new TemporaryFolder())
     {
         var executor = new GitCommandExecutor(repo.Path);
         Assert.Throws<ApplicationException>(() => executor.Execute("bad command"));
     }
 }
コード例 #2
0
ファイル: LogRetriever.cs プロジェクト: JakeGinnivan/GitViz
 public LogRetriever(
     GitCommandExecutor executor,
     LogParser logParser = null,
     FsckParser fsckParser = null)
 {
     _executor = executor;
     _logParser = logParser ?? new LogParser();
     _fsckParser = fsckParser ?? new FsckParser();
 }
コード例 #3
0
ファイル: LogRetriever.cs プロジェクト: Jan-Thes/GitViz
 public LogRetriever(
     GitCommandExecutor executor,
     LogParser logParser   = null,
     FsckParser fsckParser = null)
 {
     _executor   = executor;
     _logParser  = logParser ?? new LogParser();
     _fsckParser = fsckParser ?? new FsckParser();
 }
コード例 #4
0
        public void ShouldGitInit()
        {
            using (var repo = new TemporaryFolder())
            {
                var executor = new GitCommandExecutor(repo.Path);
                executor.Execute("init");

                var expectedGitFolderPath = Path.Combine(repo.Path, ".git");
                Assert.IsTrue(Directory.Exists(expectedGitFolderPath));
            }
        }
コード例 #5
0
        public void ShouldLimitNumberOfRecentCommitsRetrieved()
        {
            using (var tempFolder = new TemporaryFolder())
            {
                var tempRepository = new TemporaryRepository(tempFolder);
                tempRepository.RunCommand("init");
                for (var i = 0; i < 20; i ++)
                    tempRepository.TouchFileAndCommit();

                var executor = new GitCommandExecutor(tempFolder.Path);
                var log = new LogRetriever(executor).GetRecentCommits(10).ToArray();

                Assert.AreEqual(10, log.Length);
            }
        }
コード例 #6
0
        public void ShouldReturnMostRecentCommitFirst()
        {
            using (var tempFolder = new TemporaryFolder())
            {
                var tempRepository = new TemporaryRepository(tempFolder);
                tempRepository.RunCommand("init");
                tempRepository.TouchFileAndCommit();
                tempRepository.TouchFileAndCommit();

                var executor = new GitCommandExecutor(tempFolder.Path);
                var log = new LogRetriever(executor).GetRecentCommits().ToArray();

                var firstCommitReturned = log.ElementAt(0);
                var secondCommitReturned = log.ElementAt(1);

                CollectionAssert.AreEqual(new[] { secondCommitReturned.Hash }, firstCommitReturned.ParentHashes);
            }
        }
コード例 #7
0
        public void ShouldReturnMultipleUnreachableCommitHashesAfterRewind()
        {
            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 < 10; i++)
                    tempRepository.TouchFileAndCommit();

                tempRepository.RunCommand("reset --hard " + firstCommitHash);

                var orphanedHashes = log.GetRecentUnreachableCommitHashes(100);
                Assert.AreEqual(10, orphanedHashes.Count());
            }
        }
コード例 #8
0
        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());
            }
        }
コード例 #9
0
        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);
            }
        }
コード例 #10
0
        public void ShouldReturnTwoRecentCommits()
        {
            using (var tempFolder = new TemporaryFolder())
            {
                var tempRepository = new TemporaryRepository(tempFolder);
                tempRepository.RunCommand("init");
                tempRepository.TouchFileAndCommit();
                tempRepository.TouchFileAndCommit();

                var executor = new GitCommandExecutor(tempFolder.Path);
                var log = new LogRetriever(executor).GetRecentCommits().ToArray();

                Assert.AreEqual(2, log.Length);

                var commit = log.ElementAt(0);
                Assert.IsNotNullOrEmpty(commit.Hash);
                Assert.AreEqual(40, commit.Hash.Length);
                CollectionAssert.AreEqual(new[] { log.ElementAt(1).Hash }, commit.ParentHashes);

                commit = log.ElementAt(1);
                Assert.IsNotNullOrEmpty(commit.Hash);
                Assert.AreEqual(40, commit.Hash.Length);
                Assert.IsNull(commit.ParentHashes);
            }
        }
コード例 #11
0
        public void ShouldReturnSingleRecentCommitWithLocalRefs()
        {
            using (var tempFolder = new TemporaryFolder())
            {
                var tempRepository = new TemporaryRepository(tempFolder);
                tempRepository.RunCommand("init");
                tempRepository.TouchFileAndCommit();

                var executor = new GitCommandExecutor(tempFolder.Path);
                var log = new LogRetriever(executor).GetRecentCommits().ToArray();

                var commit = log.Single();
                CollectionAssert.AreEqual(new[] { "HEAD", "master" }, commit.Refs);
            }
        }
コード例 #12
0
        public void ShouldReturnSingleRecentCommitWithHashButNoParents()
        {
            using (var tempFolder = new TemporaryFolder())
            {
                var tempRepository = new TemporaryRepository(tempFolder);
                tempRepository.RunCommand("init");
                tempRepository.TouchFileAndCommit();

                var executor = new GitCommandExecutor(tempFolder.Path);
                var log = new LogRetriever(executor).GetRecentCommits().ToArray();

                Assert.AreEqual(1, log.Length);

                var commit = log.Single();
                Assert.IsNotNullOrEmpty(commit.Hash);
                Assert.AreEqual(40, commit.Hash.Length);
                Assert.IsNull(commit.ParentHashes);
            }
        }
コード例 #13
0
        public void ShouldReturnSingleRecentCommit()
        {
            using (var tempFolder = new TemporaryFolder())
            {
                var tempRepository = new TemporaryRepository(tempFolder);
                tempRepository.RunCommand("init");
                tempRepository.TouchFileAndCommit();

                var executor = new GitCommandExecutor(tempFolder.Path);
                var log = new LogRetriever(executor).GetRecentCommits().ToArray();

                Assert.AreEqual(1, log.Length);
            }
        }