diff test/org/tmatesoft/hg/test/TestOutgoing.java @ 653:629a7370554c

Tests for recent changes in HgParentChildMap and RepositoryComparator (outgoing to respect drafts and Issue 47)
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 03 Jul 2013 14:38:30 +0200
parents 2813a26b8999
children
line wrap: on
line diff
--- a/test/org/tmatesoft/hg/test/TestOutgoing.java	Tue Jul 02 23:21:16 2013 +0200
+++ b/test/org/tmatesoft/hg/test/TestOutgoing.java	Wed Jul 03 14:38:30 2013 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011 TMate Software Ltd
+ * Copyright (c) 2011-2013 TMate Software Ltd
  *  
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -16,19 +16,23 @@
  */
 package org.tmatesoft.hg.test;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
 import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
 import java.util.List;
 
 import org.junit.Assert;
 import org.junit.Rule;
 import org.junit.Test;
+import org.tmatesoft.hg.core.HgCheckoutCommand;
+import org.tmatesoft.hg.core.HgCommitCommand;
 import org.tmatesoft.hg.core.HgLogCommand;
 import org.tmatesoft.hg.core.HgOutgoingCommand;
 import org.tmatesoft.hg.core.Nodeid;
 import org.tmatesoft.hg.repo.HgLookup;
 import org.tmatesoft.hg.repo.HgRemoteRepository;
+import org.tmatesoft.hg.repo.HgRepository;
 
 /**
  *
@@ -71,10 +75,10 @@
 			TestIncoming.report(collector, outParser, liteResult, errorCollector);
 			//
 			File f = new File(dest, "Test.txt");
-			append(f, "1");
+			RepoUtils.createFile(f, "1");
 			eh0.run("hg", "add");
 			eh0.run("hg", "commit", "-m", "1");
-			append(f, "2");
+			RepoUtils.modifyFileAppend(f, "2");
 			eh0.run("hg", "commit", "-m", "2");
 			//
 			cmd = new HgOutgoingCommand(lookup.detect(dest)).against(hgRemote);
@@ -85,10 +89,41 @@
 			TestIncoming.report(collector, outParser, liteResult, errorCollector);
 		}
 	}
-
-	static void append(File f, String s) throws IOException {
-		FileWriter fw = new FileWriter(f);
-		fw.append(s);
-		fw.close();
+	
+	/**
+	 * Issue 47: Incorrect set of outgoing changes when revision spins off prior to common revision of local and remote repos
+	 */
+	@Test
+	public void testOutgoingPreceedsCommon() throws Exception {
+		File srcRepoLoc = RepoUtils.cloneRepoToTempLocation("test-annotate", "test-outgoing-src", false);
+		File dstRepoLoc = RepoUtils.cloneRepoToTempLocation("test-annotate", "test-outgoing-dst", false);
+		File f1 = new File(srcRepoLoc, "file1");
+		assertTrue("[sanity]", f1.canWrite());
+		HgServer server = new HgServer().start(dstRepoLoc);
+		try {
+			final HgLookup hgLookup = new HgLookup();
+			final HgRepository srcRepo = hgLookup.detect(srcRepoLoc);
+			final HgRemoteRepository dstRemote = hgLookup.detect(server.getURL());
+			new HgCheckoutCommand(srcRepo).changeset(6).clean(true).execute();
+			assertEquals("[sanity]", "with-merge", srcRepo.getWorkingCopyBranchName());
+			RepoUtils.modifyFileAppend(f1, "change1");
+			new HgCommitCommand(srcRepo).message("Commit 1").execute();
+			new HgCheckoutCommand(srcRepo).changeset(5).clean(true).execute();
+			assertEquals("[sanity]", "no-merge", srcRepo.getWorkingCopyBranchName());
+			RepoUtils.modifyFileAppend(f1, "change2");
+			new HgCommitCommand(srcRepo).message("Commit 2").execute();
+			//
+			HgOutgoingCommand cmd = new HgOutgoingCommand(srcRepo).against(dstRemote);
+			LogOutputParser outParser = new LogOutputParser(true);
+			ExecHelper eh = new ExecHelper(outParser, srcRepoLoc);
+			HgLogCommand.CollectHandler collector = new HgLogCommand.CollectHandler();
+			//
+			List<Nodeid> liteResult = cmd.executeLite();
+			cmd.executeFull(collector);
+			eh.run("hg", "outgoing", "--debug", dstRemote.getLocation());
+			TestIncoming.report(collector, outParser, liteResult, errorCollector);
+		} finally {
+			server.stop();
+		}
 	}
 }