public void AmendCommitTest() { GitFileStatusTracker.Init(tempFolder); File.WriteAllLines(tempFile, lines); GitFileStatusTracker tracker = new GitFileStatusTracker(tempFolder); tracker.StageFile(tempFile); tracker.Commit("中文 1čtestč"); Assert.IsTrue(tracker.LastCommitMessage.StartsWith("中文 1čtestč")); File.WriteAllText(tempFile, "changed text"); tracker.StageFile(tempFile); tracker.Commit("new message", true); Assert.IsTrue(tracker.LastCommitMessage.StartsWith("new message")); }
public void LastCommitMessageTest() { GitFileStatusTracker.Init(tempFolder); File.WriteAllLines(tempFile, lines); GitFileStatusTracker tracker = new GitFileStatusTracker(tempFolder); tracker.StageFile(tempFile); tracker.Commit("中文 1čtestč"); Assert.IsTrue(tracker.LastCommitMessage.StartsWith("中文 1čtestč")); }
public void DiffFileTest() { GitFileStatusTracker.Init(tempFolder); File.WriteAllLines(tempFile, lines); GitFileStatusTracker tracker = new GitFileStatusTracker(tempFolder); tracker.StageFile(tempFile); tracker.Commit("test message"); File.WriteAllText(tempFile, "changed text"); var diffFile = tracker.DiffFile(tempFile); var diff = File.ReadAllText(diffFile); Console.WriteLine(diff); Assert.IsTrue(diff.Contains("@@ -1,3 +1 @@")); }
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 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)); }
public void SaveFileFromRepositoryTest() { GitFileStatusTracker.Init(tempFolder); File.WriteAllLines(tempFile, lines); GitFileStatusTracker tracker = new GitFileStatusTracker(tempFolder); tracker.StageFile(tempFile); tracker.Commit("test"); tracker.SaveFileFromRepository(tempFile, tempFile + ".bk"); var newlines = File.ReadAllLines(tempFile + ".bk"); Assert.AreEqual(lines[0], newlines[0]); Assert.AreEqual(lines[1], newlines[1]); Assert.AreEqual(lines[2], newlines[2]); }
public void CheckOutFileTest() { GitFileStatusTracker.Init(tempFolder); File.WriteAllLines(tempFile, lines); GitFileStatusTracker tracker = new GitFileStatusTracker(tempFolder); tracker.StageFile(tempFile); tracker.Commit("test"); File.WriteAllText(tempFile, "changed text"); tracker.CheckOutFile(tempFile); var newlines = File.ReadAllLines(tempFile); Assert.AreEqual(lines[0], newlines[0]); Assert.AreEqual(lines[1], newlines[1]); Assert.AreEqual(lines[2], newlines[2]); }
public void GetBranchTest() { GitFileStatusTracker.Init(tempFolder); File.WriteAllLines(tempFile, lines); GitFileStatusTracker tracker = new GitFileStatusTracker(tempFolder); tracker.StageFile(tempFile); Assert.AreEqual("master", tracker.CurrentBranch); tracker.Commit("test message"); Assert.AreEqual("master", tracker.CurrentBranch); tempFile = tempFile.Replace("test", "TEST"); File.WriteAllText(tempFile, "changed text"); tracker.CheckOutBranch("dev", true); Assert.AreEqual("dev", tracker.CurrentBranch); }
private void btnPendingChanges_Click(object sender, RoutedEventArgs e) { 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 (HasComments() && StageSelectedFiles(!isAmend)) { ShowStatusMessage("Committing ..."); var id = tracker.Commit(Comments, isAmend, chkSignOff.IsChecked == true); ShowStatusMessage("Commit successfully. Commit Hash: " + id); ClearUI(); HistoryViewCommands.CloseCommitDetails.Execute(this, null); HistoryViewCommands.RefreshGraph.Execute(this, null); } service.NoRefresh = false; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation); ShowStatusMessage(ex.Message); } }
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); }
internal void Commit() { service.NoRefresh = true; if (HasComments() && StageSelectedFiles()) { try { ShowStatusMessage("Committing ..."); var id = tracker.Commit(Comments); ShowStatusMessage("Commit successfully. Commit Hash: " + id); ClearUI(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation); ShowStatusMessage(ex.Message); } } service.NoRefresh = false; //service.lastTimeRefresh = DateTime.Now; //service.NodesGlyphsDirty = true; // force refresh }
public void GetFileContentTestNegative() { GitFileStatusTracker tracker = new GitFileStatusTracker(tempFolder); var fileContent = tracker.GetFileContent(tempFile + ".bad"); Assert.IsNull(fileContent); GitFileStatusTracker.Init(tempFolder); File.WriteAllLines(tempFile, lines); tracker = new GitFileStatusTracker(tempFolder); fileContent = tracker.GetFileContent(tempFile + ".bad"); Assert.IsNull(fileContent); tracker.StageFile(tempFile); fileContent = tracker.GetFileContent(tempFile + ".bad"); Assert.IsNull(fileContent); tracker.Commit("中文 1čtestč"); fileContent = tracker.GetFileContent(tempFile + ".bad"); Assert.IsNull(fileContent); }
public void GetFileContentTest() { GitFileStatusTracker.Init(tempFolder); File.WriteAllLines(tempFile, lines); GitFileStatusTracker tracker = new GitFileStatusTracker(tempFolder); tracker.StageFile(tempFile); tracker.Commit("中文 1čtestč"); var fileContent = tracker.GetFileContent(tempFile); using (var binWriter = new BinaryWriter(File.Open(tempFile + ".bk", System.IO.FileMode.Create))) { binWriter.Write(fileContent); } var newlines = File.ReadAllLines(tempFile + ".bk"); Assert.AreEqual(lines[0], newlines[0]); Assert.AreEqual(lines[1], newlines[1]); Assert.AreEqual(lines[2], newlines[2]); }
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); }
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 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); } }