Example #1
0
        public void CanFollowFirstParent()
        {
            string path = SandboxStandardTestRepo();
            using (var repo = new Repository(path))
            {
                var branch = repo.CreateBranch("branch");

                // Make an earlier tag on master
                repo.Commit("A", Constants.Signature, Constants.Signature, new CommitOptions { AllowEmptyCommit = true });
                repo.ApplyTag("firstParentTag");

                // Make a later tag on branch
                Commands.Checkout(repo, branch);
                repo.Commit("B", Constants.Signature, Constants.Signature, new CommitOptions { AllowEmptyCommit = true });
                repo.ApplyTag("mostRecentTag");

                Commands.Checkout(repo, "master");
                repo.Commit("C", Constants.Signature, Constants.Signature, new CommitOptions { AllowEmptyCommit = true });
                repo.Merge(branch, Constants.Signature, new MergeOptions() { FastForwardStrategy = FastForwardStrategy.NoFastForward });

                // With OnlyFollowFirstParent = false, the most recent tag reachable should be returned
                Assert.Equal("mostRecentTag-3-gf17be71", repo.Describe(repo.Head.Tip, new DescribeOptions { OnlyFollowFirstParent = false, Strategy = DescribeStrategy.Tags }));

                // With OnlyFollowFirstParent = true, the most recent tag on the current branch should be returned
                Assert.Equal("firstParentTag-2-gf17be71", repo.Describe(repo.Head.Tip, new DescribeOptions { OnlyFollowFirstParent = true, Strategy = DescribeStrategy.Tags }));

            }
        }
        // Ported from cgit (https://github.com/git/git/blob/1c08bf50cfcf924094eca56c2486a90e2bf1e6e2/t/t7004-tag.sh#L37)
        public void CreatingATagForHeadInAEmptyRepositoryThrows()
        {
            string repoPath = InitNewRepository();

            using (var repo = new Repository(repoPath))
            {
                Assert.Throws <UnbornBranchException>(() => repo.ApplyTag("mytaghead", "HEAD"));
                Assert.Throws <UnbornBranchException>(() => repo.ApplyTag("mytaghead"));
            }
        }
Example #3
0
        public void CreatingADuplicateTagThrows()
        {
            TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo();

            using (var repo = new Repository(path.RepositoryPath))
            {
                repo.ApplyTag("mytag");

                Assert.Throws <LibGit2Exception>(() => repo.ApplyTag("mytag"));
            }
        }
Example #4
0
        public void CreatingATagWithNameMatchingAnAlreadyExistingReferenceHierarchyThrows()
        {
            TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo();

            using (var repo = new Repository(path.RepositoryPath))
            {
                repo.ApplyTag("i/am/deep");
                Assert.Throws <LibGit2Exception>(() => repo.ApplyTag("i/am/deep/rooted"));
                Assert.Throws <LibGit2Exception>(() => repo.ApplyTag("i/am"));
            }
        }
Example #5
0
 // Ported from cgit (https://github.com/git/git/blob/1c08bf50cfcf924094eca56c2486a90e2bf1e6e2/t/t7004-tag.sh#L90)
 public void CreatingATagWithANonValidNameShouldFail()
 {
     using (var repo = new Repository(BareTestRepoPath))
     {
         Assert.Throws <ArgumentException>(() => repo.ApplyTag(""));
         Assert.Throws <InvalidSpecificationException>(() => repo.ApplyTag(".othertag"));
         Assert.Throws <InvalidSpecificationException>(() => repo.ApplyTag("other tag"));
         Assert.Throws <InvalidSpecificationException>(() => repo.ApplyTag("othertag^"));
         Assert.Throws <InvalidSpecificationException>(() => repo.ApplyTag("other~tag"));
     }
 }
        public void CreatingATagWithNameMatchingAnAlreadyExistingReferenceHierarchyThrows()
        {
            string path = SandboxBareTestRepo();

            using (var repo = new Repository(path))
            {
                repo.ApplyTag("i/am/deep");
                Assert.Throws <LibGit2SharpException>(() => repo.ApplyTag("i/am/deep/rooted"));
                Assert.Throws <LibGit2SharpException>(() => repo.ApplyTag("i/am"));
            }
        }
        // Ported from cgit (https://github.com/git/git/blob/1c08bf50cfcf924094eca56c2486a90e2bf1e6e2/t/t7004-tag.sh#L87)
        public void CreatingADuplicateTagThrows()
        {
            string path = SandboxBareTestRepo();

            using (var repo = new Repository(path))
            {
                repo.ApplyTag("mytag");

                Assert.Throws <NameConflictException>(() => repo.ApplyTag("mytag"));
            }
        }
