/// <summary> /// Delete empty commit bundle. /// It is already verified that the commit bundle (sent in the tag) is empty. /// </summary> private void MenuDeleteEmptyClick(object sender, EventArgs e) { // Recover the commit class bundle that was selected ClassCommit c = (sender as ToolStripMenuItem).Tag as ClassCommit; status.Repo.Commits.Bundle.Remove(c); CommitsRefresh(); }
/// <summary> /// Return the commit bundle for the merge operation /// </summary> private ClassCommit GetMergeCommitBundle() { string desc = File.ReadAllText(status.pathToMergeMsg); ClassCommit c = new ClassCommit(desc); // Merge commits all affected files, we can't do merge commit with a partial file list List <string> files = status.GetFiles(); files = files.Where(s => (status.Xcode(s) == 'M') || (status.Xcode(s) == 'U')).ToList(); c.AddFiles(files); return(c); }
/// <summary> /// Edit selected commit bundle /// </summary> private void MenuEditCommitClick(object sender, EventArgs e) { // Recover the commit class bundle that was selected ClassCommit c = (sender as ToolStripMenuItem).Tag as ClassCommit; FormCommit commitForm = new FormCommit(false, c.Description); commitForm.SetFiles(c); if (commitForm.ShowDialog() == DialogResult.OK) { // Update the description text and the list of files c.Description = commitForm.GetDescription(); // Renew only files that were left checked, the rest add back to the Default commit List <string> removedFiles = c.Renew(commitForm.GetFiles()); status.Repo.Commits.Bundle[0].AddFiles(removedFiles); CommitsRefresh(); } }
/// <summary> /// Edit merge commit description /// </summary> private void MenuEditCommitMergeClick(object sender, EventArgs e) { try { ClassCommit c = GetMergeCommitBundle(); FormCommitMerge commitMerge = new FormCommitMerge(false, c.Description); commitMerge.SetFiles(c); if (commitMerge.ShowDialog() == DialogResult.OK) { // Overwrite default merge message file with our updated text File.WriteAllText(status.pathToMergeMsg, commitMerge.GetDescription()); App.DoRefresh(); } } catch (Exception ex) { App.PrintStatusMessage(ex.Message, MessageType.Error); } }
/// <summary> /// Submit merge /// </summary> private void MenuSubmitMergeClick(object sender, EventArgs e) { try { ClassCommit c = GetMergeCommitBundle(); FormCommitMerge commitMerge = new FormCommitMerge(true, c.Description); commitMerge.SetFiles(c); if (commitMerge.ShowDialog() == DialogResult.OK) { if (status.Repo.GitCommit("-F \"" + status.pathToMergeMsg + "\"", false, new List <string>())) { App.DoRefresh(); } } } catch (Exception ex) { App.PrintStatusMessage(ex.Message, MessageType.Error); } }
/// <summary> /// Handler for the drop portion of drag and drop. User dropped one or more names to the commit pane. /// The names may be files originating from the left pane, or from an external application like explorer. /// Those even don't have to be files but simply names of git objects (like _deleted_ files to be staged) /// </summary> private void TreeCommitsDragDrop(object sender, DragEventArgs e) { e.Effect = DragDropEffects.None; string[] droppedList = (string[])e.Data.GetData(DataFormats.FileDrop); // Files can come from anywhere. Prune those that are not from this repo. List <string> files = (from file in droppedList.ToList() where (file.Length > status.Repo.Path.Length) && file.StartsWith(status.Repo.Path) select file.Substring(status.Repo.Path.Length + 1)).ToList(); DoDropFiles(status, files.ToList()); // Find which node the files have been dropped to, so we can // move them to the selected commit bundle Point pt = ((TreeView)sender).PointToClient(new Point(e.X, e.Y)); TreeNode destNode = ((TreeView)sender).GetNodeAt(pt); if (destNode != null) { // Destination node could be a bundle root, or a file node (with a parent root) ClassCommit bundle = null; if (destNode.Tag is ClassCommit) { bundle = destNode.Tag as ClassCommit; } if (destNode.Tag is string && destNode.Tag.ToString() != "root") { bundle = destNode.Parent.Tag as ClassCommit; } // If we have a valid class bundle where the files should be moved to, move them if (bundle != null) { List <string> list = files.Where(s => status.IsMarked(s)).ToList(); App.Repos.Current.Commits.MoveOrAdd(bundle, list); } } App.DoRefresh(); }
/// <summary> /// Submit selected files within a changelist /// Two versions of submit are used: one for the ordinary submit and the /// other one for the submit when the operation will be a merge. /// </summary> private void MenuSubmitClick(object sender, EventArgs e) { // If the right-click selected a changelist bundle, submit it // All the files that were selected should be checked in the list ClassCommit c; if ((sender as ToolStripMenuItem).Tag is ClassCommit) { c = (sender as ToolStripMenuItem).Tag as ClassCommit; } else { // If the right-click selected files, gather all files selected // into a pseudo-bundle to submit c = new ClassCommit("ad-hoc"); List <string> files = (from n in treeCommits.SelectedNodes where status.IsMarked(n.Tag.ToString()) select n.Tag.ToString()).ToList(); c.AddFiles(files); } FormCommit commitForm = new FormCommit(true, c.Description); commitForm.SetFiles(c); if (commitForm.ShowDialog() == DialogResult.OK) { // Get the files checked for commit List <string> final = commitForm.GetFiles(); // Unless we are amending, there should be at least one file selected if (final.Count > 0 || commitForm.GetCheckAmend()) { // Create a temp file to store our commit message string tempFile = Path.GetTempFileName(); File.WriteAllText(tempFile, commitForm.GetDescription()); // If the current repo has only one commit bundle, we don't need to specify each file // but we can simply commit all files in index unless the user checked off some of them if ((status.Repo.Commits.Bundle.Count() == 1) && (status.Repo.Commits.Bundle[0].Files.Count == final.Count)) { final = new List <string>(); } // Form the final command with the description file and an optional amend if (status.Repo.GitCommit("-F \"" + tempFile + "\"", commitForm.GetCheckAmend(), final)) { File.Delete(tempFile); // If the current commit bundle is not default, remove it. Refresh which follows // will reset all files which were _not_ submitted as part of this change to be // moved to the default changelist. if (!c.IsDefault) { App.Repos.Current.Commits.Bundle.Remove(c); } else { c.Description = "Default"; } // Occasionally, run the garbage collection on the loose objects in the repo. // On average, do it once after every 10 commits. This is statistical and not // guaranteed, but it is very likely that it will prevent accumulation of loose // objects in the long run and the user will not have to worry about it at all. Random random = new Random(); if (random.Next(0, 100) <= 10) { App.PrintStatusMessage("Running garbage collection, please wait...", MessageType.General); App.Repos.Current.RunCmd("gc"); } } } App.DoRefresh(); } }
/// <summary> /// Submit selected files within a changelist /// Two versions of submit are used: one for the ordinary submit and the /// other one for the submit when the operation will be a merge. /// </summary> private void MenuSubmitClick(object sender, EventArgs e) { // If the right-click selected a changelist bundle, submit it // All the files that were selected should be checked in the list ClassCommit c; if ((sender as ToolStripMenuItem).Tag is ClassCommit) c = (sender as ToolStripMenuItem).Tag as ClassCommit; else { // If the right-click selected files, gather all files selected // into a pseudo-bundle to submit c = new ClassCommit("ad-hoc"); List<string> files = (from n in treeCommits.SelectedNodes where status.IsMarked(n.Tag.ToString()) select n.Tag.ToString()).ToList(); c.AddFiles(files); } FormCommit commitForm = new FormCommit(true, c.Description); commitForm.SetFiles(c); if (commitForm.ShowDialog() == DialogResult.OK) { // Get the files checked for commit List<string> final = commitForm.GetFiles(); // Unless we are amending, there should be at least one file selected if (final.Count > 0 || commitForm.GetCheckAmend()) { // Create a temp file to store our commit message string tempFile = Path.GetTempFileName(); File.WriteAllText(tempFile, commitForm.GetDescription()); // If the current repo has only one commit bundle, we don't need to specify each file // but we can simply commit all files in index if (status.Repo.Commits.Bundle.Count() == 1) final = new List<string>(); // Form the final command with the description file and an optional amend if (status.Repo.GitCommit("-F \"" + tempFile + "\"", commitForm.GetCheckAmend(), final)) { File.Delete(tempFile); // If the current commit bundle is not default, remove it. Refresh which follows // will reset all files which were _not_ submitted as part of this change to be // moved to the default changelist. if (!c.IsDefault) App.Repos.Current.Commits.Bundle.Remove(c); else c.Description = "Default"; // Occasionally, run the garbage collection on the loose objects in the repo. // On average, do it once after every 10 commits. This is statistical and not // guaranteed, but it is very likely that it will prevent accumulation of loose // objects in the long run and the user will not have to worry about it at all. Random random = new Random(); if (random.Next(0, 100) <= 10) { App.PrintStatusMessage("Running garbage collection, please wait...", MessageType.General); App.Repos.Current.RunCmd("gc"); } } } App.DoRefresh(); } }
/// <summary> /// Return the commit bundle for the merge operation /// </summary> private ClassCommit GetMergeCommitBundle() { string desc = File.ReadAllText(status.pathToMergeMsg); ClassCommit c = new ClassCommit(desc); // Merge commits all affected files, we can't do merge commit with a partial file list List<string> files = status.GetFiles(); files = files.Where(s => (status.Xcode(s) == 'M') || (status.Xcode(s) == 'U')).ToList(); c.AddFiles(files); return c; }
/// <summary> /// Submit selected files within a changelist /// </summary> private void MenuSubmitClick(object sender, EventArgs e) { // If the right-click selected a changelist bundle, submit it // All the files that were selected should be checked in the list ClassCommit c; if ((sender as ToolStripMenuItem).Tag is ClassCommit) c = (sender as ToolStripMenuItem).Tag as ClassCommit; else { // If the right-click selected files, gather all files selected // into a pseudo-bundle to submit c = new ClassCommit("ad-hoc"); List<string> files = (from n in treeCommits.SelectedNodes where Status.IsMarked(n.Tag.ToString()) select n.Tag.ToString()).ToList(); c.AddFiles(files); } FormCommit commitForm = new FormCommit(true, c.Description); commitForm.SetFiles(c); if (commitForm.ShowDialog() == DialogResult.OK) { // Get the files checked for commit List<string> final = commitForm.GetFiles(); // Unless we are amending, there should be at least one file selected if (final.Count > 0 || commitForm.GetCheckAmend()) { // Create a temp file to store our commit message string tempFile = Path.GetTempFileName(); File.WriteAllText(tempFile, commitForm.GetDescription()); // Form the final command with the description file and an optional amend Status.Repo.GitCommit("-F \"" + tempFile + "\"", commitForm.GetCheckAmend(), final); File.Delete(tempFile); // If the current commit bundle is not default, remove it. Refresh which follows // will reset all files which were _not_ submitted as part of this change to be // moved to the default changelist. if (!c.IsDefault) App.Repos.Current.Commits.Bundle.Remove(c); else c.Description = "Default"; } App.DoRefresh(); } }