internal void Refresh(bool reload)
 {
     tracker.Refresh();
     if (tracker.HasGitRepository)
     {
         tracker.RepositoryGraph.IsSimplified = showSimplifiedView;
     }
     GraphChanged(this, reload ? new EventArgs() : null);             // use non-null to force reload
 }
        public void GetFileStatusTest()
        {
            GitFileStatusTracker.Init(tempFolder);
            GitFileStatusTracker tracker = new GitFileStatusTracker(tempFolder);

            File.WriteAllLines(tempFile, lines);
            Assert.AreEqual(GitFileStatus.New, tracker.GetFileStatus(tempFile));

            tracker.StageFile(tempFile);
            tracker.Refresh();
            Assert.AreEqual(GitFileStatus.Added, tracker.GetFileStatus(tempFile));

            tracker.UnStageFile(tempFile);
            tracker.Refresh();
            Assert.AreEqual(GitFileStatus.New, tracker.GetFileStatus(tempFile));

            tracker.StageFile(tempFile);
            tracker.Refresh();
            Assert.AreEqual(GitFileStatus.Added, tracker.GetFileStatus(tempFile));

            tracker.Commit("中文 1čtestč");
            Assert.AreEqual(GitFileStatus.Tracked, tracker.GetFileStatus(tempFile));

            File.WriteAllText(tempFile, "changed text");
            tracker.Refresh();
            Assert.AreEqual(GitFileStatus.Modified, tracker.GetFileStatus(tempFile));

            tracker.StageFile(tempFile);
            tracker.Refresh();
            Assert.AreEqual(GitFileStatus.Staged, tracker.GetFileStatus(tempFile));

            tracker.UnStageFile(tempFile);
            tracker.Refresh();
            Assert.AreEqual(GitFileStatus.Modified, tracker.GetFileStatus(tempFile));

            File.Delete(tempFile);
            tracker.Refresh();
            Assert.AreEqual(GitFileStatus.Deleted, tracker.GetFileStatus(tempFile));

            tracker.StageFile(tempFile);
            tracker.Refresh();
            Assert.AreEqual(GitFileStatus.Removed, tracker.GetFileStatus(tempFile));

            tracker.UnStageFile(tempFile);
            tracker.Refresh();
            Assert.AreEqual(GitFileStatus.Deleted, tracker.GetFileStatus(tempFile));
        }
Example #3
0
        public void FileNameCaseTest()
        {
            GitFileStatusTracker.Init(tempFolder);
            File.WriteAllLines(tempFile, lines);

            GitFileStatusTracker tracker = new GitFileStatusTracker(tempFolder);

            tracker.StageFile(tempFile);

            tracker.Commit("test message");
            Assert.IsTrue(tracker.LastCommitMessage.StartsWith("test message"));
            tempFile = tempFile.Replace("test", "TEST");
            File.WriteAllText(tempFile, "changed text");
            tracker.Refresh();
            Assert.AreEqual(GitFileStatus.Modified, tracker.GetFileStatus(tempFile));
        }
        public void FileNameCaseTest()
        {
            GitFileStatusTracker.Init(tempFolder);
            File.WriteAllLines(tempFile, lines);

            GitFileStatusTracker tracker = new GitFileStatusTracker(tempFolder);

            tracker.StageFile(tempFile);

            tracker.Commit("test message");
            Assert.IsTrue(tracker.LastCommitMessage.StartsWith("test message"));
            tempFile = tempFile.Replace("test", "TEST");
            File.WriteAllText(tempFile, "changed text");
            tracker.Refresh();
            //This test fails all cases because status check uses ngit, never git.exe
            //Assert.AreEqual(GitFileStatus.Modified, tracker.GetFileStatus(tempFile));

            var file = tracker.ChangedFiles.First();

            Assert.AreEqual(GitFileStatus.Modified, file.Status);
        }
        public void GetChangedFilesTest()
        {
            GitFileStatusTracker.Init(tempFolder);

            File.WriteAllLines(tempFile, lines);

            GitFileStatusTracker tracker = new GitFileStatusTracker(tempFolder);

            Assert.AreEqual(GitFileStatus.New, tracker.ChangedFiles.ToList()[0].Status);

            tracker.StageFile(tempFile);
            Assert.AreEqual(GitFileStatus.Added, tracker.ChangedFiles.ToList()[0].Status);

            tracker.Commit("中文 1čtestč");

            Assert.AreEqual(0, tracker.ChangedFiles.Count());

            File.WriteAllText(tempFile, "a");
            tracker.Refresh();
            Assert.AreEqual(GitFileStatus.Modified, tracker.ChangedFiles.ToList()[0].Status);

            tracker.StageFile(tempFile);
            Assert.AreEqual(GitFileStatus.Staged, tracker.ChangedFiles.ToList()[0].Status);
        }
