Пример #1
0
        /// <summary>
        /// New commit bundle needed
        /// </summary>
        private void MenuNewCommitClick(object sender, EventArgs e)
        {
            FormCommit commitForm = new FormCommit(false, "Update");

            commitForm.SetFiles(status.Repo.Commits.Bundle[0]);
            if (commitForm.ShowDialog() == DialogResult.OK)
            {
                // Create a new commit bundle and move selected files to it
                status.Repo.Commits.NewBundle(commitForm.GetDescription(), commitForm.GetFiles());
                CommitsRefresh();
            }
        }
Пример #2
0
        /// <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();
            }
        }
Пример #3
0
        public bool StartCommitDialog(IWin32Window owner, bool showOnlyWhenChanges)
        {
            Func<bool> action = () =>
            {
                using (var form = new FormCommit(this))
                {
                    if (showOnlyWhenChanges)
                        form.ShowDialogWhenChanges(owner);
                    else
                        form.ShowDialog(owner);
                }
                return true;
            };

            return DoActionOnRepo(owner, true, false, PreCommit, PostCommit, action);
        }
Пример #4
0
        public bool StartSquashCommitDialog(IWin32Window owner, GitRevision revision)
        {
            Func<bool> action = () =>
            {
                using (var form = new FormCommit(this, CommitKind.Squash, revision))
                {
                    form.ShowDialog(owner);
                }
                return true;
            };

            return DoActionOnRepo(action);
        }
Пример #5
0
        /// <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();
            }
        }
Пример #6
0
        /// <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();
            }
        }
Пример #7
0
 /// <summary>
 /// New commit bundle needed
 /// </summary>
 private void MenuNewCommitClick(object sender, EventArgs e)
 {
     FormCommit commitForm = new FormCommit(false, "Update");
     commitForm.SetFiles(status.Repo.Commits.Bundle[0]);
     if (commitForm.ShowDialog() == DialogResult.OK)
     {
         // Create a new commit bundle and move selected files to it
         status.Repo.Commits.NewBundle(commitForm.GetDescription(), commitForm.GetFiles());
         CommitsRefresh();
     }
 }
Пример #8
0
        /// <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();
            }
        }
Пример #9
0
        /// <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();
            }
        }