当前位置: 首页>>代码示例>>C#>>正文


C# Repository.Lookup方法代码示例

本文整理汇总了C#中Repository.Lookup方法的典型用法代码示例。如果您正苦于以下问题:C# Repository.Lookup方法的具体用法?C# Repository.Lookup怎么用?C# Repository.Lookup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Repository的用法示例。


在下文中一共展示了Repository.Lookup方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CanCreateABlobIntoTheDatabaseOfABareRepository

        public void CanCreateABlobIntoTheDatabaseOfABareRepository()
        {
            TemporaryCloneOfTestRepo scd = BuildTemporaryCloneOfTestRepo();

            SelfCleaningDirectory directory = BuildSelfCleaningDirectory();

            Directory.CreateDirectory(directory.RootedDirectoryPath);
            string filepath = Path.Combine(directory.RootedDirectoryPath, "hello.txt");
            File.WriteAllText(filepath, "I'm a new file\n");

            using (var repo = new Repository(scd.RepositoryPath))
            {
                /*
                 * $ echo "I'm a new file" | git hash-object --stdin
                 * dc53d4c6b8684c21b0b57db29da4a2afea011565
                 */
                Assert.Null(repo.Lookup<Blob>("dc53d4c6b8684c21b0b57db29da4a2afea011565"));

                Blob blob = repo.ObjectDatabase.CreateBlob(filepath);

                Assert.NotNull(blob);
                Assert.Equal("dc53d4c6b8684c21b0b57db29da4a2afea011565", blob.Sha);
                Assert.Equal("I'm a new file\n", blob.ContentAsUtf8());

                var fetchedBlob = repo.Lookup<Blob>(blob.Id);
                Assert.Equal(blob, fetchedBlob);
            }
        }
开发者ID:roend83,项目名称:libgit2sharp,代码行数:28,代码来源:ObjectDatabaseFixture.cs

示例2: CanCreateABlobIntoTheDatabaseOfABareRepository

        public void CanCreateABlobIntoTheDatabaseOfABareRepository()
        {
            string path = InitNewRepository();

            SelfCleaningDirectory directory = BuildSelfCleaningDirectory();

            string filepath = Touch(directory.RootedDirectoryPath, "hello.txt", "I'm a new file\n");

            using (var repo = new Repository(path))
            {
                /*
                 * $ echo "I'm a new file" | git hash-object --stdin
                 * dc53d4c6b8684c21b0b57db29da4a2afea011565
                 */
                Assert.Null(repo.Lookup<Blob>("dc53d4c6b8684c21b0b57db29da4a2afea011565"));

                Blob blob = repo.ObjectDatabase.CreateBlob(filepath);

                Assert.NotNull(blob);
                Assert.Equal("dc53d4c6b8684c21b0b57db29da4a2afea011565", blob.Sha);
                Assert.Equal("I'm a new file\n", blob.GetContentText());

                var fetchedBlob = repo.Lookup<Blob>(blob.Id);
                Assert.Equal(blob, fetchedBlob);
            }
        }
开发者ID:AndersKroghDk,项目名称:libgit2sharp,代码行数:26,代码来源:ObjectDatabaseFixture.cs