Example #6
0
        internal void OnCommit()
        {
            if (tracker == null)
            {
                return;
            }

            try
            {
                service.NoRefresh = true;

                if (chkNewBranch.IsChecked == true)
                {
                    if (string.IsNullOrWhiteSpace(txtNewBranch.Text))
                    {
                        MessageBox.Show("Please enter new branch name.", "Commit",
                                        MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        txtNewBranch.Focus();
                        return;
                    }
                    tracker.CheckOutBranch(txtNewBranch.Text, true);
                }

                var isAmend = chkAmend.IsChecked == true;

                if (string.IsNullOrWhiteSpace(Comments))
                {
                    MessageBox.Show("Please enter comments for the commit.", "Commit",
                                    MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return;
                }

                ShowStatusMessage("Staging files ...");
                StageSelectedFiles();

                if (!isAmend)
                {
                    tracker.Refresh();
                    bool hasStaged = tracker == null ? false :
                                     tracker.ChangedFiles.Any(f => f.IsStaged);
                    if (!hasStaged)
                    {
                        MessageBox.Show("No file has been selected/staged for commit.", "Commit",
                                        MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        return;
                    }
                }
                else
                {
                    const string amendMsg = @"You are about to amend a commit that has tags or remotes, which could cause issues in local and remote repositories.

Are you sure you want to continue?";

                    if (tracker.CurrentCommitHasRefs() && MessageBox.Show(amendMsg, "Amend Last Commit",
                                                                          MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
                    {
                        return;
                    }
                }

                var id = tracker.Commit(Comments, isAmend, chkSignOff.IsChecked == true);
                ShowStatusMessage("Commit successfully. Commit Hash: " + id);
                ClearUI();

                tracker.Refresh();
                if (tracker.ChangedFiles.Count() == 0)
                {
                    HistoryViewCommands.CloseCommitDetails.Execute("PendingChanges", this);
                }
                service.NoRefresh = false;
                HistoryViewCommands.RefreshGraph.Execute(null, this);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                ShowStatusMessage(ex.Message);
            }
        }
 internal void RefreshToolWindows()
 {
     tracker.Refresh();
     GraphChanged(this, null);
 }
Example #8
0
        internal async void OnCommit()
        {
            if (tracker == null)
            {
                return;
            }

            try
            {
                if (chkNewBranch.IsChecked == true)
                {
                    if (string.IsNullOrWhiteSpace(txtNewBranch.Text))
                    {
                        MessageBox.Show("Please enter new branch name.", "Commit",
                                        MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        txtNewBranch.Focus();
                        return;
                    }
                    tracker.CheckOutBranch(txtNewBranch.Text, true);
                }

                var isAmend = chkAmend.IsChecked == true;

                if (string.IsNullOrWhiteSpace(Comments))
                {
                    Comments = tracker.GetCommitTemplate();
                    if (string.IsNullOrWhiteSpace(Comments))
                    {
                        MessageBox.Show("Please enter comments for the commit.", "Commit",
                                        MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    }
                    return;
                }

                var changed = this.listUnstaged.ItemsSource.Cast <GitFile>();
                var count   = changed.Count();

                ShowStatusMessage("Staging files ...");

                if (!isAmend)
                {
                    tracker.Refresh();
                    bool hasStaged = tracker == null ? false :
                                     tracker.ChangedFiles.Any(f => f.X != ' ') || count > 0;

                    if (!hasStaged)
                    {
                        MessageBox.Show("No file has been selected/staged for commit.", "Commit",
                                        MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        return;
                    }
                }
                else
                {
                    const string amendMsg = @"You are about to amend a commit that has tags or remotes, which could cause issues in local and remote repositories.

Are you sure you want to continue?";

                    if (tracker.CurrentCommitHasRefs() && MessageBox.Show(amendMsg, "Amend Last Commit",
                                                                          MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
                    {
                        return;
                    }
                }

                service.NoRefresh = true;
                int  i       = 1;
                bool signoff = chkSignOff.IsChecked == true;

                await Task.Run(() =>
                {
                    if (changed.Count() > 0 && listStaged.Items.Count == 0)
                    {
                        // auto stage all changes if nothing is staged
                        foreach (var item in changed)
                        {
                            tracker.StageFile(item.FileName);
                            ShowStatusMessage(string.Format("Staged ({0}/{1}): {2}", i++, count, item.FileName));
                        }
                    }

                    var id = tracker.Commit(Comments, isAmend, signoff);
                    ShowStatusMessage("Commit successfully. Commit Hash: " + id);
                });

                ClearUI();
                Comments = tracker.GetCommitTemplate();
                tracker.Refresh();
                if (tracker.ChangedFiles.Count() == 0)
                {
                    HistoryViewCommands.CloseCommitDetails.Execute("PendingChanges", this);
                }
                service.NoRefresh = false;
                HistoryViewCommands.RefreshGraph.Execute(null, this);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                ShowStatusMessage(ex.Message);
            }
        }