Exemplo n.º 1
0
        public void CanCreateATreeContainingABlobFromAFileInTheWorkingDirectory()
        {
            string path = SandboxStandardTestRepo();

            using (var repo = new Repository(path))
            {
                Assert.Equal(FileStatus.Nonexistent, repo.RetrieveStatus("hello.txt"));
                File.AppendAllText(Path.Combine(repo.Info.WorkingDirectory, "hello.txt"), "I'm a new file\n");

                TreeDefinition td = TreeDefinition.From(repo.Head.Tip.Tree)
                                    .Add("1/new file", "hello.txt", Mode.NonExecutableFile);

                TreeEntryDefinition ted = td["1/new file"];
                Assert.NotNull(ted);
                Assert.Equal(ObjectId.Zero, ted.TargetId);

                td.Add("1/2/another new file", ted);

                Tree tree = repo.ObjectDatabase.CreateTree(td);

                TreeEntry te = tree["1/new file"];
                Assert.NotNull(te.Target);
                Assert.Equal("dc53d4c6b8684c21b0b57db29da4a2afea011565", te.Target.Sha);
                Assert.Equal("dc53d4c6b8684c21b0b57db29da4a2afea011565", td["1/new file"].TargetId.Sha);

                te = tree["1/2/another new file"];
                Assert.NotNull(te.Target);
                Assert.Equal("dc53d4c6b8684c21b0b57db29da4a2afea011565", te.Target.Sha);
                Assert.Equal("dc53d4c6b8684c21b0b57db29da4a2afea011565", td["1/2/another new file"].TargetId.Sha);
            }
        }
Exemplo n.º 2
0
        public void CanReplaceAnExistingGitLinkWithABlob()
        {
            const string blobSha    = "42cfb95cd01bf9225b659b5ee3edcc78e8eeb478";
            const string targetPath = "sm_unchanged";

            using (var repo = new Repository(SubmoduleTestRepoWorkingDirPath))
            {
                TreeDefinition td = TreeDefinition.From(repo.Head.Tip.Tree);
                Assert.NotNull(td[targetPath]);
                Assert.Equal(TreeEntryTargetType.GitLink, td[targetPath].TargetType);
                Assert.Equal(Mode.GitLink, td[targetPath].Mode);

                var objectId = new ObjectId(blobSha);
                var blob     = repo.Lookup <Blob>(objectId);

                td.Add(targetPath, blob, Mode.NonExecutableFile);

                TreeEntryDefinition fetched = td[targetPath];
                Assert.NotNull(fetched);

                Assert.Equal(objectId, fetched.TargetId);
                Assert.Equal(TreeEntryTargetType.Blob, fetched.TargetType);
                Assert.Equal(Mode.NonExecutableFile, fetched.Mode);
            }
        }
Exemplo n.º 3
0
        public void CanReplaceAnExistingTreeWithABlob()
        {
            const string blobSha    = "a8233120f6ad708f843d861ce2b7228ec4e3dec6";
            const string targetPath = "1";

            using (var repo = new Repository(BareTestRepoPath))
            {
                TreeDefinition td = TreeDefinition.From(repo.Head.Tip.Tree);
                Assert.Equal(TreeEntryTargetType.Tree, td[targetPath].TargetType);

                var objectId = new ObjectId(blobSha);
                var blob     = repo.Lookup <Blob>(objectId);

                Assert.NotNull(td["1/branch_file.txt"]);

                td.Add(targetPath, blob, Mode.NonExecutableFile);

                TreeEntryDefinition fetched = td[targetPath];
                Assert.NotNull(fetched);

                Assert.Equal(TreeEntryTargetType.Blob, td[targetPath].TargetType);
                Assert.Equal(objectId, fetched.TargetId);
                Assert.Equal(Mode.NonExecutableFile, fetched.Mode);

                Assert.Null(td["1/branch_file.txt"]);
            }
        }
