tikhomirov@203: /* tikhomirov@653: * Copyright (c) 2011-2013 TMate Software Ltd tikhomirov@203: * tikhomirov@203: * This program is free software; you can redistribute it and/or modify tikhomirov@203: * it under the terms of the GNU General Public License as published by tikhomirov@203: * the Free Software Foundation; version 2 of the License. tikhomirov@203: * tikhomirov@203: * This program is distributed in the hope that it will be useful, tikhomirov@203: * but WITHOUT ANY WARRANTY; without even the implied warranty of tikhomirov@203: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the tikhomirov@203: * GNU General Public License for more details. tikhomirov@203: * tikhomirov@203: * For information on how to redistribute this software under tikhomirov@203: * the terms of a license other than GNU General Public License tikhomirov@203: * contact TMate Software at support@hg4j.com tikhomirov@203: */ tikhomirov@203: package org.tmatesoft.hg.test; tikhomirov@203: tikhomirov@653: import static org.junit.Assert.assertEquals; tikhomirov@653: import static org.junit.Assert.assertTrue; tikhomirov@653: tikhomirov@203: import java.io.File; tikhomirov@203: import java.util.List; tikhomirov@203: tikhomirov@203: import org.junit.Assert; tikhomirov@203: import org.junit.Rule; tikhomirov@203: import org.junit.Test; tikhomirov@653: import org.tmatesoft.hg.core.HgCheckoutCommand; tikhomirov@653: import org.tmatesoft.hg.core.HgCommitCommand; tikhomirov@203: import org.tmatesoft.hg.core.HgLogCommand; tikhomirov@203: import org.tmatesoft.hg.core.HgOutgoingCommand; tikhomirov@203: import org.tmatesoft.hg.core.Nodeid; tikhomirov@203: import org.tmatesoft.hg.repo.HgLookup; tikhomirov@203: import org.tmatesoft.hg.repo.HgRemoteRepository; tikhomirov@653: import org.tmatesoft.hg.repo.HgRepository; tikhomirov@203: tikhomirov@203: /** tikhomirov@203: * tikhomirov@203: * @author Artem Tikhomirov tikhomirov@203: * @author TMate Software Ltd. tikhomirov@203: */ tikhomirov@203: public class TestOutgoing { tikhomirov@203: tikhomirov@203: @Rule tikhomirov@203: public ErrorCollectorExt errorCollector = new ErrorCollectorExt(); tikhomirov@203: tikhomirov@203: public static void main(String[] args) throws Throwable { tikhomirov@203: Configuration.get().remoteServers("http://localhost:8000/"); tikhomirov@203: TestOutgoing t = new TestOutgoing(); tikhomirov@203: t.testSimple(); tikhomirov@203: t.errorCollector.verify(); tikhomirov@203: } tikhomirov@203: tikhomirov@203: public TestOutgoing() { tikhomirov@203: } tikhomirov@203: tikhomirov@203: @Test tikhomirov@203: public void testSimple() throws Exception { tikhomirov@203: int x = 0; tikhomirov@203: HgLookup lookup = new HgLookup(); tikhomirov@203: for (HgRemoteRepository hgRemote : Configuration.get().allRemote()) { tikhomirov@536: File dest = RepoUtils.createEmptyDir("test-outgoing-" + x++); tikhomirov@203: ExecHelper eh0 = new ExecHelper(new OutputParser.Stub(false), null); tikhomirov@203: eh0.run("hg", "clone", hgRemote.getLocation(), dest.toString()); tikhomirov@203: eh0.cwd(dest); tikhomirov@203: Assert.assertEquals("initial clone failed", 0, eh0.getExitValue()); tikhomirov@203: HgOutgoingCommand cmd = new HgOutgoingCommand(lookup.detect(dest)).against(hgRemote); tikhomirov@203: LogOutputParser outParser = new LogOutputParser(true); tikhomirov@203: ExecHelper eh = new ExecHelper(outParser, dest); tikhomirov@203: HgLogCommand.CollectHandler collector = new HgLogCommand.CollectHandler(); tikhomirov@203: // tikhomirov@203: cmd.executeFull(collector); tikhomirov@215: List liteResult = cmd.executeLite(); tikhomirov@203: eh.run("hg", "outgoing", "--debug", hgRemote.getLocation()); tikhomirov@203: TestIncoming.report(collector, outParser, liteResult, errorCollector); tikhomirov@203: // tikhomirov@203: File f = new File(dest, "Test.txt"); tikhomirov@653: RepoUtils.createFile(f, "1"); tikhomirov@203: eh0.run("hg", "add"); tikhomirov@203: eh0.run("hg", "commit", "-m", "1"); tikhomirov@653: RepoUtils.modifyFileAppend(f, "2"); tikhomirov@203: eh0.run("hg", "commit", "-m", "2"); tikhomirov@203: // tikhomirov@203: cmd = new HgOutgoingCommand(lookup.detect(dest)).against(hgRemote); tikhomirov@203: cmd.executeFull(collector = new HgLogCommand.CollectHandler()); tikhomirov@215: liteResult = cmd.executeLite(); tikhomirov@203: outParser.reset(); tikhomirov@203: eh.run("hg", "outgoing", "--debug", hgRemote.getLocation()); tikhomirov@203: TestIncoming.report(collector, outParser, liteResult, errorCollector); tikhomirov@203: } tikhomirov@203: } tikhomirov@653: tikhomirov@653: /** tikhomirov@653: * Issue 47: Incorrect set of outgoing changes when revision spins off prior to common revision of local and remote repos tikhomirov@653: */ tikhomirov@653: @Test tikhomirov@653: public void testOutgoingPreceedsCommon() throws Exception { tikhomirov@653: File srcRepoLoc = RepoUtils.cloneRepoToTempLocation("test-annotate", "test-outgoing-src", false); tikhomirov@653: File dstRepoLoc = RepoUtils.cloneRepoToTempLocation("test-annotate", "test-outgoing-dst", false); tikhomirov@653: File f1 = new File(srcRepoLoc, "file1"); tikhomirov@653: assertTrue("[sanity]", f1.canWrite()); tikhomirov@653: HgServer server = new HgServer().start(dstRepoLoc); tikhomirov@653: try { tikhomirov@653: final HgLookup hgLookup = new HgLookup(); tikhomirov@653: final HgRepository srcRepo = hgLookup.detect(srcRepoLoc); tikhomirov@653: final HgRemoteRepository dstRemote = hgLookup.detect(server.getURL()); tikhomirov@653: new HgCheckoutCommand(srcRepo).changeset(6).clean(true).execute(); tikhomirov@653: assertEquals("[sanity]", "with-merge", srcRepo.getWorkingCopyBranchName()); tikhomirov@653: RepoUtils.modifyFileAppend(f1, "change1"); tikhomirov@653: new HgCommitCommand(srcRepo).message("Commit 1").execute(); tikhomirov@653: new HgCheckoutCommand(srcRepo).changeset(5).clean(true).execute(); tikhomirov@653: assertEquals("[sanity]", "no-merge", srcRepo.getWorkingCopyBranchName()); tikhomirov@653: RepoUtils.modifyFileAppend(f1, "change2"); tikhomirov@653: new HgCommitCommand(srcRepo).message("Commit 2").execute(); tikhomirov@653: // tikhomirov@653: HgOutgoingCommand cmd = new HgOutgoingCommand(srcRepo).against(dstRemote); tikhomirov@653: LogOutputParser outParser = new LogOutputParser(true); tikhomirov@653: ExecHelper eh = new ExecHelper(outParser, srcRepoLoc); tikhomirov@653: HgLogCommand.CollectHandler collector = new HgLogCommand.CollectHandler(); tikhomirov@653: // tikhomirov@653: List liteResult = cmd.executeLite(); tikhomirov@653: cmd.executeFull(collector); tikhomirov@653: eh.run("hg", "outgoing", "--debug", dstRemote.getLocation()); tikhomirov@653: TestIncoming.report(collector, outParser, liteResult, errorCollector); tikhomirov@653: } finally { tikhomirov@653: server.stop(); tikhomirov@653: } tikhomirov@203: } tikhomirov@203: }