Ejemplo n.º 1
0
        private string GetBranchesWhichContainsThisCommit(string revision, bool showBranchesAsLinks)
        {
            const string remotesPrefix = "remotes/";
            // Include local branches if explicitly requested or when needed to decide whether to show remotes
            bool getLocal = Settings.CommitInfoShowContainedInBranchesLocal ||
                            Settings.CommitInfoShowContainedInBranchesRemoteIfNoLocal;
            // Include remote branches if requested
            bool getRemote = Settings.CommitInfoShowContainedInBranchesRemote ||
                             Settings.CommitInfoShowContainedInBranchesRemoteIfNoLocal;
            var  branches    = CommitInformation.GetAllBranchesWhichContainGivenCommit(Module, revision, getLocal, getRemote);
            var  links       = new List <string>();
            bool allowLocal  = Settings.CommitInfoShowContainedInBranchesLocal;
            bool allowRemote = getRemote;

            foreach (var branch in branches)
            {
                string noPrefixBranch = branch;
                bool   branchIsLocal;
                if (getLocal && getRemote)
                {
                    // "git branch -a" prefixes remote branches with "remotes/"
                    // It is possible to create a local branch named "remotes/origin/something"
                    // so this check is not 100% reliable.
                    // This shouldn't be a big problem if we're only displaying information.
                    branchIsLocal = !branch.StartsWith(remotesPrefix);
                    if (!branchIsLocal)
                    {
                        noPrefixBranch = branch.Substring(remotesPrefix.Length);
                    }
                }
                else
                {
                    branchIsLocal = !getRemote;
                }

                if ((branchIsLocal && allowLocal) || (!branchIsLocal && allowRemote))
                {
                    string branchText;
                    if (showBranchesAsLinks)
                    {
                        branchText = LinkFactory.CreateBranchLink(noPrefixBranch);
                    }
                    else
                    {
                        branchText = WebUtility.HtmlEncode(noPrefixBranch);
                    }
                    links.Add(branchText);
                }

                if (branchIsLocal && Settings.CommitInfoShowContainedInBranchesRemoteIfNoLocal)
                {
                    allowRemote = false;
                }
            }
            if (links.Any())
            {
                return(Environment.NewLine + WebUtility.HtmlEncode(containedInBranches.Text) + " " + links.Join(", "));
            }
            return(Environment.NewLine + WebUtility.HtmlEncode(containedInNoBranch.Text));
        }
Ejemplo n.º 2
0
        public void ParseGoToBranchLink()
        {
            var linkFactory = new LinkFactory();

            linkFactory.CreateBranchLink("master");
            string expected = "gitext://gotobranch/master";
            string actual   = linkFactory.ParseLink("master#gitext://gotobranch/master");

            Assert.That(actual, Is.EqualTo(expected));
        }
Ejemplo n.º 3
0
        public void ParseGoToBranchLinkWithHash()
        {
            var linkFactory = new LinkFactory();

            linkFactory.CreateBranchLink("PR#23");
            string expected = "gitext://gotobranch/PR#23";
            string actual   = linkFactory.ParseLink("PR#23#gitext://gotobranch/PR#23");

            Assert.That(actual, Is.EqualTo(expected));
        }
Ejemplo n.º 4
0
        public void ParseGoToBranchLinkWithHash()
        {
            var linkFactory = new LinkFactory();

            linkFactory.CreateBranchLink("PR#23");
            string expected = "gitext://gotobranch/PR#23";

            Assert.True(linkFactory.ParseLink("PR#23#gitext://gotobranch/PR#23", out var actualUri));
            Assert.That(actualUri.AbsoluteUri, Is.EqualTo(expected));
        }