/// <summary> /// Refresh the tree view of branches /// </summary> public void BranchesRefresh() { // Use predefined [0] for local and [1] for remote branches treeBranches.Nodes[0].Nodes.Clear(); treeBranches.Nodes[1].Nodes.Clear(); if (App.Repos.Current != null) { ClassBranches branches = App.Repos.Current.Branches; branches.Refresh(); // Add all local branches to the tree foreach (string s in branches.Local) { TreeNode tn = new TreeNode(s, (int)BranchIcons.BranchIdle, (int)BranchIcons.BranchIdle); tn.Tag = s; if (s == branches.Current) { tn.SelectedImageIndex = tn.ImageIndex = (int)BranchIcons.BranchSelected; } treeBranches.Nodes[0].Nodes.Add(tn); } // Add all remote branches to the tree foreach (string s in branches.Remote) { TreeNode tn = new TreeNode(s, (int)BranchIcons.BranchIdle, (int)BranchIcons.BranchIdle); tn.Tag = s; treeBranches.Nodes[1].Nodes.Add(tn); } } // By default, expand branches treeBranches.ExpandAll(); }
/// <summary> /// Builds ands returns a context menu for branches /// </summary> public ToolStripItemCollection GetContextMenu(ToolStrip owner) { // Menus are set in this order: // [0] New... -> always open a dialog // [1] Delete... -> always open a dialog // [2] Switch to -> dialog or switch: local branches only, different from current // [3] Merge with -> dialog or merge: branch different from current ToolStripMenuItem mNew = new ToolStripMenuItem("New...", null, MenuNewBranchClick); ToolStripMenuItem mDelete = new ToolStripMenuItem("Delete...", null, MenuDeleteBranchClick); ToolStripMenuItem mSwitchTo = new ToolStripMenuItem("Switch to...", null, MenuSwitchClick); ToolStripMenuItem mMergeWith = new ToolStripMenuItem("Merge with...", null, MenuMergeClick); if (App.Repos.Current != null) { ClassBranches branches = App.Repos.Current.Branches; string sel = GetSelectedBranch(); if (sel != null) { if (sel != branches.Current && branches.Local.IndexOf(sel) >= 0) { mSwitchTo = new ToolStripMenuItem("Switch to " + sel, null, TreeBranchesDoubleClick); } if (sel != branches.Current && (branches.Local.IndexOf(sel) >= 0 || branches.Remote.IndexOf(sel) >= 0)) { mMergeWith = new ToolStripMenuItem("Merge with " + sel, null, MenuMergeClick); } } else { mDelete.Enabled = mSwitchTo.Enabled = mMergeWith.Enabled = false; } } else { mNew.Enabled = mDelete.Enabled = mSwitchTo.Enabled = mMergeWith.Enabled = false; } ToolStripItemCollection menu = new ToolStripItemCollection(owner, new ToolStripItem[] { mNew, mDelete, mSwitchTo, mMergeWith }); return(menu); }
/// <summary> /// Fills in the list of revisions and changes to the repository /// </summary> public void RevlistRefresh() { // Clear the current lists in preparation for the refresh listRev.BeginUpdate(); listRev.Items.Clear(); btBranch.DropDownItems.Clear(); labelLogBranch.Text = ""; if (App.Repos.Current != null) { ClassBranches branches = App.Repos.Current.Branches; // Initialize our tracking branch if (!branches.Local.Contains(logBranch) && !branches.Remote.Contains(logBranch)) { logBranch = branches.Current; } // TODO: history for arbitrary branch is broken. For now, we will only show the current branch logBranch = branches.Current; // If the repo does not have a branch at all (new repo that was just initialized), exit if (string.IsNullOrEmpty(logBranch)) { goto End; } if (logBranch != branches.Current) { labelLogBranch.Text = String.Format(" (Branch: \"{0}\")", logBranch); } // Populate the drop-down list of branches: local and remote) foreach (var branch in branches.Local) { btBranch.DropDownItems.Add(new ToolStripMenuItem(branch, null, LogBranchChanged)); } foreach (var branch in branches.Remote) { btBranch.DropDownItems.Add(new ToolStripMenuItem(branch, null, LogBranchChanged)); } // Get the list of revisions by running a git command StringBuilder cmd = new StringBuilder("log "); // If we are filtering, append the filter string if (btClearFilter.Enabled) { cmd.Append(formFilter.gitFilter); } cmd.Append(" --pretty=format:"); // Start formatting section cmd.Append("%h%x09"); // Abbreviated commit hash cmd.Append("%ct%x09"); // Committing time, UNIX-style cmd.Append("%an%x09"); // Author name cmd.Append("%s"); // Subject // Add the branch name using only the first token in order to handle links (br -> br) //string branchStr = logBranch; //ExecResult result; //if(logBranch!="(no branch)") //{ // branchStr = logBranch.Split(' ').First(); // if (branchStr != "master") // { // // Get the tracking branch for this branch // //result = App.Repos.Current.Run("config --get branch." + logBranch + ".merge"); // //if (result.Success()) // // cmd.Append(" " + result + ".."); // //else // cmd.Append(" .." + branchStr); // } // else // cmd.Append(" " + branchStr); //} // Limit the number of commits to show if (Properties.Settings.Default.commitsRetrieveAll == false) { cmd.Append(" -" + Properties.Settings.Default.commitsRetrieveLast); } ExecResult result = App.Repos.Current.Run(cmd.ToString()); if (result.Success()) { UpdateList(listRev, result.stdout, false); } } End: listRev.EndUpdate(); }