public virtual void TestDeletionOnSideConflict() { Git git = new Git(db); WriteTrashFile("a", "1\na\n3\n"); WriteTrashFile("b", "1\nb\n3\n"); git.Add().AddFilepattern("a").AddFilepattern("b").Call(); RevCommit initialCommit = git.Commit().SetMessage("initial").Call(); // create side branch and delete "a" CreateBranch(initialCommit, "refs/heads/side"); CheckoutBranch("refs/heads/side"); git.Rm().AddFilepattern("a").Call(); RevCommit secondCommit = git.Commit().SetMessage("side").Call(); // update a on master to generate conflict CheckoutBranch("refs/heads/master"); WriteTrashFile("a", "1\na(main)\n3\n"); git.Add().AddFilepattern("a").Call(); git.Commit().SetMessage("main").Call(); // merge side with master MergeCommandResult result = git.Merge().Include(secondCommit.Id).SetStrategy(MergeStrategy .RESOLVE).Call(); NUnit.Framework.Assert.AreEqual(MergeStatus.CONFLICTING, result.GetMergeStatus()); NUnit.Framework.Assert.IsTrue(new FilePath(db.WorkTree, "a").Exists()); NUnit.Framework.Assert.AreEqual("1\na(main)\n3\n", Read(new FilePath(db.WorkTree, "a"))); NUnit.Framework.Assert.AreEqual("1\nb\n3\n", Read(new FilePath(db.WorkTree, "b")) ); NUnit.Framework.Assert.AreEqual(1, result.GetConflicts().Count); NUnit.Framework.Assert.AreEqual(3, result.GetConflicts().Get("a")[0].Length); }
public virtual void TestMergeNonVersionedPaths() { Git git = new Git(db); WriteTrashFile("a", "1\na\n3\n"); WriteTrashFile("b", "1\nb\n3\n"); WriteTrashFile("c/c/c", "1\nc\n3\n"); git.Add().AddFilepattern("a").AddFilepattern("b").AddFilepattern("c/c/c").Call(); RevCommit initialCommit = git.Commit().SetMessage("initial").Call(); CreateBranch(initialCommit, "refs/heads/side"); CheckoutBranch("refs/heads/side"); WriteTrashFile("a", "1\na(side)\n3\n"); WriteTrashFile("b", "1\nb(side)\n3\n"); git.Add().AddFilepattern("a").AddFilepattern("b").Call(); RevCommit secondCommit = git.Commit().SetMessage("side").Call(); NUnit.Framework.Assert.AreEqual("1\nb(side)\n3\n", Read(new FilePath(db.WorkTree, "b"))); CheckoutBranch("refs/heads/master"); NUnit.Framework.Assert.AreEqual("1\nb\n3\n", Read(new FilePath(db.WorkTree, "b")) ); WriteTrashFile("a", "1\na(main)\n3\n"); WriteTrashFile("c/c/c", "1\nc(main)\n3\n"); git.Add().AddFilepattern("a").AddFilepattern("c/c/c").Call(); git.Commit().SetMessage("main").Call(); WriteTrashFile("d", "1\nd\n3\n"); NUnit.Framework.Assert.IsTrue(new FilePath(db.WorkTree, "e").Mkdir()); MergeCommandResult result = git.Merge().Include(secondCommit.Id).SetStrategy(MergeStrategy .RESOLVE).Call(); NUnit.Framework.Assert.AreEqual(MergeStatus.CONFLICTING, result.GetMergeStatus()); NUnit.Framework.Assert.AreEqual("1\n<<<<<<< HEAD\na(main)\n=======\na(side)\n>>>>>>> 86503e7e397465588cc267b65d778538bffccb83\n3\n" , Read(new FilePath(db.WorkTree, "a"))); NUnit.Framework.Assert.AreEqual("1\nb(side)\n3\n", Read(new FilePath(db.WorkTree, "b"))); NUnit.Framework.Assert.AreEqual("1\nc(main)\n3\n", Read(new FilePath(db.WorkTree, "c/c/c"))); NUnit.Framework.Assert.AreEqual("1\nd\n3\n", Read(new FilePath(db.WorkTree, "d")) ); FilePath dir = new FilePath(db.WorkTree, "e"); NUnit.Framework.Assert.IsTrue(dir.IsDirectory()); NUnit.Framework.Assert.AreEqual(1, result.GetConflicts().Count); NUnit.Framework.Assert.AreEqual(3, result.GetConflicts().Get("a")[0].Length); NUnit.Framework.Assert.AreEqual(RepositoryState.MERGING, db.GetRepositoryState()); }
public virtual void TestSuccessfulContentMergeAndDirtyworkingTree() { Git git = new Git(db); WriteTrashFile("a", "1\na\n3\n"); WriteTrashFile("b", "1\nb\n3\n"); WriteTrashFile("d", "1\nd\n3\n"); WriteTrashFile("c/c/c", "1\nc\n3\n"); git.Add().AddFilepattern("a").AddFilepattern("b").AddFilepattern("c/c/c").AddFilepattern ("d").Call(); RevCommit initialCommit = git.Commit().SetMessage("initial").Call(); CreateBranch(initialCommit, "refs/heads/side"); CheckoutBranch("refs/heads/side"); WriteTrashFile("a", "1(side)\na\n3\n"); WriteTrashFile("b", "1\nb(side)\n3\n"); git.Add().AddFilepattern("a").AddFilepattern("b").Call(); RevCommit secondCommit = git.Commit().SetMessage("side").Call(); NUnit.Framework.Assert.AreEqual("1\nb(side)\n3\n", Read(new FilePath(db.WorkTree, "b"))); CheckoutBranch("refs/heads/master"); NUnit.Framework.Assert.AreEqual("1\nb\n3\n", Read(new FilePath(db.WorkTree, "b")) ); WriteTrashFile("a", "1\na\n3(main)\n"); WriteTrashFile("c/c/c", "1\nc(main)\n3\n"); git.Add().AddFilepattern("a").AddFilepattern("c/c/c").Call(); RevCommit thirdCommit = git.Commit().SetMessage("main").Call(); WriteTrashFile("d", "--- dirty ---"); MergeCommandResult result = git.Merge().Include(secondCommit.Id).SetStrategy(MergeStrategy .RESOLVE).Call(); NUnit.Framework.Assert.AreEqual(MergeStatus.MERGED, result.GetMergeStatus()); NUnit.Framework.Assert.AreEqual("1(side)\na\n3(main)\n", Read(new FilePath(db.WorkTree , "a"))); NUnit.Framework.Assert.AreEqual("1\nb(side)\n3\n", Read(new FilePath(db.WorkTree, "b"))); NUnit.Framework.Assert.AreEqual("1\nc(main)\n3\n", Read(new FilePath(db.WorkTree, "c/c/c"))); NUnit.Framework.Assert.AreEqual("--- dirty ---", Read(new FilePath(db.WorkTree, "d" ))); NUnit.Framework.Assert.AreEqual(null, result.GetConflicts()); NUnit.Framework.Assert.IsTrue(2 == result.GetMergedCommits().Length); NUnit.Framework.Assert.AreEqual(thirdCommit, result.GetMergedCommits()[0]); NUnit.Framework.Assert.AreEqual(secondCommit, result.GetMergedCommits()[1]); Iterator <RevCommit> it = git.Log().Call().Iterator(); RevCommit newHead = it.Next(); NUnit.Framework.Assert.AreEqual(newHead, result.GetNewHead()); NUnit.Framework.Assert.AreEqual(2, newHead.ParentCount); NUnit.Framework.Assert.AreEqual(thirdCommit, newHead.GetParent(0)); NUnit.Framework.Assert.AreEqual(secondCommit, newHead.GetParent(1)); NUnit.Framework.Assert.AreEqual("Merge commit '064d54d98a4cdb0fed1802a21c656bfda67fe879'" , newHead.GetFullMessage()); NUnit.Framework.Assert.AreEqual(RepositoryState.SAFE, db.GetRepositoryState()); }
/// <exception cref="System.Exception"></exception> private void CheckMergeFailedResult(MergeCommandResult result, ResolveMerger.MergeFailureReason reason, string indexState, FilePath fileA) { NUnit.Framework.Assert.AreEqual(MergeStatus.FAILED, result.GetMergeStatus()); NUnit.Framework.Assert.AreEqual(reason, result.GetFailingPaths().Get("a")); NUnit.Framework.Assert.AreEqual("a(modified)", Read(fileA)); NUnit.Framework.Assert.IsFalse(new FilePath(db.WorkTree, "b").Exists()); NUnit.Framework.Assert.AreEqual("c", Read(new FilePath(db.WorkTree, "c"))); NUnit.Framework.Assert.AreEqual(indexState, IndexState(CONTENT)); NUnit.Framework.Assert.AreEqual(null, result.GetConflicts()); NUnit.Framework.Assert.AreEqual(RepositoryState.SAFE, db.GetRepositoryState()); }
public virtual void TestModifiedAndRenamed() { // this test is essentially the same as testDeletionOnSideConflict, // however if once rename support is added this test should result in a // successful merge instead of a conflict Git git = new Git(db); WriteTrashFile("x", "add x"); git.Add().AddFilepattern("x").Call(); RevCommit initial = git.Commit().SetMessage("add x").Call(); CreateBranch(initial, "refs/heads/d1"); CreateBranch(initial, "refs/heads/d2"); // rename x to y on d1 CheckoutBranch("refs/heads/d1"); new FilePath(db.WorkTree, "x").RenameTo(new FilePath(db.WorkTree, "y")); git.Rm().AddFilepattern("x").Call(); git.Add().AddFilepattern("y").Call(); RevCommit d1Commit = git.Commit().SetMessage("d1 rename x -> y").Call(); CheckoutBranch("refs/heads/d2"); WriteTrashFile("x", "d2 change"); git.Add().AddFilepattern("x").Call(); RevCommit d2Commit = git.Commit().SetMessage("d2 change in x").Call(); CheckoutBranch("refs/heads/master"); MergeCommandResult d1Merge = git.Merge().Include(d1Commit).Call(); NUnit.Framework.Assert.AreEqual(MergeStatus.FAST_FORWARD, d1Merge.GetMergeStatus( )); MergeCommandResult d2Merge = git.Merge().Include(d2Commit).Call(); NUnit.Framework.Assert.AreEqual(MergeStatus.CONFLICTING, d2Merge.GetMergeStatus() ); NUnit.Framework.Assert.AreEqual(1, d2Merge.GetConflicts().Count); NUnit.Framework.Assert.AreEqual(3, d2Merge.GetConflicts().Get("x")[0].Length); }
public virtual void TestMergeConflictFileFolder() { Git git = new Git(db); WriteTrashFile("a", "1\na\n3\n"); WriteTrashFile("b", "1\nb\n3\n"); git.Add().AddFilepattern("a").AddFilepattern("b").Call(); RevCommit initialCommit = git.Commit().SetMessage("initial").Call(); CreateBranch(initialCommit, "refs/heads/side"); CheckoutBranch("refs/heads/side"); WriteTrashFile("c/c/c", "1\nc(side)\n3\n"); WriteTrashFile("d", "1\nd(side)\n3\n"); git.Add().AddFilepattern("c/c/c").AddFilepattern("d").Call(); RevCommit secondCommit = git.Commit().SetMessage("side").Call(); CheckoutBranch("refs/heads/master"); WriteTrashFile("c", "1\nc(main)\n3\n"); WriteTrashFile("d/d/d", "1\nd(main)\n3\n"); git.Add().AddFilepattern("c").AddFilepattern("d/d/d").Call(); git.Commit().SetMessage("main").Call(); MergeCommandResult result = git.Merge().Include(secondCommit.Id).SetStrategy(MergeStrategy .RESOLVE).Call(); NUnit.Framework.Assert.AreEqual(MergeStatus.CONFLICTING, result.GetMergeStatus()); NUnit.Framework.Assert.AreEqual("1\na\n3\n", Read(new FilePath(db.WorkTree, "a")) ); NUnit.Framework.Assert.AreEqual("1\nb\n3\n", Read(new FilePath(db.WorkTree, "b")) ); NUnit.Framework.Assert.AreEqual("1\nc(main)\n3\n", Read(new FilePath(db.WorkTree, "c"))); NUnit.Framework.Assert.AreEqual("1\nd(main)\n3\n", Read(new FilePath(db.WorkTree, "d/d/d"))); NUnit.Framework.Assert.AreEqual(null, result.GetConflicts()); NUnit.Framework.Assert.AreEqual(RepositoryState.MERGING, db.GetRepositoryState()); }
public virtual void TestMergeFailingWithDirtyWorkingTree() { Git git = new Git(db); WriteTrashFile("a", "1\na\n3\n"); WriteTrashFile("b", "1\nb\n3\n"); git.Add().AddFilepattern("a").AddFilepattern("b").Call(); RevCommit initialCommit = git.Commit().SetMessage("initial").Call(); CreateBranch(initialCommit, "refs/heads/side"); CheckoutBranch("refs/heads/side"); WriteTrashFile("a", "1(side)\na\n3\n"); WriteTrashFile("b", "1\nb(side)\n3\n"); git.Add().AddFilepattern("a").AddFilepattern("b").Call(); RevCommit secondCommit = git.Commit().SetMessage("side").Call(); NUnit.Framework.Assert.AreEqual("1\nb(side)\n3\n", Read(new FilePath(db.WorkTree, "b"))); CheckoutBranch("refs/heads/master"); NUnit.Framework.Assert.AreEqual("1\nb\n3\n", Read(new FilePath(db.WorkTree, "b")) ); WriteTrashFile("a", "1\na\n3(main)\n"); git.Add().AddFilepattern("a").Call(); git.Commit().SetMessage("main").Call(); WriteTrashFile("a", "--- dirty ---"); MergeCommandResult result = git.Merge().Include(secondCommit.Id).SetStrategy(MergeStrategy .RESOLVE).Call(); NUnit.Framework.Assert.AreEqual(MergeStatus.FAILED, result.GetMergeStatus()); NUnit.Framework.Assert.AreEqual("--- dirty ---", Read(new FilePath(db.WorkTree, "a" ))); NUnit.Framework.Assert.AreEqual("1\nb\n3\n", Read(new FilePath(db.WorkTree, "b")) ); NUnit.Framework.Assert.AreEqual(null, result.GetConflicts()); NUnit.Framework.Assert.AreEqual(RepositoryState.SAFE, db.GetRepositoryState()); }