public void GetAllBranchesWhichContainGivenCommitTestReturnsEmptyList() { var actualResult = CommitInformation.GetAllBranchesWhichContainGivenCommit(new GitModule(""), "fakesha1", false, false); Assert.IsNotNull(actualResult); Assert.IsTrue(!actualResult.Any()); }
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)); }
private string GetBranchesWhichContainsThisCommit(string revision) { 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(revision, getLocal, getRemote); var branchString = ""; 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)) { if (branchString != string.Empty) { branchString += ", "; } branchString += noPrefixBranch; } if (branchIsLocal && Settings.CommitInfoShowContainedInBranchesRemoteIfNoLocal) { allowRemote = false; } } if (branchString != string.Empty) { return(Environment.NewLine + HttpUtility.HtmlEncode(containedInBranches.Text + " " + branchString)); } return(Environment.NewLine + HttpUtility.HtmlEncode(containedInNoBranch.Text)); }
private IList <string> getContainsRevisionBranches() { if (_containsRevisionBranches == null) { _containsRevisionBranches = CommitInformation .GetAllBranchesWhichContainGivenCommit(Module, _containRevison, LocalBranch.Checked, !LocalBranch.Checked) .Where(a => !a.Equals("(no branch)", StringComparison.OrdinalIgnoreCase)).ToList(); } return(_containsRevisionBranches); }
private void Initialize() { Branches.DisplayMember = "Name"; if (_containRevison == null) { if (LocalBranch.Checked) { Branches.DataSource = GitModule.Current.GetHeads(false).Select(a => a.Name).ToList(); } else { var heads = GitModule.Current.GetHeads(true, true); var remoteHeads = new List <GitHead>(); foreach (var head in heads) { if (head.IsRemote && !head.IsTag) { remoteHeads.Add(head); } } Branches.DataSource = remoteHeads.Select(a => a.Name).ToList(); } } else { var branches = CommitInformation .GetAllBranchesWhichContainGivenCommit(_containRevison, LocalBranch.Checked, !LocalBranch.Checked) .Where(a => !a.Equals("(no branch)", StringComparison.OrdinalIgnoreCase)); Branches.DataSource = branches.ToList(); } Branches.Text = null; remoteOptionsPanel.Visible = Remotebranch.Checked; rbCreateBranch.Checked = Settings.CreateLocalBranchForRemote; }