示例3: CanAddAndRemoveStash

        public void CanAddAndRemoveStash()
        {
            string path = SandboxStandardTestRepo();
            using (var repo = new Repository(path))
            {
                var stasher = Constants.Signature;

                Assert.True(repo.RetrieveStatus().IsDirty);

                Stash stash = repo.Stashes.Add(stasher, "My very first stash", StashModifiers.IncludeUntracked);

                // Check that untracked files are deleted from working directory
                string untrackedFilename = "new_untracked_file.txt";
                Assert.False(File.Exists(Path.Combine(repo.Info.WorkingDirectory, untrackedFilename)));
                Assert.NotNull(stash.Untracked[untrackedFilename]);

                Assert.NotNull(stash);
                Assert.Equal("[email protected]{0}", stash.CanonicalName);
                Assert.Contains("My very first stash", stash.Message);

                var stashRef = repo.Refs["refs/stash"];
                Assert.Equal(stash.WorkTree.Sha, stashRef.TargetIdentifier);

                Assert.False(repo.RetrieveStatus().IsDirty);

                // Create extra file
                untrackedFilename = "stash_candidate.txt";
                Touch(repo.Info.WorkingDirectory, untrackedFilename, "Oh, I'm going to be stashed!\n");

                Stash secondStash = repo.Stashes.Add(stasher, "My second stash", StashModifiers.IncludeUntracked);

                Assert.NotNull(stash);
                Assert.Equal("[email protected]{0}", stash.CanonicalName);
                Assert.Contains("My second stash", secondStash.Message);

                Assert.Equal(2, repo.Stashes.Count());
                Assert.Equal("[email protected]{0}", repo.Stashes.First().CanonicalName);
                Assert.Equal("[email protected]{1}", repo.Stashes.Last().CanonicalName);

                Assert.NotNull(secondStash.Untracked[untrackedFilename]);

                // Stash history has been shifted
                Assert.Equal(repo.Lookup<Commit>("[email protected]{0}").Sha, secondStash.WorkTree.Sha);
                Assert.Equal(repo.Lookup<Commit>("[email protected]{1}").Sha, stash.WorkTree.Sha);

                //Remove one stash
                repo.Stashes.Remove(0);
                Assert.Equal(1, repo.Stashes.Count());
                Stash newTopStash = repo.Stashes.First();
                Assert.Equal("[email protected]{0}", newTopStash.CanonicalName);
                Assert.Equal(stash.WorkTree.Sha, newTopStash.WorkTree.Sha);

                // Stash history has been shifted
                Assert.Equal(stash.WorkTree.Sha, repo.Lookup<Commit>("stash").Sha);
                Assert.Equal(stash.WorkTree.Sha, repo.Lookup<Commit>("[email protected]{0}").Sha);
            }
        }
开发者ID:beulah444,项目名称:libgit2sharp,代码行数:57,代码来源:StashFixture.cs

示例4: CanAddAndRemoveStash

        public void CanAddAndRemoveStash()
        {
            TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath);
            using (var repo = new Repository(path.RepositoryPath))
            {
                var stasher = DummySignature;

                Assert.True(repo.Index.RetrieveStatus().IsDirty);

                Stash stash = repo.Stashes.Add(stasher, "My very first stash", StashOptions.IncludeUntracked);

                // Check that untracked files are deleted from working directory
                Assert.False(File.Exists(Path.Combine(repo.Info.WorkingDirectory, "new_untracked_file.txt")));

                Assert.NotNull(stash);
                Assert.Equal("[email protected]{0}", stash.CanonicalName);
                Assert.Contains("My very first stash", stash.Message);

                var stashRef = repo.Refs["refs/stash"];
                Assert.Equal(stash.Target.Sha, stashRef.TargetIdentifier);

                Assert.False(repo.Index.RetrieveStatus().IsDirty);

                // Create extra file
                string newFileFullPath = Path.Combine(repo.Info.WorkingDirectory, "stash_candidate.txt");
                File.WriteAllText(newFileFullPath, "Oh, I'm going to be stashed!\n");

                Stash secondStash = repo.Stashes.Add(stasher, "My second stash", StashOptions.IncludeUntracked);

                Assert.NotNull(stash);
                Assert.Equal("[email protected]{0}", stash.CanonicalName);
                Assert.Contains("My second stash", secondStash.Message);

                Assert.Equal(2, repo.Stashes.Count());
                Assert.Equal("[email protected]{0}", repo.Stashes.First().CanonicalName);
                Assert.Equal("[email protected]{1}", repo.Stashes.Last().CanonicalName);

                // Stash history has been shifted
                Assert.Equal(repo.Lookup<Commit>("[email protected]{0}").Sha, secondStash.Target.Sha);
                Assert.Equal(repo.Lookup<Commit>("[email protected]{1}").Sha, stash.Target.Sha);

                //Remove one stash
                repo.Stashes.Remove("[email protected]{0}");
                Assert.Equal(1, repo.Stashes.Count());
                Stash newTopStash = repo.Stashes.First();
                Assert.Equal("[email protected]{0}", newTopStash.CanonicalName);
                Assert.Equal(stash.Target.Sha, newTopStash.Target.Sha);

                // Stash history has been shifted
                Assert.Equal(stash.Target.Sha, repo.Lookup<Commit>("stash").Sha);
                Assert.Equal(stash.Target.Sha, repo.Lookup<Commit>("[email protected]{0}").Sha);
            }
        }
开发者ID:KindDragon,项目名称:libgit2sharp,代码行数:53,代码来源:StashFixture.cs