Exemplo n.º 4
0
        public void CanReplaceAnExistingGitLinkWithATree()
        {
            const string treeSha    = "607d96653d4d0a4f733107f7890c2e67b55b620d";
            const string targetPath = "sm_unchanged";

            using (var repo = new Repository(SubmoduleTestRepoWorkingDirPath))
            {
                TreeDefinition td = TreeDefinition.From(repo.Head.Tip.Tree);
                Assert.NotNull(td[targetPath]);
                Assert.Equal(TreeEntryTargetType.GitLink, td[targetPath].TargetType);
                Assert.Equal(Mode.GitLink, td[targetPath].Mode);

                var objectId = new ObjectId(treeSha);
                var tree     = repo.Lookup <Tree>(objectId);

                td.Add(targetPath, tree);

                TreeEntryDefinition fetched = td[targetPath];
                Assert.NotNull(fetched);

                Assert.Equal(objectId, fetched.TargetId);
                Assert.Equal(TreeEntryTargetType.Tree, fetched.TargetType);
                Assert.Equal(Mode.Directory, fetched.Mode);
            }
        }
        public void CanReplaceAnExistingTreeWithAGitLink()
        {
            var          commitId   = (ObjectId)"480095882d281ed676fe5b863569520e54a7d5c0";
            const string targetPath = "just_a_dir";

            var path = SandboxSubmoduleTestRepo();

            using (var repo = new Repository(path))
            {
                TreeDefinition td = TreeDefinition.From(repo.Head.Tip.Tree);
                Assert.Equal(TreeEntryTargetType.Tree, td[targetPath].TargetType);

                Assert.NotNull(td["just_a_dir/contents"]);

                td.AddGitLink(targetPath, commitId);

                TreeEntryDefinition fetched = td[targetPath];
                Assert.NotNull(fetched);

                Assert.Equal(commitId, fetched.TargetId);
                Assert.Equal(TreeEntryTargetType.GitLink, fetched.TargetType);
                Assert.Equal(Mode.GitLink, fetched.Mode);

                Assert.Null(td["just_a_dir/contents"]);
            }
        }
Exemplo n.º 6
0
        public void CanAddAnExistingSubmodule()
        {
            const string submodulePath = "sm_unchanged";

            using (var repo = new Repository(SubmoduleTestRepoWorkingDirPath))
            {
                var submodule = repo.Submodules[submodulePath];
                Assert.NotNull(submodule);

                TreeDefinition td = TreeDefinition.From(repo.Head.Tip.Tree);
                Assert.NotNull(td[submodulePath]);

                td.Remove(submodulePath);
                Assert.Null(td[submodulePath]);

                td.Add(submodule);

                TreeEntryDefinition fetched = td[submodulePath];
                Assert.NotNull(fetched);

                Assert.Equal(submodule.HeadCommitId, fetched.TargetId);
                Assert.Equal(TreeEntryTargetType.GitLink, fetched.TargetType);
                Assert.Equal(Mode.GitLink, fetched.Mode);
            }
        }
        public void CanReplaceAnExistingBlobWithATree(string targetPath)
        {
            const string treeSha = "7f76480d939dc401415927ea7ef25c676b8ddb8f";

            string path = SandboxBareTestRepo();

            using (var repo = new Repository(path))
            {
                TreeDefinition td = TreeDefinition.From(repo.Head.Tip.Tree);
                Assert.NotNull(td[targetPath]);
                Assert.Equal(TreeEntryTargetType.Blob, td[targetPath].TargetType);

                var objectId = new ObjectId(treeSha);
                var tree     = repo.Lookup <Tree>(objectId);

                td.Add(targetPath, tree);

                TreeEntryDefinition fetched = td[targetPath];
                Assert.NotNull(fetched);

                Assert.Equal(TreeEntryTargetType.Tree, td[targetPath].TargetType);
                Assert.Equal(objectId, fetched.TargetId);
                Assert.Equal(Mode.Directory, fetched.Mode);
            }
        }
        public void CanAddAnExistingTree()
        {
            const string treeSha    = "7f76480d939dc401415927ea7ef25c676b8ddb8f";
            const string targetPath = "1/2";

            string path = SandboxBareTestRepo();

            using (var repo = new Repository(path))
            {
                TreeDefinition td = TreeDefinition.From(repo.Head.Tip.Tree);

                var objectId = new ObjectId(treeSha);
                var tree     = repo.Lookup <Tree>(objectId);

                td.Add(targetPath, tree);

                TreeEntryDefinition fetched = td[targetPath];
                Assert.NotNull(fetched);

                Assert.Equal(objectId, fetched.TargetId);
                Assert.Equal(Mode.Directory, fetched.Mode);

                Assert.NotNull(td["1/2/branch_file.txt"]);
            }
        }
Exemplo n.º 9
0
        public void CanRetrieveEntries(string path, string expectedAttributes, TreeEntryTargetType expectedType, string expectedSha)
        {
            using (var repo = new Repository(BareTestRepoPath))
            {
                TreeDefinition td = TreeDefinition.From(repo.Head.Tip.Tree);

                TreeEntryDefinition ted = td[path];

                Assert.Equal(ToMode(expectedAttributes), ted.Mode);
                Assert.Equal(expectedType, ted.TargetType);
                Assert.Equal(new ObjectId(expectedSha), ted.TargetId);
            }
        }
Exemplo n.º 10
0
        public void CanAddAnExistingTreeEntryDefinition(string sourcePath, string targetPath)
        {
            using (var repo = new Repository(BareTestRepoPath))
            {
                TreeDefinition td = TreeDefinition.From(repo.Head.Tip.Tree);
                Assert.Null(td[targetPath]);

                TreeEntryDefinition ted = td[sourcePath];
                td.Add(targetPath, ted);

                TreeEntryDefinition fetched = td[targetPath];
                Assert.NotNull(fetched);

                Assert.Equal(ted, fetched);
            }
        }