Example #8
0
        private void InitCoreTags(Repository repo)
        {
            // Create tags for Upvote, Downvote, and EmptyTree
            Tree emptyTree = repo.ObjectDatabase.CreateTree(new TreeDefinition());

            repo.ApplyTag(EMPTY_TREE, emptyTree.Sha);

            Blob upvote = repo.ObjectDatabase.CreateBlob(new MemoryStream(Encoding.ASCII.GetBytes(UPVOTE)));

            repo.ApplyTag(UPVOTE, upvote.Sha);

            Blob downvote = repo.ObjectDatabase.CreateBlob(new MemoryStream(Encoding.ASCII.GetBytes(DOWNVOTE)));

            repo.ApplyTag(DOWNVOTE, downvote.Sha);
        }
Example #9
0
 public void CreatingATagForANonCanonicalReferenceThrows()
 {
     using (var repo = new Repository(BareTestRepoPath))
     {
         Assert.Throws <LibGit2Exception>(() => repo.ApplyTag("noncanonicaltarget", "br2"));
     }
 }
Example #10
0
        public int Execute(Options options)
        {
            var calculator = new VersionCalculator();
            var finder     = new GitFolderFinder();

            var version = calculator.CalculateVersion(options);

            if (version == null)
            {
                return(1);
            }

            if (version.IsDirty)
            {
                Console.WriteLine("Cannot apply tag with uncommitted changes");
                return(1);
            }

            var gitFolder = finder.FindGitFolder(options.Path);

            using (var repo = new Repository(gitFolder))
            {
                repo.ApplyTag(version.SemVer);
            }

            Console.WriteLine($"Created Tag: {version.SemVer}");

            return(0);
        }
Example #11
0
 public void CreateTag(string name, string sha, string comment, string Owner, string emailOwner, DateTime creationDate)
 {
     if (_repository.Tags[name] == null)
     {
         _repository.ApplyTag(name, sha, new Signature(Owner, emailOwner, new DateTimeOffset(creationDate)), comment);
     }
 }
Example #12
0
 // Ported from cgit (https://github.com/git/git/blob/1c08bf50cfcf924094eca56c2486a90e2bf1e6e2/t/t7004-tag.sh#L42)
 public void CreatingATagForAnUnknowReferenceThrows()
 {
     using (var repo = new Repository(BareTestRepoPath))
     {
         Assert.Throws <LibGit2SharpException>(() => repo.ApplyTag("mytagnorev", "aaaaaaaaaaa"));
     }
 }
Example #13
0
 // Ported from cgit (https://github.com/git/git/blob/1c08bf50cfcf924094eca56c2486a90e2bf1e6e2/t/t7004-tag.sh#L42)
 public void CreatingATagForAnUnknowObjectIdThrows()
 {
     using (var repo = new Repository(BareTestRepoPath))
     {
         Assert.Throws <LibGit2SharpException>(() => repo.ApplyTag("mytagnorev", Constants.UnknownSha));
     }
 }
Example #14
0
 protected static void AddTag(Repository repo, string tagName)
 {
     var randomFile = Path.Combine(repo.Info.WorkingDirectory, Guid.NewGuid().ToString());
     File.WriteAllText(randomFile, string.Empty);
     repo.Index.Stage(randomFile);
     var sign = SignatureBuilder.SignatureNow();
     repo.ApplyTag(tagName, repo.Head.Tip.Id.Sha, sign, "foo");
 }
Example #15
0
 public static void Tag(string repositoryPath)
 {
     using (var repo = new Repository(repositoryPath))
     {
         string tag = DateTime.Now.ToString("yyyyMMddHHmmss");
         Tag    t   = repo.ApplyTag(tag);
     }
 }
Example #16
0
        // Ported from cgit (https://github.com/git/git/blob/1c08bf50cfcf924094eca56c2486a90e2bf1e6e2/t/t7004-tag.sh#L32)
        public void CreatingATagInAEmptyRepositoryThrows()
        {
            string repoPath = InitNewRepository();

            using (var repo = new Repository(repoPath))
            {
                Assert.Throws <LibGit2SharpException>(() => repo.ApplyTag("mynotag"));
            }
        }
        // Ported from cgit (https://github.com/git/git/blob/1c08bf50cfcf924094eca56c2486a90e2bf1e6e2/t/t7004-tag.sh#L42)
        public void CreatingATagForAnUnknowReferenceThrows()
        {
            string path = SandboxBareTestRepo();

            using (var repo = new Repository(path))
            {
                Assert.Throws <NotFoundException>(() => repo.ApplyTag("mytagnorev", "aaaaaaaaaaa"));
            }
        }
        // Ported from cgit (https://github.com/git/git/blob/1c08bf50cfcf924094eca56c2486a90e2bf1e6e2/t/t7004-tag.sh#L42)
        public void CreatingATagForAnUnknowObjectIdThrows()
        {
            string path = SandboxBareTestRepo();

            using (var repo = new Repository(path))
            {
                Assert.Throws <NotFoundException>(() => repo.ApplyTag("mytagnorev", Constants.UnknownSha));
            }
        }