示例5: CanFindCommonAncestorForTwoCommitsAsEnumerable

        public void CanFindCommonAncestorForTwoCommitsAsEnumerable()
        {
            using (var repo = new Repository(BareTestRepoPath))
            {
                var first = repo.Lookup<Commit>("c47800c7266a2be04c571c04d5a6614691ea99bd");
                var second = repo.Lookup<Commit>("9fd738e8f7967c078dceed8190330fc8648ee56a");

                Commit ancestor = repo.Commits.FindCommonAncestor(new[] { first, second });

                Assert.NotNull(ancestor);
                ancestor.Id.Sha.ShouldEqual("5b5b025afb0b4c913b4c338a42934a3863bf3644");
            }
        }
开发者ID:kcomkar,项目名称:libgit2sharp,代码行数:13,代码来源:CommitAncestorFixture.cs

示例6: CanFindCommonAncestorForSeveralCommits

        public void CanFindCommonAncestorForSeveralCommits()
        {
            using (var repo = new Repository(BareTestRepoPath))
            {
                var first = repo.Lookup<Commit>("4c062a6361ae6959e06292c1fa5e2822d9c96345");
                var second = repo.Lookup<Commit>("be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
                var third = repo.Lookup<Commit>("c47800c7266a2be04c571c04d5a6614691ea99bd");
                var fourth = repo.Lookup<Commit>("5b5b025afb0b4c913b4c338a42934a3863bf3644");

                Commit ancestor = repo.Commits.FindCommonAncestor(new[] { first, second, third, fourth });

                Assert.NotNull(ancestor);
                ancestor.Id.Sha.ShouldEqual("5b5b025afb0b4c913b4c338a42934a3863bf3644");
            }
        }
开发者ID:kcomkar,项目名称:libgit2sharp,代码行数:15,代码来源:CommitAncestorFixture.cs

示例7: CanCalculateHistoryDivergenceWhenNoAncestorIsShared

        public void CanCalculateHistoryDivergenceWhenNoAncestorIsShared(
            string sinceSha, string untilSha,
            int? expectedAheadBy, int? expectedBehindBy)
        {
            using (var repo = new Repository(BareTestRepoPath))
            {
                var since = repo.Lookup<Commit>(sinceSha);
                var until = repo.Lookup<Commit>(untilSha);

                HistoryDivergence div = repo.ObjectDatabase.CalculateHistoryDivergence(since, until);

                Assert.Equal(expectedAheadBy, div.AheadBy);
                Assert.Equal(expectedBehindBy, div.BehindBy);
                Assert.Null(div.CommonAncestor);
            }
        }
开发者ID:kgybels,项目名称:libgit2sharp,代码行数:16,代码来源:ObjectDatabaseFixture.cs

示例8: HardResetUpdatesTheContentOfTheWorkingDirectory

        public void HardResetUpdatesTheContentOfTheWorkingDirectory()
        {
            bool progressCalled = false;

            string path = SandboxStandardTestRepo();
            using (var repo = new Repository(path))
            {
                var names = new DirectoryInfo(repo.Info.WorkingDirectory).GetFileSystemInfos().Select(fsi => fsi.Name).ToList();

                File.Delete(Path.Combine(repo.Info.WorkingDirectory, "README"));
                Touch(repo.Info.WorkingDirectory, "WillNotBeRemoved.txt", "content\n");

                Assert.True(names.Count > 4);

                var commit = repo.Lookup<Commit>("HEAD~3");
                repo.Reset(ResetMode.Hard, commit, new CheckoutOptions()
                {
                    OnCheckoutProgress = (_path, _completed, _total) => { progressCalled = true; },
                });

                names = new DirectoryInfo(repo.Info.WorkingDirectory).GetFileSystemInfos().Select(fsi => fsi.Name).ToList();
                names.Sort(StringComparer.Ordinal);

                Assert.Equal(true, progressCalled);
                Assert.Equal(new[] { ".git", "README", "WillNotBeRemoved.txt", "branch_file.txt", "new.txt", "new_untracked_file.txt" }, names);
            }
        }
开发者ID:PKRoma,项目名称:libgit2sharp,代码行数:27,代码来源:ResetHeadFixture.cs

示例9: CanArchiveATree

        public void CanArchiveATree()
        {
            string path = SandboxBareTestRepo();
            using (var repo = new Repository(path))
            {
                var tree = repo.Lookup<Tree>("581f9824ecaf824221bd36edf5430f2739a7c4f5");

                var archiver = new MockArchiver();

                var before = DateTimeOffset.Now.TruncateMilliseconds();

                repo.ObjectDatabase.Archive(tree, archiver);

                var expected = new ArrayList
                {
                    new { Path = "1", Sha = "7f76480d939dc401415927ea7ef25c676b8ddb8f" },
                    new { Path = Path.Combine("1", "branch_file.txt"), Sha = "45b983be36b73c0788dc9cbcb76cbb80fc7bb057" },
                    new { Path = "README", Sha = "a8233120f6ad708f843d861ce2b7228ec4e3dec6" },
                    new { Path = "branch_file.txt", Sha = "45b983be36b73c0788dc9cbcb76cbb80fc7bb057" },
                    new { Path = "new.txt", Sha = "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd" },
                };
                Assert.Equal(expected, archiver.Files);
                Assert.Null(archiver.ReceivedCommitSha);
                Assert.InRange(archiver.ModificationTime, before, DateTimeOffset.UtcNow);
            }
        }
开发者ID:PKRoma,项目名称:libgit2sharp,代码行数:26,代码来源:ArchiveFixture.cs

示例10: CanCheckoutAnArbitraryCommit

        public void CanCheckoutAnArbitraryCommit(string commitPointer)
        {
            TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath);
            using (var repo = new Repository(path.RepositoryPath))
            {
                Branch master = repo.Branches["master"];
                Assert.True(master.IsCurrentRepositoryHead);

                // Set the working directory to the current head
                ResetAndCleanWorkingDirectory(repo);

                Assert.False(repo.Index.RetrieveStatus().IsDirty);

                Branch detachedHead = repo.Checkout(commitPointer);

                Assert.Equal(repo.Head, detachedHead);
                Assert.Equal(repo.Lookup(commitPointer).Sha, detachedHead.Tip.Sha);
                Assert.True(repo.Head.IsCurrentRepositoryHead);
                Assert.True(repo.Info.IsHeadDetached);
                Assert.False(repo.Index.RetrieveStatus().IsDirty);

                Assert.True(detachedHead.IsCurrentRepositoryHead);
                Assert.False(detachedHead.IsRemote);
                Assert.Equal(detachedHead.Name, detachedHead.CanonicalName);

                Assert.Equal("(no branch)", detachedHead.CanonicalName);

                Assert.False(master.IsCurrentRepositoryHead);
            }
        }
