public static string path(this DiffEntry diffEntry) { if (diffEntry.notNull()) { return(diffEntry.GetNewPath()); } return(null); }
public virtual void CommitNewSubmodule() { Git git = new Git(db); WriteTrashFile("file.txt", "content"); git.Add().AddFilepattern("file.txt").Call(); RevCommit commit = git.Commit().SetMessage("create file").Call(); SubmoduleAddCommand command = new SubmoduleAddCommand(db); string path = "sub"; command.SetPath(path); string uri = db.Directory.ToURI().ToString(); command.SetURI(uri); Repository repo = command.Call(); NUnit.Framework.Assert.IsNotNull(repo); AddRepoToClose(repo); SubmoduleWalk generator = SubmoduleWalk.ForIndex(db); NUnit.Framework.Assert.IsTrue(generator.Next()); NUnit.Framework.Assert.AreEqual(path, generator.GetPath()); NUnit.Framework.Assert.AreEqual(commit, generator.GetObjectId()); NUnit.Framework.Assert.AreEqual(uri, generator.GetModulesUrl()); NUnit.Framework.Assert.AreEqual(path, generator.GetModulesPath()); NUnit.Framework.Assert.AreEqual(uri, generator.GetConfigUrl()); Repository subModRepo = generator.GetRepository(); AddRepoToClose(subModRepo); NUnit.Framework.Assert.IsNotNull(subModRepo); NUnit.Framework.Assert.AreEqual(commit, repo.Resolve(Constants.HEAD)); RevCommit submoduleCommit = git.Commit().SetMessage("submodule add").SetOnly(path ).Call(); NUnit.Framework.Assert.IsNotNull(submoduleCommit); TreeWalk walk = new TreeWalk(db); walk.AddTree(commit.Tree); walk.AddTree(submoduleCommit.Tree); walk.Filter = TreeFilter.ANY_DIFF; IList <DiffEntry> diffs = DiffEntry.Scan(walk); NUnit.Framework.Assert.AreEqual(1, diffs.Count); DiffEntry subDiff = diffs[0]; NUnit.Framework.Assert.AreEqual(FileMode.MISSING, subDiff.GetOldMode()); NUnit.Framework.Assert.AreEqual(FileMode.GITLINK, subDiff.GetNewMode()); NUnit.Framework.Assert.AreEqual(ObjectId.ZeroId, subDiff.GetOldId().ToObjectId()); NUnit.Framework.Assert.AreEqual(commit, subDiff.GetNewId().ToObjectId()); NUnit.Framework.Assert.AreEqual(path, subDiff.GetNewPath()); }
private static string Path(DiffEntry difference) { switch (difference.GetChangeType()) { case DiffEntry.ChangeType.ADD: return(difference.GetNewPath()); case DiffEntry.ChangeType.COPY: return(string.Format("{0} -> {1}", difference.GetOldPath(), difference.GetNewPath())); case DiffEntry.ChangeType.DELETE: return(difference.GetOldPath()); case DiffEntry.ChangeType.MODIFY: return(difference.GetOldPath()); case DiffEntry.ChangeType.RENAME: return(string.Format("{0} -> {1}", difference.GetOldPath(), difference.GetNewPath())); default: return(difference.ToString()); } }
/// <summary>Assert which renames should have happened, in traversal order.</summary> /// <remarks>Assert which renames should have happened, in traversal order.</remarks> /// <param name="expectedRenames">the rename specs, each one in the form "srcPath->destPath" /// </param> protected internal virtual void AssertRenames(params string[] expectedRenames) { NUnit.Framework.Assert.AreEqual(expectedRenames.Length, diffCollector.diffs.Count , "Unexpected number of renames. Expected: " + expectedRenames.Length + ", actual: " + diffCollector.diffs.Count); for (int i = 0; i < expectedRenames.Length; i++) { DiffEntry diff = diffCollector.diffs[i]; NUnit.Framework.Assert.IsNotNull(diff); string[] split = expectedRenames[i].RegexSplit("->"); NUnit.Framework.Assert.IsNotNull(split); NUnit.Framework.Assert.AreEqual(2, split.Length); string src = split[0]; string target = split[1]; NUnit.Framework.Assert.AreEqual(src, diff.GetOldPath()); NUnit.Framework.Assert.AreEqual(target, diff.GetNewPath()); } }
public virtual void TestNoOutputStreamSet() { FilePath file = WriteTrashFile("test.txt", "a"); NUnit.Framework.Assert.IsTrue(file.SetLastModified(file.LastModified() - 5000)); Git git = new Git(db); git.Add().AddFilepattern(".").Call(); Write(file, "b"); IList <DiffEntry> diffs = git.Diff().Call(); NUnit.Framework.Assert.IsNotNull(diffs); NUnit.Framework.Assert.AreEqual(1, diffs.Count); DiffEntry diff = diffs[0]; NUnit.Framework.Assert.AreEqual(DiffEntry.ChangeType.MODIFY, diff.GetChangeType() ); NUnit.Framework.Assert.AreEqual("test.txt", diff.GetOldPath()); NUnit.Framework.Assert.AreEqual("test.txt", diff.GetNewPath()); }