Example #19
0
        public static async Task Main(string[] args)
        {
            var client = new SecretClient(
                vaultUri: new Uri("https://roslyninfra.vault.azure.net:443"),
                credential: new DefaultAzureCredential(includeInteractiveCredentials: true));

            using var devdivConnection = new AzDOConnection("https://devdiv.visualstudio.com/DefaultCollection", "DevDiv", "Roslyn-Signed", client, "vslsnap-vso-auth-token");
            using var dncengConnection = new AzDOConnection("https://dnceng.visualstudio.com/DefaultCollection", "internal", "dotnet-roslyn CI", client, "vslsnap-build-auth-token");

            var connections = new[] { devdivConnection, dncengConnection };

            var visualStudioReleases = await GetVisualStudioReleasesAsync(devdivConnection.GitClient);

            var roslynRepository = new Repository(args[0]);
            var existingTags     = roslynRepository.Tags.ToImmutableArray();

            foreach (var visualStudioRelease in visualStudioReleases)
            {
                var roslynTagName = TryGetRoslynTagName(visualStudioRelease);

                if (roslynTagName is not null)
                {
                    if (!existingTags.Any(t => t.FriendlyName == roslynTagName))
                    {
                        Console.WriteLine($"Tag {roslynTagName} is missing.");

                        RoslynBuildInformation?roslynBuild = null;
                        foreach (var connection in connections)
                        {
                            roslynBuild = await TryGetRoslynBuildForReleaseAsync(visualStudioRelease, devdivConnection, connection);

                            if (roslynBuild is not null)
                            {
                                break;
                            }
                        }

                        if (roslynBuild is not null)
                        {
                            Console.WriteLine($"Tagging {roslynBuild.CommitSha} as {roslynTagName}.");

                            string message = $"Build Branch: {roslynBuild.SourceBranch}\r\nInternal ID: {roslynBuild.BuildId}\r\nInternal VS ID: {visualStudioRelease.BuildId}";

                            roslynRepository.ApplyTag(roslynTagName, roslynBuild.CommitSha, new Signature("dotnet bot", "*****@*****.**", when: visualStudioRelease.CreationTime), message);
                        }
                        else
                        {
                            Console.WriteLine($"Unable to find the build for {roslynTagName}.");
                        }
                    }
                    else
                    {
                        Console.WriteLine($"Tag {roslynTagName} already exists.");
                    }
                }
            }
        }
Example #20
0
        public void CreatingATagForHeadInAEmptyRepositoryThrows()
        {
            SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
            string dir = Repository.Init(scd.DirectoryPath);

            using (var repo = new Repository(dir))
            {
                Assert.Throws <LibGit2Exception>(() => repo.ApplyTag("mytaghead", "HEAD"));
            }
        }