开发者ID:KindDragon,项目名称:libgit2sharp,代码行数:30,代码来源:CheckoutFixture.cs

示例11: CanExtractStatisticsFromDiff

        public void CanExtractStatisticsFromDiff()
        {
            using (var repo = new Repository(StandardTestRepoPath))
            {
                var oldTree = repo.Lookup<Commit>("origin/packed-test").Tree;
                var newTree = repo.Lookup<Commit>("HEAD").Tree;
                var stats = repo.Diff.Compare<PatchStats>(oldTree, newTree);

                Assert.Equal(8, stats.TotalLinesAdded);
                Assert.Equal(1, stats.TotalLinesDeleted);

                var contentStats = stats["new.txt"];
                Assert.Equal(1, contentStats.LinesAdded);
                Assert.Equal(1, contentStats.LinesDeleted);
            }
        }
开发者ID:AndersKroghDk,项目名称:libgit2sharp,代码行数:16,代码来源:PatchStatsFixture.cs

示例12: CanAmendACommitWithMoreThanOneParent

        public void CanAmendACommitWithMoreThanOneParent()
        {
            string path = CloneStandardTestRepo();
            using (var repo = new Repository(path))
            {
                var mergedCommit = repo.Lookup<Commit>("be3563a");
                Assert.NotNull(mergedCommit);
                Assert.Equal(2, mergedCommit.Parents.Count());

                repo.Reset(ResetOptions.Soft, mergedCommit.Sha);

                CreateAndStageANewFile(repo);
                const string commitMessage = "I'm rewriting the history!";

                Commit amendedCommit = repo.Commit(commitMessage, DummySignature, DummySignature, true);

                AssertCommitHasBeenAmended(repo, amendedCommit, mergedCommit);

                // Assert a reflog entry is created
                var reflogEntry = repo.Refs.Log("HEAD").First();
                Assert.Equal(amendedCommit.Committer, reflogEntry.Commiter);
                Assert.Equal(amendedCommit.Id, reflogEntry.To);
                Assert.Equal(string.Format("commit (amend): {0}", commitMessage), reflogEntry.Message);
            }
        }
开发者ID:TiThompson,项目名称:libgit2sharp,代码行数:25,代码来源:CommitFixture.cs