Exemplo n.º 11
0
        public void CanAddAnExistingBlobEntryWithAnExistingTree()
        {
            using (var repo = new Repository(BareTestRepoPath))
            {
                TreeDefinition      td       = TreeDefinition.From(repo.Head.Tip.Tree);
                TreeEntryDefinition original = td["README"];

                td.Add("1/2/README", original);

                TreeEntryDefinition fetched = td["1/2/README"];
                Assert.NotNull(fetched);

                Assert.Equal(original.TargetId, fetched.TargetId);
                Assert.Equal(original.Mode, fetched.Mode);

                Assert.NotNull(td["1/branch_file.txt"]);
            }
        }
Exemplo n.º 12
0
        public void CanAddAnExistingBlob(string blobSha, string targetPath)
        {
            using (var repo = new Repository(BareTestRepoPath))
            {
                TreeDefinition td = TreeDefinition.From(repo.Head.Tip.Tree);
                Assert.Null(td[targetPath]);

                var objectId = new ObjectId(blobSha);
                var blob     = repo.Lookup <Blob>(objectId);

                td.Add(targetPath, blob, Mode.NonExecutableFile);

                TreeEntryDefinition fetched = td[targetPath];
                Assert.NotNull(fetched);

                Assert.Equal(objectId, fetched.TargetId);
                Assert.Equal(Mode.NonExecutableFile, fetched.Mode);
            }
        }
Exemplo n.º 13
0
        public void CanAddAnExistingGitLinkTreeEntryDefinition()
        {
            const string sourcePath = "sm_unchanged";
            const string targetPath = "sm_from_td";

            using (var repo = new Repository(SubmoduleTestRepoWorkingDirPath))
            {
                TreeDefinition td = TreeDefinition.From(repo.Head.Tip.Tree);
                Assert.Null(td[targetPath]);

                TreeEntryDefinition ted = td[sourcePath];
                td.Add(targetPath, ted);

                TreeEntryDefinition fetched = td[targetPath];
                Assert.NotNull(fetched);

                Assert.Equal(ted, fetched);
            }
        }
Exemplo n.º 14
0
        public void CanAddBlobById(string blobSha, string targetPath)
        {
            string path = SandboxBareTestRepo();

            using (var repo = new Repository(path))
            {
                TreeDefinition td = TreeDefinition.From(repo.Head.Tip.Tree);
                Assert.Null(td[targetPath]);

                var objectId = new ObjectId(blobSha);

                td.Add(targetPath, objectId, Mode.NonExecutableFile);

                TreeEntryDefinition fetched = td[targetPath];
                Assert.NotNull(fetched);

                Assert.Equal(objectId, fetched.TargetId);
                Assert.Equal(Mode.NonExecutableFile, fetched.Mode);
            }
        }
Exemplo n.º 15
0
        public void CanCreateATreeContainingAGitLinkFromAnUntrackedSubmoduleInTheWorkingDirectory()
        {
            string path = SandboxSubmoduleTestRepo();

            using (var repo = new Repository(path))
            {
                const string submodulePath = "sm_added_and_uncommited";

                var submoduleBefore = repo.Submodules[submodulePath];
                Assert.NotNull(submoduleBefore);
                Assert.Null(submoduleBefore.HeadCommitId);

                var objectId = (ObjectId)"480095882d281ed676fe5b863569520e54a7d5c0";

                TreeDefinition td = TreeDefinition.From(repo.Head.Tip.Tree)
                                    .AddGitLink(submodulePath, objectId);

                TreeEntryDefinition ted = td[submodulePath];
                Assert.NotNull(ted);
                Assert.Equal(Mode.GitLink, ted.Mode);
                Assert.Equal(objectId, ted.TargetId);
                Assert.Equal(TreeEntryTargetType.GitLink, ted.TargetType);

                Tree tree = repo.ObjectDatabase.CreateTree(td);

                TreeEntry te = tree[submodulePath];
                Assert.NotNull(te.Target);
                Assert.IsType <GitLink>(te.Target);
                Assert.Equal(objectId, te.Target.Id);

                var commitWithSubmodule = repo.ObjectDatabase.CreateCommit(Constants.Signature, Constants.Signature, "Submodule!",
                                                                           tree, new[] { repo.Head.Tip }, false);
                repo.Reset(ResetMode.Soft, commitWithSubmodule);

                var submodule = repo.Submodules[submodulePath];
                Assert.NotNull(submodule);
                Assert.Equal(submodulePath, submodule.Name);
                Assert.Equal(submodulePath, submodule.Path);
                Assert.Equal(objectId, submodule.HeadCommitId);
            }
        }