Example #21
0
        public static void TagPrefix(string tag, string prefix, string expectedVersion, string path, Repository repo, Version actualVersion)
        {
            $"Given a git repository with a commit in '{path = GetScenarioDirectory($"tag-prefixes-{tag}")}'"
            .x(c => repo = EnsureEmptyRepositoryAndCommit(path).Using(c));

            $"And the commit is tagged '{tag}'"
            .x(() => repo.ApplyTag(tag));

            $"When the version is determined using the tag prefix '{prefix}'"
            .x(() => actualVersion = Versioner.GetVersion(path, prefix, default, default, new TestLogger()));
Example #22
0
    protected static void AddTag(Repository repo, string tagName)
    {
        var randomFile = Path.Combine(repo.Info.WorkingDirectory, Guid.NewGuid().ToString());

        File.WriteAllText(randomFile, string.Empty);
        repo.Stage(randomFile);
        var sign = SignatureBuilder.SignatureNow();

        repo.ApplyTag(tagName, repo.Head.Tip.Id.Sha, sign, "foo");
    }
        public void CanFollowFirstParent()
        {
            string path = SandboxStandardTestRepo();

            using (var repo = new Repository(path))
            {
                var branch = repo.CreateBranch("branch");

                // Make an earlier tag on master
                repo.Commit("A", Constants.Signature, Constants.Signature, new CommitOptions {
                    AllowEmptyCommit = true
                });
                repo.ApplyTag("firstParentTag");

                // Make a later tag on branch
                Commands.Checkout(repo, branch);
                repo.Commit("B", Constants.Signature, Constants.Signature, new CommitOptions {
                    AllowEmptyCommit = true
                });
                repo.ApplyTag("mostRecentTag");

                Commands.Checkout(repo, "master");
                repo.Commit("C", Constants.Signature, Constants.Signature, new CommitOptions {
                    AllowEmptyCommit = true
                });
                repo.Merge(branch, Constants.Signature, new MergeOptions()
                {
                    FastForwardStrategy = FastForwardStrategy.NoFastForward
                });

                // With OnlyFollowFirstParent = false, the most recent tag reachable should be returned
                Assert.Equal("mostRecentTag-3-gf17be71", repo.Describe(repo.Head.Tip, new DescribeOptions {
                    OnlyFollowFirstParent = false, Strategy = DescribeStrategy.Tags
                }));

                // With OnlyFollowFirstParent = true, the most recent tag on the current branch should be returned
                Assert.Equal("firstParentTag-2-gf17be71", repo.Describe(repo.Head.Tip, new DescribeOptions {
                    OnlyFollowFirstParent = true, Strategy = DescribeStrategy.Tags
                }));
            }
        }
Example #24
0
        // Ported from cgit (https://github.com/git/git/blob/1c08bf50cfcf924094eca56c2486a90e2bf1e6e2/t/t7004-tag.sh#L359)
        public void CanCreateAnAnnotatedTagWithAnEmptyMessage()
        {
            TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo();

            using (var repo = new Repository(path.RepositoryPath))
            {
                Tag newTag = repo.ApplyTag("empty-annotated-tag", signatureNtk, string.Empty);
                Assert.NotNull(newTag);
                Assert.True(newTag.IsAnnotated);
                Assert.Equal(string.Empty, newTag.Annotation.Message);
            }
        }
Example #25
0
        public void CanCreateAnAnnotatedTagWithAnEmptyMessage()
        {
            TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo();

            using (var repo = new Repository(path.RepositoryPath))
            {
                Tag newTag = repo.ApplyTag("empty-annotated-tag", signatureNtk, string.Empty);
                newTag.ShouldNotBeNull();
                newTag.IsAnnotated.ShouldBeTrue();
                newTag.Annotation.Message.ShouldEqual(string.Empty);
            }
        }
Example #26
0
        public static async Task Main(string[] args)
        {
            var client = new SecretClient(
                vaultUri: new Uri("https://roslyninfra.vault.azure.net:443"),
                credential: new DefaultAzureCredential(includeInteractiveCredentials: true));

            var azureDevOpsSecret = await client.GetSecretAsync("vslsnap-vso-auth-token");

            using var connection = new VssConnection(
                      new Uri("https://devdiv.visualstudio.com/DefaultCollection"),
                      new WindowsCredential(new NetworkCredential("vslsnap", azureDevOpsSecret.Value.Value)));

            using var gitClient = await connection.GetClientAsync <GitHttpClient>();

            using var buildClient = await connection.GetClientAsync <BuildHttpClient>();

            var visualStudioReleases = await GetVisualStudioReleasesAsync(gitClient);

            var roslynRepository = new Repository(args[0]);
            var existingTags     = roslynRepository.Tags.ToImmutableArray();

            foreach (var visualStudioRelease in visualStudioReleases)
            {
                var roslynTagName = TryGetRoslynTagName(visualStudioRelease);

                if (roslynTagName != null)
                {
                    if (!existingTags.Any(t => t.FriendlyName == roslynTagName))
                    {
                        Console.WriteLine($"Tag {roslynTagName} is missing.");

                        var roslynBuild = await TryGetRoslynBuildForReleaseAsync(visualStudioRelease, gitClient, buildClient);

                        if (roslynBuild != null)
                        {
                            Console.WriteLine($"Tagging {roslynBuild.CommitSha} as {roslynTagName}.");

                            string message = $"Build Branch: {roslynBuild.SourceBranch}\r\nInternal ID: {roslynBuild.BuildId}\r\nInternal VS ID: {visualStudioRelease.BuildId}";

                            roslynRepository.ApplyTag(roslynTagName, roslynBuild.CommitSha, new Signature("dotnet bot", "*****@*****.**", when: visualStudioRelease.CreationTime), message);
                        }
                        else
                        {
                            Console.WriteLine($"Unable to find the build for {roslynTagName}.");
                        }
                    }
                    else
                    {
                        Console.WriteLine($"Tag {roslynTagName} already exists.");
                    }
                }
            }
        }
        // Ported from cgit (https://github.com/git/git/blob/1c08bf50cfcf924094eca56c2486a90e2bf1e6e2/t/t7004-tag.sh#L359)
        public void CanAddAnAnnotatedTagWithAnEmptyMessage()
        {
            string path = SandboxBareTestRepo();

            using (var repo = new Repository(path))
            {
                Tag newTag = repo.ApplyTag("empty-annotated-tag", signatureNtk, string.Empty);
                Assert.NotNull(newTag);
                Assert.True(newTag.IsAnnotated);
                Assert.Equal(string.Empty, newTag.Annotation.Message);
            }
        }
Example #28
0
        public static void RtmVersionIncrement(string tag, VersionPart autoIncrement, string expectedVersion, string path, Repository repo, Version actualVersion)
        {
            $"Given a git repository with a commit in '{path = GetScenarioDirectory($"rtm-auto-increment-{tag}")}'"
            .x(c => repo = EnsureEmptyRepositoryAndCommit(path).Using(c));

            $"And the commit is tagged '{tag}'"
            .x(() => repo.ApplyTag(tag));

            $"And another commit"
            .x(() => Commit(path));

            $"When the version is determined using auto-increment '{autoIncrement}'"
            .x(() => actualVersion = Versioner.GetVersion(path, default, default, default, autoIncrement, default, new TestLogger()));
Example #29
0
        protected override bool OnStepStart()
        {
            var commit = GitUtils.GetCommit(Repository, CommitSearch);

            if (commit == null)
            {
                RockLog.WriteLine(this, LogTier.Error, "Commit not found!");
                return(false);
            }

            Repository.ApplyTag(TagName, commit.Sha);

            return(true);
        }
Example #30
0
        public void LightTagNameTest()
        {
            using (TempRepoProvider tempRepo = new TempRepoProvider("Test3.version.json"))
            {
                using Repository repo = new Repository(tempRepo.RepoDirectory.FullName);
                Commands.Checkout(repo, repo.CreateBranch("ccdd"));

                repo.ApplyTag("v3.2.1");

                VersionGenerator versionGenerator = new VersionGenerator(tempRepo.RepoVersionFilePath);

                Assert.Equal("tag v3.2.1", versionGenerator.BranchName);
            }
        }
Example #31
0
        public void CanCreateATagUsingHead()
        {
            TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo();

            using (var repo = new Repository(path.RepositoryPath))
            {
                Tag tag = repo.ApplyTag("mytag", "HEAD");
                tag.ShouldNotBeNull();

                tag.Target.Id.ShouldEqual(repo.Head.Tip.Id);

                Tag retrievedTag = repo.Tags[tag.CanonicalName];
                tag.ShouldEqual(retrievedTag);
            }
        }
        // Ported from cgit (https://github.com/git/git/blob/1c08bf50cfcf924094eca56c2486a90e2bf1e6e2/t/t7004-tag.sh#L101)
        public void CanAddATagUsingHead()
        {
            string path = SandboxBareTestRepo();

            using (var repo = new Repository(path))
            {
                Tag tag = repo.ApplyTag("mytag", "HEAD");
                Assert.NotNull(tag);

                Assert.Equal(repo.Head.Tip.Id, tag.Target.Id);

                Tag retrievedTag = repo.Tags[tag.CanonicalName];
                Assert.Equal(retrievedTag, tag);
            }
        }
Example #33
0
        public void CanDescribeACommit()
        {
            string path = SandboxBareTestRepo();
            using (var repo = new Repository(path))
            {
                // No annotated tags can be used to describe "master"
                var masterTip = repo.Branches["master"].Tip;
                Assert.Throws<NotFoundException>(() => repo.Describe(masterTip));
                Assert.Equal("4c062a6", repo.Describe(masterTip,
                    new DescribeOptions { UseCommitIdAsFallback = true }));
                Assert.Equal("4c06", repo.Describe(masterTip,
                    new DescribeOptions { UseCommitIdAsFallback = true, MinimumCommitIdAbbreviatedSize = 2 }));

                // No lightweight tags can either be used to describe "master"
                Assert.Throws<NotFoundException>(() => repo.Describe(masterTip,
                    new DescribeOptions{ Strategy = DescribeStrategy.Tags }));

                repo.ApplyTag("myTag", "5b5b025afb0b4c913b4c338a42934a3863bf3644");
                Assert.Equal("myTag-5-g4c062a6", repo.Describe(masterTip,
                    new DescribeOptions { Strategy = DescribeStrategy.Tags }));
                Assert.Equal("myTag-5-g4c062a636", repo.Describe(masterTip,
                    new DescribeOptions { Strategy = DescribeStrategy.Tags, MinimumCommitIdAbbreviatedSize = 9 }));
                Assert.Equal("myTag-4-gbe3563a", repo.Describe(masterTip.Parents.Single(),
                    new DescribeOptions { Strategy = DescribeStrategy.Tags }));

                Assert.Equal("heads/master", repo.Describe(masterTip,
                    new DescribeOptions { Strategy = DescribeStrategy.All }));
                Assert.Equal("heads/packed-test-3-gbe3563a", repo.Describe(masterTip.Parents.Single(),
                    new DescribeOptions { Strategy = DescribeStrategy.All }));

                // "test" branch points to an annotated tag (also named "test")
                // Let's rename the branch to ease the understanding of what we
                // are exercising.

                repo.Branches.Rename(repo.Branches["test"], "ForLackOfABetterName");

                var anotherTip = repo.Branches["ForLackOfABetterName"].Tip;
                Assert.Equal("test", repo.Describe(anotherTip));
                Assert.Equal("test-0-g7b43849", repo.Describe(anotherTip,
                    new DescribeOptions{ AlwaysRenderLongFormat = true }));
            }
        }
Example #34
0
 public void CanCreateAnAnnotatedTagWithAnEmptyMessage()
 {
     TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo();
     using (var repo = new Repository(path.RepositoryPath))
     {
         Tag newTag = repo.ApplyTag("empty-annotated-tag", signatureNtk, string.Empty);
         newTag.ShouldNotBeNull();
         newTag.IsAnnotated.ShouldBeTrue();
         newTag.Annotation.Message.ShouldEqual(string.Empty);
     }
 }
Example #35
0
        public void CanEnumerateCommitsFromATagWhichPointsToATree()
        {
            string path = CloneBareTestRepo();
            using (var repo = new Repository(path))
            {
                string headTreeSha = repo.Head.Tip.Tree.Sha;

                Tag tag = repo.ApplyTag("point_to_tree", headTreeSha);

                AssertEnumerationOfCommitsInRepo(repo,
                    r => new Filter { Since = tag },
                    new string[] { });
            }
        }
Example #36
0
        public void CanCreateAnAnnotatedTagPointingToATagAnnotation()
        {
            TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo();
            using (var repo = new Repository(path.RepositoryPath))
            {
                Tag annotatedTag = repo.Tags["e90810b"];
                TagAnnotation annotation = annotatedTag.Annotation;

                Tag tag = repo.ApplyTag("annotatedtag-tag", annotation.Sha, signatureNtk, "A new annotation");
                tag.ShouldNotBeNull();
                tag.IsAnnotated.ShouldBeTrue();
                tag.Annotation.Target.Id.ShouldEqual(annotation.Id);
                tag.Annotation.ShouldNotEqual(annotation);

                repo.Tags[tag.Name].ShouldEqual(tag);
            }
        }
Example #37
0
 public void CreatingATagForAnUnknowReferenceThrows()
 {
     using (var repo = new Repository(BareTestRepoPath))
     {
         Assert.Throws<LibGit2Exception>(() => repo.ApplyTag("mytagnorev", "aaaaaaaaaaa"));
     }
 }
Example #38
0
        public void CreatingATagInAEmptyRepositoryThrows()
        {
            using (var scd = new SelfCleaningDirectory())
            {
                var dir = Repository.Init(scd.DirectoryPath);

                using (var repo = new Repository(dir))
                {
                    Assert.Throws<ApplicationException>(() => repo.ApplyTag("mynotag"));
                }
            }
        }
Example #39
0
        public void CreatingADuplicateTagThrows()
        {
            TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo();
            using (var repo = new Repository(path.RepositoryPath))
            {
                repo.ApplyTag("mytag");

                Assert.Throws<LibGit2Exception>(() => repo.ApplyTag("mytag"));
            }
        }
Example #40
0
 public void CreatingATagForANonCanonicalReferenceThrows()
 {
     using (var repo = new Repository(BareTestRepoPath))
     {
         Assert.Throws<LibGit2Exception>(() => repo.ApplyTag("noncanonicaltarget", "br2"));
     }
 }
Example #41
0
 public void CreatingATagForAnUnknowObjectIdShouldFail()
 {
     using (var path = new TemporaryCloneOfTestRepo())
     using (var repo = new Repository(path.RepositoryPath))
     {
         Assert.Throws<ApplicationException>(() => repo.ApplyTag("mytagnorev", Constants.UnknownSha));
     }
 }
Example #42
0
        public void CreatingADuplicateTagShouldFail()
        {
            using (var path = new TemporaryCloneOfTestRepo())
            using (var repo = new Repository(path.RepositoryPath))
            {
                repo.ApplyTag("mytag");

                Assert.Throws<ApplicationException>(() => repo.ApplyTag("mytag"));
            }
        }
Example #43
0
 public void CreatingATagWithNameMatchingAnAlreadyExistingReferenceHierarchyThrows()
 {
     TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo();
     using (var repo = new Repository(path.RepositoryPath))
     {
         repo.ApplyTag("i/am/deep");
         Assert.Throws<LibGit2Exception>(() => repo.ApplyTag("i/am/deep/rooted"));
         Assert.Throws<LibGit2Exception>(() => repo.ApplyTag("i/am"));
     }
 }
Example #44
0
        public void CanCreateATagPointingToABlob()
        {
            TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo();
            using (var repo = new Repository(path.RepositoryPath))
            {
                Commit headCommit = repo.Head.Tip;
                Blob blob = headCommit.Tree.Blobs.First();

                Tag tag = repo.ApplyTag("blob-tag", blob.Sha);
                Assert.NotNull(tag);
                Assert.False(tag.IsAnnotated);
                Assert.Equal(blob.Id, tag.Target.Id);

                Assert.Equal(blob, repo.Lookup(tag.Target.Id));
                Assert.Equal(tag, repo.Tags[tag.Name]);
            }
        }
Example #45
0
 public void CanCreateAnAnnotatedTagWithAnEmptyMessage()
 {
     TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo();
     using (var repo = new Repository(path.RepositoryPath))
     {
         Tag newTag = repo.ApplyTag("empty-annotated-tag", signatureNtk, string.Empty);
         Assert.NotNull(newTag);
         Assert.True(newTag.IsAnnotated);
         Assert.Equal(string.Empty, newTag.Annotation.Message);
     }
 }
Example #46
0
 public void CreatingATagForAnUnknowReferenceShouldFail()
 {
     using (var path = new TemporaryCloneOfTestRepo())
     using (var repo = new Repository(path.RepositoryPath))
     {
         Assert.Throws<ApplicationException>(() => repo.ApplyTag("mytagnorev", "aaaaaaaaaaa"));
     }
 }
Example #47
0
        public void CanCreateATagPointingToABlob()
        {
            using (var path = new TemporaryCloneOfTestRepo())
            using (var repo = new Repository(path.RepositoryPath))
            {
                var headCommit = (Commit)repo.Head.Tip;
                var blob = headCommit.Tree.Files.First();

                var tag = repo.ApplyTag("blob-tag", blob.Sha);
                tag.ShouldNotBeNull();
                tag.IsAnnotated.ShouldBeFalse();
                tag.Target.Id.ShouldEqual(blob.Id);

                repo.Lookup(tag.Target.Id).ShouldEqual(blob);
                repo.Tags[tag.Name].ShouldEqual(tag);
            }
        }
Example #48
0
        public void CanCreateATagPointingToATree()
        {
            TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo();
            using (var repo = new Repository(path.RepositoryPath))
            {
                Commit headCommit = repo.Head.Tip;
                Tree tree = headCommit.Tree;

                Tag tag = repo.ApplyTag("tree-tag", tree.Sha);
                tag.ShouldNotBeNull();
                tag.IsAnnotated.ShouldBeFalse();
                tag.Target.Id.ShouldEqual(tree.Id);

                repo.Lookup(tag.Target.Id).ShouldEqual(tree);
                repo.Tags[tag.Name].ShouldEqual(tag);
            }
        }
Example #49
0
        public void CanCreateATagPointingToATree()
        {
            using (var path = new TemporaryCloneOfTestRepo())
            using (var repo = new Repository(path.RepositoryPath))
            {
                var headCommit = (Commit)repo.Head.ResolveToDirectReference().Target;
                var tree = headCommit.Tree;

                var tag = repo.ApplyTag("tree-tag", tree.Sha);
                tag.ShouldNotBeNull();
                tag.IsAnnotated.ShouldBeFalse();
                tag.Target.Id.ShouldEqual(tree.Id);

                repo.Lookup(tag.Target.Id).ShouldEqual(tree);
                repo.Tags[tag.Name].ShouldEqual(tag);
            }
        }
Example #50
0
        public void CanCreateATagUsingHead()
        {
            TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo();
            using (var repo = new Repository(path.RepositoryPath))
            {
                Tag tag = repo.ApplyTag("mytag", "HEAD");
                tag.ShouldNotBeNull();

                tag.Target.Id.ShouldEqual(repo.Head.Tip.Id);

                Tag retrievedTag = repo.Tags[tag.CanonicalName];
                tag.ShouldEqual(retrievedTag);
            }
        }
Example #51
0
        public void CanCreateATagForImplicitHead()
        {
            TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo();
            using (var repo = new Repository(path.RepositoryPath))
            {
                Tag tag = repo.ApplyTag("mytag");
                Assert.NotNull(tag);

                Assert.Equal(repo.Head.Tip.Id, tag.Target.Id);

                Tag retrievedTag = repo.Tags[tag.CanonicalName];
                Assert.Equal(retrievedTag, tag);
            }
        }
Example #52
0
        public void CreatingALightweightTagPointingToATagAnnotationGeneratesAnAnnotatedTagReusingThePointedAtTagAnnotation()
        {
            TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo();
            using (var repo = new Repository(path.RepositoryPath))
            {
                Tag annotatedTag = repo.Tags["e90810b"];
                TagAnnotation annotation = annotatedTag.Annotation;

                Tag tag = repo.ApplyTag("lightweight-tag", annotation.Sha);
                tag.ShouldNotBeNull();
                tag.IsAnnotated.ShouldBeTrue();
                tag.Target.Id.ShouldEqual(annotation.Target.Id);
                tag.Annotation.ShouldEqual(annotation);

                repo.Lookup(tag.Annotation.Id).ShouldEqual(annotation);
                repo.Tags[tag.Name].ShouldEqual(tag);
            }
        }
        private static void FeedTheRepository(Repository repo)
        {
            string fullPath = Path.Combine(repo.Info.WorkingDirectory, "a.txt");
            File.WriteAllText(fullPath, "Hello\n");
            repo.Index.Stage(fullPath);
            repo.Commit("Initial commit", Constants.Signature, Constants.Signature);
            repo.ApplyTag("mytag");

            File.AppendAllText(fullPath, "World\n");
            repo.Index.Stage(fullPath);

            Signature shiftedSignature = Constants.Signature.TimeShift(TimeSpan.FromMinutes(1));
            repo.Commit("Update file", shiftedSignature, shiftedSignature);
            repo.CreateBranch("mybranch");

            repo.Checkout("mybranch");

            Assert.False(repo.Index.RetrieveStatus().IsDirty);
        }
Example #54
0
 public void CreatingATagForAnUnknowObjectIdThrows()
 {
     using (var repo = new Repository(BareTestRepoPath))
     {
         Assert.Throws<LibGit2Exception>(() => repo.ApplyTag("mytagnorev", Constants.UnknownSha));
     }
 }
Example #55
0
        public void CreatingATagInAEmptyRepositoryThrows()
        {
            SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
            string dir = Repository.Init(scd.DirectoryPath);

            using (var repo = new Repository(dir))
            {
                Assert.Throws<LibGit2Exception>(() => repo.ApplyTag("mynotag"));
            }
        }
Example #56
0
 public void CreatingATagWithANonValidNameShouldFail()
 {
     using (var repo = new Repository(BareTestRepoPath))
     {
         Assert.Throws<ArgumentException>(() => repo.ApplyTag(""));
         Assert.Throws<LibGit2Exception>(() => repo.ApplyTag(".othertag"));
         Assert.Throws<LibGit2Exception>(() => repo.ApplyTag("other tag"));
         Assert.Throws<LibGit2Exception>(() => repo.ApplyTag("othertag^"));
         Assert.Throws<LibGit2Exception>(() => repo.ApplyTag("other~tag"));
     }
 }
Example #57
0
 public void CreatingATagWithANonValidNameShouldFail()
 {
     using (var path = new TemporaryCloneOfTestRepo())
     using (var repo = new Repository(path.RepositoryPath))
     {
         Assert.Throws<ArgumentException>(() => repo.ApplyTag(""));
         Assert.Throws<ApplicationException>(() => repo.ApplyTag(".othertag"));
         Assert.Throws<ApplicationException>(() => repo.ApplyTag("other tag"));
         Assert.Throws<ApplicationException>(() => repo.ApplyTag("othertag^"));
         Assert.Throws<ApplicationException>(() => repo.ApplyTag("other~tag"));
     }
 }
Example #58
0
        public void CanCreateATagForImplicitHead()
        {
            using (var path = new TemporaryCloneOfTestRepo())
            using (var repo = new Repository(path.RepositoryPath))
            {
                var tag = repo.ApplyTag("mytag");
                tag.ShouldNotBeNull();

                tag.Target.Id.ShouldEqual(repo.Head.Tip.Id);

                var retrievedTag = repo.Tags[tag.CanonicalName];
                tag.ShouldEqual(retrievedTag);
            }
        }
Example #59
0
        public void CanCreateATagUsingHead()
        {
            using (var path = new TemporaryCloneOfTestRepo())
            using (var repo = new Repository(path.RepositoryPath))
            {
                var tag = repo.ApplyTag("mytag", "HEAD");
                tag.ShouldNotBeNull();

                tag.Target.Id.ShouldEqual(repo.Head.ResolveToDirectReference().Target.Id);

                var retrievedTag = repo.Tags[tag.CanonicalName];
                tag.ShouldEqual(retrievedTag);
            }
        }