示例13: CanAmendACommitWithMoreThanOneParent

        public void CanAmendACommitWithMoreThanOneParent()
        {
            string path = CloneStandardTestRepo();
            using (var repo = new Repository(path))
            {
                var mergedCommit = repo.Lookup<Commit>("be3563a");
                Assert.NotNull(mergedCommit);
                Assert.Equal(2, mergedCommit.Parents.Count());

                repo.Reset(ResetMode.Soft, mergedCommit.Sha);

                CreateAndStageANewFile(repo);
                const string commitMessage = "I'm rewriting the history!";

                Commit amendedCommit = repo.Commit(commitMessage, Constants.Signature, Constants.Signature,
                    new CommitOptions { AmendPreviousCommit = true });

                AssertCommitHasBeenAmended(repo, amendedCommit, mergedCommit);

                AssertRefLogEntry(repo, "HEAD",
                                  amendedCommit.Id,
                                  string.Format("commit (amend): {0}", commitMessage),
                                  mergedCommit.Id,
                                  amendedCommit.Committer);
            }
        }
开发者ID:nulltoken,项目名称:libgit2sharp,代码行数:26,代码来源:CommitFixture.cs

示例14: CanArchiveACommitWithDirectoryAsTar

        public void CanArchiveACommitWithDirectoryAsTar()
        {
            var path = SandboxBareTestRepo();
            using (var repo = new Repository(path))
            {
                // This tests generates an archive of the bare test repo, and compares it with
                // a pre-generated tar file. The expected tar file has been generated with the
                // crlf filter active (on windows), so we need to make sure that even if the test
                // is launched on linux then the files content has the crlf filter applied (not
                // active by default).
                var sb = new StringBuilder();
                sb.Append("* text eol=crlf\n");
                Touch(Path.Combine(repo.Info.Path, "info"), "attributes", sb.ToString());

                var commit = repo.Lookup<Commit>("4c062a6361ae6959e06292c1fa5e2822d9c96345");

                var scd = BuildSelfCleaningDirectory();
                var archivePath = Path.Combine(scd.RootedDirectoryPath, Path.GetRandomFileName() + ".tar");
                Directory.CreateDirectory(scd.RootedDirectoryPath);

                repo.ObjectDatabase.Archive(commit, archivePath);

                using (var expectedStream = new StreamReader(Path.Combine(ResourcesDirectory.FullName, "expected_archives/commit_with_directory.tar")))
                using (var actualStream = new StreamReader(archivePath))
                {
                    string expected = expectedStream.ReadToEnd();
                    string actual = actualStream.ReadToEnd();

                    Assert.Equal(expected, actual);
                }
            }
        }
开发者ID:PKRoma,项目名称:libgit2sharp,代码行数:32,代码来源:ArchiveTarFixture.cs

示例15: CanSpecifyConflictFileStrategy

        public void CanSpecifyConflictFileStrategy(CheckoutFileConflictStrategy conflictStrategy)
        {
            const string conflictFile = "a.txt";
            const string conflictBranchName = "conflicts";

            string path = CloneMergeTestRepo();
            using (var repo = new Repository(path))
            {
                Branch branch = repo.Branches[conflictBranchName];
                Assert.NotNull(branch);

                CherryPickOptions cherryPickOptions = new CherryPickOptions()
                {
                    FileConflictStrategy = conflictStrategy,
                };

                CherryPickResult result = repo.CherryPick(branch.Tip, Constants.Signature, cherryPickOptions);
                Assert.Equal(CherryPickStatus.Conflicts, result.Status);

                // Get the information on the conflict.
                Conflict conflict = repo.Index.Conflicts[conflictFile];

                Assert.NotNull(conflict);
                Assert.NotNull(conflict.Theirs);
                Assert.NotNull(conflict.Ours);

                // Get the blob containing the expected content.
                Blob expectedBlob = null;
                switch (conflictStrategy)
                {
                    case CheckoutFileConflictStrategy.Theirs:
                        expectedBlob = repo.Lookup<Blob>(conflict.Theirs.Id);
                        break;
                    case CheckoutFileConflictStrategy.Ours:
                        expectedBlob = repo.Lookup<Blob>(conflict.Ours.Id);
                        break;
                    default:
                        throw new Exception("Unexpected FileConflictStrategy");
                }

                Assert.NotNull(expectedBlob);

                // Check the content of the file on disk matches what is expected.
                string expectedContent = expectedBlob.GetContentText(new FilteringOptions(conflictFile));
                Assert.Equal(expectedContent, File.ReadAllText(Path.Combine(repo.Info.WorkingDirectory, conflictFile)));
            }
        }
开发者ID:nulltoken,项目名称:libgit2sharp,代码行数:47,代码来源:CherryPickFixture.cs


注:本文中的Repository.Lookup方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。