public virtual void TestPullFastForward() { PullResult res = target.Pull().Call(); // nothing to update since we don't have different data yet NUnit.Framework.Assert.IsTrue(res.GetFetchResult().GetTrackingRefUpdates().IsEmpty ()); NUnit.Framework.Assert.IsTrue(res.GetMergeResult().GetMergeStatus().Equals(MergeStatus .ALREADY_UP_TO_DATE)); AssertFileContentsEqual(targetFile, "Hello world"); // change the source file WriteToFile(sourceFile, "Another change"); source.Add().AddFilepattern("SomeFile.txt").Call(); source.Commit().SetMessage("Some change in remote").Call(); res = target.Pull().Call(); NUnit.Framework.Assert.IsFalse(res.GetFetchResult().GetTrackingRefUpdates().IsEmpty ()); NUnit.Framework.Assert.AreEqual(res.GetMergeResult().GetMergeStatus(), MergeStatus .FAST_FORWARD); AssertFileContentsEqual(targetFile, "Another change"); NUnit.Framework.Assert.AreEqual(RepositoryState.SAFE, target.GetRepository().GetRepositoryState ()); res = target.Pull().Call(); NUnit.Framework.Assert.AreEqual(res.GetMergeResult().GetMergeStatus(), MergeStatus .ALREADY_UP_TO_DATE); }
public virtual void TestPullMerge() { PullResult res = target.Pull().Call(); // nothing to update since we don't have different data yet NUnit.Framework.Assert.IsTrue(res.GetFetchResult().GetTrackingRefUpdates().IsEmpty ()); NUnit.Framework.Assert.IsTrue(res.GetMergeResult().GetMergeStatus().Equals(MergeStatus .ALREADY_UP_TO_DATE)); WriteToFile(sourceFile, "Source change"); source.Add().AddFilepattern("SomeFile.txt"); RevCommit sourceCommit = source.Commit().SetMessage("Source change in remote").Call (); FilePath targetFile2 = new FilePath(dbTarget.WorkTree, "OtherFile.txt"); WriteToFile(targetFile2, "Unconflicting change"); target.Add().AddFilepattern("OtherFile.txt").Call(); RevCommit targetCommit = target.Commit().SetMessage("Unconflicting change in local" ).Call(); res = target.Pull().Call(); MergeCommandResult mergeResult = res.GetMergeResult(); ObjectId[] mergedCommits = mergeResult.GetMergedCommits(); NUnit.Framework.Assert.AreEqual(targetCommit.Id, mergedCommits[0]); NUnit.Framework.Assert.AreEqual(sourceCommit.Id, mergedCommits[1]); RevCommit mergeCommit = new RevWalk(dbTarget).ParseCommit(mergeResult.GetNewHead( )); string message = "Merge branch 'master' of " + db.WorkTree; NUnit.Framework.Assert.AreEqual(message, mergeCommit.GetShortMessage()); }
public virtual void TestPullConflict() { PullResult res = target.Pull().Call(); // nothing to update since we don't have different data yet NUnit.Framework.Assert.IsTrue(res.GetFetchResult().GetTrackingRefUpdates().IsEmpty ()); NUnit.Framework.Assert.IsTrue(res.GetMergeResult().GetMergeStatus().Equals(MergeStatus .ALREADY_UP_TO_DATE)); AssertFileContentsEqual(targetFile, "Hello world"); // change the source file WriteToFile(sourceFile, "Source change"); source.Add().AddFilepattern("SomeFile.txt").Call(); source.Commit().SetMessage("Source change in remote").Call(); // change the target file WriteToFile(targetFile, "Target change"); target.Add().AddFilepattern("SomeFile.txt").Call(); target.Commit().SetMessage("Target change in local").Call(); res = target.Pull().Call(); string sourceChangeString = "Source change\n>>>>>>> branch 'master' of " + target .GetRepository().GetConfig().GetString("remote", "origin", "url"); NUnit.Framework.Assert.IsFalse(res.GetFetchResult().GetTrackingRefUpdates().IsEmpty ()); NUnit.Framework.Assert.AreEqual(res.GetMergeResult().GetMergeStatus(), MergeStatus .CONFLICTING); string result = "<<<<<<< HEAD\nTarget change\n=======\n" + sourceChangeString + "\n"; AssertFileContentsEqual(targetFile, result); NUnit.Framework.Assert.AreEqual(RepositoryState.MERGING, target.GetRepository().GetRepositoryState ()); }
public virtual void TestPullLocalConflict() { target.BranchCreate().SetName("basedOnMaster").SetStartPoint("refs/heads/master") .SetUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK).Call(); target.GetRepository().UpdateRef(Constants.HEAD).Link("refs/heads/basedOnMaster"); PullResult res = target.Pull().Call(); // nothing to update since we don't have different data yet NUnit.Framework.Assert.IsNull(res.GetFetchResult()); NUnit.Framework.Assert.IsTrue(res.GetMergeResult().GetMergeStatus().Equals(MergeStatus .ALREADY_UP_TO_DATE)); AssertFileContentsEqual(targetFile, "Hello world"); // change the file in master target.GetRepository().UpdateRef(Constants.HEAD).Link("refs/heads/master"); WriteToFile(targetFile, "Master change"); target.Add().AddFilepattern("SomeFile.txt").Call(); target.Commit().SetMessage("Source change in master").Call(); // change the file in slave target.GetRepository().UpdateRef(Constants.HEAD).Link("refs/heads/basedOnMaster"); WriteToFile(targetFile, "Slave change"); target.Add().AddFilepattern("SomeFile.txt").Call(); target.Commit().SetMessage("Source change in based on master").Call(); res = target.Pull().Call(); string sourceChangeString = "Master change\n>>>>>>> branch 'master' of local repository"; NUnit.Framework.Assert.IsNull(res.GetFetchResult()); NUnit.Framework.Assert.AreEqual(res.GetMergeResult().GetMergeStatus(), MergeStatus .CONFLICTING); string result = "<<<<<<< HEAD\nSlave change\n=======\n" + sourceChangeString + "\n"; AssertFileContentsEqual(targetFile, result); NUnit.Framework.Assert.AreEqual(RepositoryState.MERGING, target.GetRepository().GetRepositoryState ()); }
public virtual void TestPullFastForwardWithBranchInSource() { PullResult res = target.Pull().Call(); // nothing to update since we don't have different data yet NUnit.Framework.Assert.IsTrue(res.GetFetchResult().GetTrackingRefUpdates().IsEmpty ()); NUnit.Framework.Assert.AreEqual(RebaseResult.Status.UP_TO_DATE, res.GetRebaseResult ().GetStatus()); AssertFileContentsEqual(targetFile, "Hello world"); // change the source file WriteToFile(sourceFile, "Another change\n\n\n\nFoo"); source.Add().AddFilepattern("SomeFile.txt").Call(); RevCommit initialCommit = source.Commit().SetMessage("Some change in remote").Call (); // modify the source file in a branch CreateBranch(initialCommit, "refs/heads/side"); CheckoutBranch("refs/heads/side"); WriteToFile(sourceFile, "Another change\n\n\n\nBoo"); source.Add().AddFilepattern("SomeFile.txt").Call(); RevCommit sideCommit = source.Commit().SetMessage("Some change in remote").Call(); // modify the source file on master CheckoutBranch("refs/heads/master"); WriteToFile(sourceFile, "More change\n\n\n\nFoo"); source.Add().AddFilepattern("SomeFile.txt").Call(); source.Commit().SetMessage("Some change in remote").Call(); // merge side into master MergeCommandResult result = source.Merge().Include(sideCommit.Id).SetStrategy(MergeStrategy .RESOLVE).Call(); NUnit.Framework.Assert.AreEqual(MergeStatus.MERGED, result.GetMergeStatus()); }
public virtual void TestPullConflict() { PullResult res = target.Pull().Call(); // nothing to update since we don't have different data yet NUnit.Framework.Assert.IsTrue(res.GetFetchResult().GetTrackingRefUpdates().IsEmpty ()); NUnit.Framework.Assert.AreEqual(RebaseResult.Status.UP_TO_DATE, res.GetRebaseResult ().GetStatus()); AssertFileContentsEqual(targetFile, "Hello world"); // change the source file WriteToFile(sourceFile, "Source change"); source.Add().AddFilepattern("SomeFile.txt").Call(); source.Commit().SetMessage("Source change in remote").Call(); // change the target file WriteToFile(targetFile, "Target change"); target.Add().AddFilepattern("SomeFile.txt").Call(); target.Commit().SetMessage("Target change in local").Call(); res = target.Pull().Call(); string remoteUri = target.GetRepository().GetConfig().GetString(ConfigConstants.CONFIG_REMOTE_SECTION , "origin", ConfigConstants.CONFIG_KEY_URL); NUnit.Framework.Assert.IsFalse(res.GetFetchResult().GetTrackingRefUpdates().IsEmpty ()); NUnit.Framework.Assert.AreEqual(RebaseResult.Status.STOPPED, res.GetRebaseResult( ).GetStatus()); string result = "<<<<<<< Upstream, based on branch 'master' of " + remoteUri + "\nSource change\n=======\nTarget change\n>>>>>>> 42453fd Target change in local\n"; AssertFileContentsEqual(targetFile, result); NUnit.Framework.Assert.AreEqual(RepositoryState.REBASING_INTERACTIVE, target.GetRepository ().GetRepositoryState()); }
public virtual void TestPullConflict() { PullResult res = target.Pull().Call(); // nothing to update since we don't have different data yet NUnit.Framework.Assert.IsTrue(res.GetFetchResult().GetTrackingRefUpdates().IsEmpty ()); NUnit.Framework.Assert.IsTrue(res.GetRebaseResult().GetStatus().Equals(RebaseResult.Status .UP_TO_DATE)); AssertFileContentsEqual(targetFile, "Hello world"); // change the source file WriteToFile(sourceFile, "Source change"); source.Add().AddFilepattern("SomeFile.txt").Call(); source.Commit().SetMessage("Source change in remote").Call(); // change the target file WriteToFile(targetFile, "Target change"); target.Add().AddFilepattern("SomeFile.txt").Call(); target.Commit().SetMessage("Target change in local").Call(); res = target.Pull().Call(); NUnit.Framework.Assert.IsFalse(res.GetFetchResult().GetTrackingRefUpdates().IsEmpty ()); NUnit.Framework.Assert.IsTrue(res.GetRebaseResult().GetStatus().Equals(RebaseResult.Status .STOPPED)); string result = "<<<<<<< OURS\nSource change\n=======\nTarget change\n>>>>>>> THEIRS\n"; AssertFileContentsEqual(targetFile, result); NUnit.Framework.Assert.AreEqual(RepositoryState.REBASING_INTERACTIVE, target.GetRepository ().GetRepositoryState()); }
public virtual void TestPullLocalConflict() { target.BranchCreate().SetName("basedOnMaster").SetStartPoint("refs/heads/master") .SetUpstreamMode(CreateBranchCommand.SetupUpstreamMode.NOTRACK).Call(); StoredConfig config = target.GetRepository().GetConfig(); config.SetString("branch", "basedOnMaster", "remote", "."); config.SetString("branch", "basedOnMaster", "merge", "refs/heads/master"); config.SetBoolean("branch", "basedOnMaster", "rebase", true); config.Save(); target.GetRepository().UpdateRef(Constants.HEAD).Link("refs/heads/basedOnMaster"); PullResult res = target.Pull().Call(); // nothing to update since we don't have different data yet NUnit.Framework.Assert.IsNull(res.GetFetchResult()); NUnit.Framework.Assert.AreEqual(RebaseResult.Status.UP_TO_DATE, res.GetRebaseResult ().GetStatus()); AssertFileContentsEqual(targetFile, "Hello world"); // change the file in master target.GetRepository().UpdateRef(Constants.HEAD).Link("refs/heads/master"); WriteToFile(targetFile, "Master change"); target.Add().AddFilepattern("SomeFile.txt").Call(); target.Commit().SetMessage("Source change in master").Call(); // change the file in slave target.GetRepository().UpdateRef(Constants.HEAD).Link("refs/heads/basedOnMaster"); WriteToFile(targetFile, "Slave change"); target.Add().AddFilepattern("SomeFile.txt").Call(); target.Commit().SetMessage("Source change in based on master").Call(); res = target.Pull().Call(); NUnit.Framework.Assert.IsNull(res.GetFetchResult()); NUnit.Framework.Assert.AreEqual(RebaseResult.Status.STOPPED, res.GetRebaseResult( ).GetStatus()); string result = "<<<<<<< Upstream, based on branch 'master' of local repository\n" + "Master change\n=======\nSlave change\n>>>>>>> 4049c9e Source change in based on master\n"; AssertFileContentsEqual(targetFile, result); NUnit.Framework.Assert.AreEqual(RepositoryState.REBASING_INTERACTIVE, target.GetRepository ().GetRepositoryState()); }
public static bool reset_on_MergeConflicts(this API_NGit nGit, PullResult pullResult) { if (nGit.notNull() && pullResult.notNull()) { try { if (pullResult.GetMergeResult().GetMergeStatus() == MergeStatus.CONFLICTING) { "[API_NGit][revert_on_MergeConflicts] pull result had a conflict so going to triger a hard reset".error(); return nGit.reset_Hard(); } } catch (Exception ex) { ex.log("[API_NGit][reset_on_MergeConflicts]"); } } return false; }