public void RetrievingDiffChangesMustAlwaysBeCaseSensitive() { ObjectId treeOldOid, treeNewOid; string repoPath = InitNewRepository(); using (var repo = new Repository(repoPath)) { Blob oldContent = OdbHelper.CreateBlob(repo, "awesome content\n"); Blob newContent = OdbHelper.CreateBlob(repo, "more awesome content\n"); var td = new TreeDefinition() .Add("A.TXT", oldContent, Mode.NonExecutableFile) .Add("a.txt", oldContent, Mode.NonExecutableFile); treeOldOid = repo.ObjectDatabase.CreateTree(td).Id; td = new TreeDefinition() .Add("A.TXT", newContent, Mode.NonExecutableFile) .Add("a.txt", newContent, Mode.NonExecutableFile); treeNewOid = repo.ObjectDatabase.CreateTree(td).Id; } using (var repo = new Repository(repoPath)) { var changes = repo.Diff.Compare <TreeChanges>(repo.Lookup <Tree>(treeOldOid), repo.Lookup <Tree>(treeNewOid)); Assert.Equal(ChangeKind.Modified, changes["a.txt"].Status); Assert.Equal(ChangeKind.Modified, changes["A.TXT"].Status); } }
private void CanHandleTwoTreeEntryChangesWithTheSamePath(SimilarityOptions similarity, Action <string, TreeChanges> verifier) { string repoPath = InitNewRepository(); using (var repo = new Repository(repoPath)) { Blob mainContent = OdbHelper.CreateBlob(repo, "awesome content\n" + new string('b', 4096)); Blob linkContent = OdbHelper.CreateBlob(repo, "../../objc/Nu.h"); string path = Path.Combine("include", "Nu", "Nu.h"); var tdOld = new TreeDefinition() .Add(path, linkContent, Mode.SymbolicLink) .Add("objc/Nu.h", mainContent, Mode.NonExecutableFile); Tree treeOld = repo.ObjectDatabase.CreateTree(tdOld); var tdNew = new TreeDefinition() .Add(path, mainContent, Mode.NonExecutableFile); Tree treeNew = repo.ObjectDatabase.CreateTree(tdNew); var changes = repo.Diff.Compare <TreeChanges>(treeOld, treeNew, compareOptions: new CompareOptions { Similarity = similarity, }); verifier(path, changes); } }
private static void AddSomeCornerCases(Repository repo) { // Turn 1.txt into a directory in the Index repo.Index.Remove("1.txt"); var blob = repo.Lookup <Blob>("a8233120f6ad708f843d861ce2b7228ec4e3dec6"); repo.Index.Add(blob, "1.txt/Sneaky", Mode.NonExecutableFile); // Turn README into a symlink Blob linkContent = OdbHelper.CreateBlob(repo, "1.txt/sneaky"); repo.Index.Add(linkContent, "README", Mode.SymbolicLink); }
/// <summary> /// Adds a commit to the object database. The tree will have a single text file with the given specific content /// at the beginning of the file and the given common content at the end of the file. /// </summary> /// <param name="repo">The repository.</param> /// <param name="message">The commit message.</param> /// <param name="path">The file's path.</param> /// <param name="specificContent">The content specific to that file.</param> /// <param name="commonContent">The content shared with other files.</param> /// <param name="parents">The commit's parents.</param> /// <returns>The commit added to the object database.</returns> private Commit AddCommitToOdb(Repository repo, string message, string path, string specificContent, string commonContent, params Commit[] parents) { var content = string.IsNullOrEmpty(commonContent) ? specificContent : specificContent + Environment.NewLine + commonContent + Environment.NewLine; var td = new TreeDefinition(); td.Add(path, OdbHelper.CreateBlob(repo, content), Mode.NonExecutableFile); var t = repo.ObjectDatabase.CreateTree(td); var commitSignature = GetNextSignature(); return(repo.ObjectDatabase.CreateCommit(commitSignature, commitSignature, message, t, parents, true)); }
public void CanParseSymlinkTreeEntries() { var path = CloneBareTestRepo(); using (var repo = new Repository(path)) { Blob linkContent = OdbHelper.CreateBlob(repo, "1/branch_file.txt"); var td = TreeDefinition.From(repo.Head.Tip) .Add("A symlink", linkContent, Mode.SymbolicLink); Tree t = repo.ObjectDatabase.CreateTree(td); var te = t["A symlink"]; Assert.NotNull(te); Assert.Equal(Mode.SymbolicLink, te.Mode); Assert.Equal(linkContent, te.Target); } }
public void CanHandleTwoTreeEntryChangesWithTheSamePath() { string repoPath = InitNewRepository(); using (var repo = new Repository(repoPath)) { Blob mainContent = OdbHelper.CreateBlob(repo, "awesome content\n"); Blob linkContent = OdbHelper.CreateBlob(repo, "../../objc/Nu.h"); string path = string.Format("include{0}Nu{0}Nu.h", Path.DirectorySeparatorChar); var tdOld = new TreeDefinition() .Add(path, linkContent, Mode.SymbolicLink) .Add("objc/Nu.h", mainContent, Mode.NonExecutableFile); Tree treeOld = repo.ObjectDatabase.CreateTree(tdOld); var tdNew = new TreeDefinition() .Add(path, mainContent, Mode.NonExecutableFile); Tree treeNew = repo.ObjectDatabase.CreateTree(tdNew); var changes = repo.Diff.Compare <TreeChanges>(treeOld, treeNew, compareOptions: new CompareOptions { Similarity = SimilarityOptions.None, }); /* * $ git diff-tree -p 5c87b67 d5278d0 * diff --git a/include/Nu/Nu.h b/include/Nu/Nu.h * deleted file mode 120000 * index 19bf568..0000000 * --- a/include/Nu/Nu.h * +++ /dev/null * @@ -1 +0,0 @@ * -../../objc/Nu.h * \ No newline at end of file * diff --git a/include/Nu/Nu.h b/include/Nu/Nu.h * new file mode 100644 * index 0000000..f9e6561 * --- /dev/null * +++ b/include/Nu/Nu.h * @@ -0,0 +1 @@ * +awesome content * diff --git a/objc/Nu.h b/objc/Nu.h * deleted file mode 100644 * index f9e6561..0000000 * --- a/objc/Nu.h * +++ /dev/null * @@ -1 +0,0 @@ * -awesome content */ Assert.Equal(1, changes.Deleted.Count()); Assert.Equal(0, changes.Modified.Count()); Assert.Equal(1, changes.TypeChanged.Count()); TreeEntryChanges change = changes[path]; Assert.Equal(Mode.SymbolicLink, change.OldMode); Assert.Equal(Mode.NonExecutableFile, change.Mode); Assert.Equal(ChangeKind.TypeChanged, change.Status); Assert.Equal(path, change.Path); } }
public void UsingPatienceAlgorithmCompareOptionProducesPatienceDiff() { string repoPath = InitNewRepository(); using (var repo = new Repository(repoPath)) { Func <string, Tree> fromString = s => repo.ObjectDatabase.CreateTree(new TreeDefinition().Add("file.txt", OdbHelper.CreateBlob(repo, s), Mode.NonExecutableFile)); Tree treeOld = fromString(new StringBuilder() .Append("aaaaaa\n") .Append("aaaaaa\n") .Append("bbbbbb\n") .Append("bbbbbb\n") .Append("cccccc\n") .Append("cccccc\n") .Append("abc\n").ToString()); Tree treeNew = fromString(new StringBuilder() .Append("abc\n") .Append("aaaaaa\n") .Append("aaaaaa\n") .Append("bbbbbb\n") .Append("bbbbbb\n") .Append("cccccc\n") .Append("cccccc\n").ToString()); string diffDefault = new StringBuilder() .Append("diff --git a/file.txt b/file.txt\n") .Append("index 3299d68..accc3bd 100644\n") .Append("--- a/file.txt\n") .Append("+++ b/file.txt\n") .Append("@@ -1,7 +1,7 @@\n") .Append("+abc\n") .Append(" aaaaaa\n") .Append(" aaaaaa\n") .Append(" bbbbbb\n") .Append(" bbbbbb\n") .Append(" cccccc\n") .Append(" cccccc\n") .Append("-abc\n").ToString(); string diffPatience = new StringBuilder() .Append("diff --git a/file.txt b/file.txt\n") .Append("index 3299d68..accc3bd 100644\n") .Append("--- a/file.txt\n") .Append("+++ b/file.txt\n") .Append("@@ -1,7 +1,7 @@\n") .Append("-aaaaaa\n") .Append("-aaaaaa\n") .Append("-bbbbbb\n") .Append("-bbbbbb\n") .Append("-cccccc\n") .Append("-cccccc\n") .Append(" abc\n") .Append("+aaaaaa\n") .Append("+aaaaaa\n") .Append("+bbbbbb\n") .Append("+bbbbbb\n") .Append("+cccccc\n") .Append("+cccccc\n").ToString(); Assert.Equal(diffDefault, repo.Diff.Compare <Patch>(treeOld, treeNew)); Assert.Equal(diffPatience, repo.Diff.Compare <Patch>(treeOld, treeNew, compareOptions: new CompareOptions { Algorithm = DiffAlgorithm.Patience })); } }