public void AmendCommitTest() { GitRepository.Init(tempFolder); File.WriteAllLines(tempFilePath, lines); GitRepository tracker = new GitRepository(tempFolder); tracker.StageFile(tempFile); tracker.Commit("中文 1čtestč"); Assert.IsTrue(tracker.LastCommitMessage.Equals("中文 1čtestč")); File.WriteAllText(tempFile, "changed text"); tracker.StageFile(tempFile); tracker.Commit("new message", true); Assert.IsTrue(tracker.LastCommitMessage.Equals("new message")); }
public void CheckOutFileTest() { GitRepository.Init(tempFolder); File.WriteAllLines(tempFilePath, lines); GitRepository tracker = new GitRepository(tempFolder); tracker.StageFile(tempFile); tracker.Commit("test"); File.WriteAllText(tempFilePath, "changed text"); tracker.CheckOutFile(tempFile); var newlines = File.ReadAllLines(tempFilePath); Assert.AreEqual(lines[0], newlines[0]); Assert.AreEqual(lines[1], newlines[1]); Assert.AreEqual(lines[2], newlines[2]); }
public void DiffFileTest() { GitRepository.Init(tempFolder); File.WriteAllLines(tempFilePath, lines); GitRepository tracker = new GitRepository(tempFolder); tracker.StageFile(tempFile); tracker.Commit("test message"); File.WriteAllText(tempFilePath, "changed text"); var diffFile = tracker.DiffFile(tempFile); var diff = File.ReadAllText(diffFile); Assert.IsTrue(diff.Contains("@@ -1,3 +1 @@")); }
public void SaveFileFromRepositoryTest() { GitRepository.Init(tempFolder); File.WriteAllLines(tempFilePath, lines); GitRepository tracker = new GitRepository(tempFolder); tracker.StageFile(tempFile); tracker.Commit("test"); var tmp = Path.Combine(Path.GetTempPath(), tempFile) + ".bk"; tracker.SaveFileFromLastCommit(tempFile, tmp); var newlines = File.ReadAllLines(tmp); Assert.AreEqual(lines[0], newlines[0]); Assert.AreEqual(lines[1], newlines[1]); Assert.AreEqual(lines[2], newlines[2]); }
public void LastCommitMessageTest() { GitRepository.Init(tempFolder); File.WriteAllLines(tempFilePath, lines); GitRepository tracker = new GitRepository(tempFolder); tracker.StageFile(tempFile); tracker.Commit("中文 1čtestč"); Assert.IsTrue(tracker.LastCommitMessage.Equals("中文 1čtestč")); }
public void GetFileStatusTest() { GitRepository.Init(tempFolder); GitRepository tracker = new GitRepository(tempFolder); File.WriteAllLines(tempFilePath, 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č"); tracker.Refresh(); Assert.AreEqual(GitFileStatus.Tracked, tracker.GetFileStatus(tempFile)); File.WriteAllText(tempFilePath, "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(tempFilePath); 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 GetChangedFilesTest() { GitRepository.Init(tempFolder); File.WriteAllLines(tempFilePath, lines); GitRepository tracker = new GitRepository(tempFolder); tracker.StageFile(tempFile); tracker.Refresh(); Assert.AreEqual(GitFileStatus.Added, tracker.GetFileStatus(tempFile)); tracker.Commit("中文 1čtestč"); tracker.Refresh(); Assert.AreEqual(0, tracker.ChangedFiles.Count()); File.WriteAllText(tempFilePath, "a"); tracker.Refresh(); Assert.AreEqual(GitFileStatus.Modified, tracker.GetFileStatus(tempFile)); }
public void GetBranchTest() { GitRepository.Init(tempFolder); File.WriteAllLines(tempFilePath, lines); GitRepository tracker = new GitRepository(tempFolder); Assert.AreEqual("master", tracker.CurrentBranch); tracker.StageFile(tempFile); Assert.AreEqual("master", tracker.CurrentBranch); tracker.Commit("test message"); Assert.AreEqual("master", tracker.CurrentBranch); tempFile = tempFile.Replace("test", "TEST"); File.WriteAllText(tempFilePath, "changed text"); tracker.CheckOutBranch("dev", true); Assert.AreEqual("dev", tracker.CurrentBranch); }
public void FileNameCaseTest() { GitRepository.Init(tempFolder); File.WriteAllLines(tempFilePath, lines); GitRepository tracker = new GitRepository(tempFolder); tracker.StageFile(tempFile); tracker.Commit("test message"); Assert.IsTrue(tracker.LastCommitMessage.StartsWith("test message")); tempFile = tempFile.Replace("test", "TEST"); File.WriteAllText(tempFilePath, "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); }