public void Init(Commit c1, Commit c2) { if (c1 == null) { m_treediff.ItemsSource = null; return; } //m_title.Content = "Differences between commits " + c1.ShortHash + " and " + c2.ShortHash; var changes = c1.CompareAgainst(c2); m_treediff.ItemsSource = changes; if (changes.Count() > 0) { m_treediff.SelectedIndex = 0; } FireSelectionChanged(); }
public void Commit_changes_to_existing_commit() { using (var repo = GetTrashRepository()) { var workingDirectory = repo.WorkingDirectory; string filepath = Path.Combine(workingDirectory, "README"); File.WriteAllText(filepath, "This is a really short readme file\n\nWill write up some text here."); repo.Index.Add(filepath); //repo.Index.Remove(Path.Combine(workingDirectory, "a/a1")); var commit = repo.Commit("Adding ä README\n\n", new Author("müller", "mü[email protected]")); Assert.NotNull(commit); Assert.IsTrue(commit.IsCommit); Assert.AreEqual(commit.Parent.Hash, "49322bb17d3acc9146f98c97d078513228bbf3c0"); Assert.AreEqual("müller", commit.Author.Name); Assert.AreEqual("mü[email protected]", commit.Author.EmailAddress); Assert.AreEqual("Adding ä README\n\n", commit.Message); // check if tree contains the new file, get the blob and check the content. Assert.AreEqual(commit, repo.Head.CurrentCommit); var previous = new Commit(repo, "HEAD^"); Assert.IsTrue(previous.IsCommit); Assert.AreEqual(previous, commit.Parent); var changes = previous.CompareAgainst(commit).ToDictionary(change => change.Name); Assert.AreEqual(ChangeType.Added, changes["README"].ChangeType); Assert.AreEqual("This is a really short readme file\n\nWill write up some text here.", (changes["README"].ComparedObject as Blob).Data); Assert.AreEqual(ChangeType.Deleted, changes["a1"].ChangeType); Assert.AreEqual(ChangeType.Deleted, changes["a1.txt"].ChangeType); Assert.AreEqual(ChangeType.Deleted, changes["a2.txt"].ChangeType); Assert.AreEqual(ChangeType.Deleted, changes["b1.txt"].ChangeType); Assert.AreEqual(ChangeType.Deleted, changes["b2.txt"].ChangeType); Assert.AreEqual(ChangeType.Deleted, changes["c1.txt"].ChangeType); Assert.AreEqual(ChangeType.Deleted, changes["c2.txt"].ChangeType); Assert.AreEqual(ChangeType.Deleted, changes["master.txt"].ChangeType); Assert.AreEqual(9, changes.Count); } }