tikhomirov@660: /* tikhomirov@660: * Copyright (c) 2013 TMate Software Ltd tikhomirov@660: * tikhomirov@660: * This program is free software; you can redistribute it and/or modify tikhomirov@660: * it under the terms of the GNU General Public License as published by tikhomirov@660: * the Free Software Foundation; version 2 of the License. tikhomirov@660: * tikhomirov@660: * This program is distributed in the hope that it will be useful, tikhomirov@660: * but WITHOUT ANY WARRANTY; without even the implied warranty of tikhomirov@660: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the tikhomirov@660: * GNU General Public License for more details. tikhomirov@660: * tikhomirov@660: * For information on how to redistribute this software under tikhomirov@660: * the terms of a license other than GNU General Public License tikhomirov@660: * contact TMate Software at support@hg4j.com tikhomirov@660: */ tikhomirov@660: package org.tmatesoft.hg.test; tikhomirov@660: tikhomirov@660: import static org.tmatesoft.hg.repo.HgRepository.TIP; tikhomirov@660: tikhomirov@660: import java.io.File; tikhomirov@660: import java.util.List; tikhomirov@660: tikhomirov@660: import org.junit.Rule; tikhomirov@660: import org.junit.Test; tikhomirov@660: import org.tmatesoft.hg.core.HgIncomingCommand; tikhomirov@660: import org.tmatesoft.hg.core.HgPullCommand; tikhomirov@660: import org.tmatesoft.hg.core.Nodeid; tikhomirov@660: import org.tmatesoft.hg.repo.HgLookup; tikhomirov@660: import org.tmatesoft.hg.repo.HgRemoteRepository; tikhomirov@660: import org.tmatesoft.hg.repo.HgRepository; tikhomirov@660: tikhomirov@660: /** tikhomirov@660: * tikhomirov@660: * @author Artem Tikhomirov tikhomirov@660: * @author TMate Software Ltd. tikhomirov@660: */ tikhomirov@660: public class TestPull { tikhomirov@660: tikhomirov@660: @Rule tikhomirov@660: public ErrorCollectorExt errorCollector = new ErrorCollectorExt(); tikhomirov@660: tikhomirov@660: @Test tikhomirov@660: public void testPullToEmpty() throws Exception { tikhomirov@660: File srcRepoLoc = RepoUtils.cloneRepoToTempLocation("test-annotate", "test-pull2empty-src", false); tikhomirov@660: File dstRepoLoc = RepoUtils.initEmptyTempRepo("test-pull2empty-dst"); tikhomirov@660: HgServer server = new HgServer().start(srcRepoLoc); tikhomirov@660: try { tikhomirov@660: final HgLookup hgLookup = new HgLookup(); tikhomirov@660: final HgRemoteRepository srcRemote = hgLookup.detect(server.getURL()); tikhomirov@660: HgRepository dstRepo = hgLookup.detect(dstRepoLoc); tikhomirov@660: HgPullCommand cmd = new HgPullCommand(dstRepo).source(srcRemote); tikhomirov@660: cmd.execute(); tikhomirov@660: final HgRepository srcRepo = hgLookup.detect(srcRepoLoc); tikhomirov@660: checkRepositoriesAreSame(srcRepo, dstRepo); tikhomirov@660: final List incoming = new HgIncomingCommand(dstRepo).against(srcRemote).executeLite(); tikhomirov@660: errorCollector.assertTrue(incoming.toString(), incoming.isEmpty()); tikhomirov@660: RepoUtils.assertHgVerifyOk(errorCollector, dstRepoLoc); tikhomirov@660: } finally { tikhomirov@660: server.stop(); tikhomirov@660: } tikhomirov@660: } tikhomirov@660: tikhomirov@660: // test when pull comes with new file (if AddRevInspector/RevlogStreamWriter is ok with file that doesn't exist tikhomirov@660: tikhomirov@660: private void checkRepositoriesAreSame(HgRepository srcRepo, HgRepository dstRepo) { tikhomirov@660: // XXX copy of TestPush#checkRepositoriesAreSame tikhomirov@660: errorCollector.assertEquals(srcRepo.getChangelog().getRevisionCount(), dstRepo.getChangelog().getRevisionCount()); tikhomirov@660: errorCollector.assertEquals(srcRepo.getChangelog().getRevision(0), dstRepo.getChangelog().getRevision(0)); tikhomirov@660: errorCollector.assertEquals(srcRepo.getChangelog().getRevision(TIP), dstRepo.getChangelog().getRevision(TIP)); tikhomirov@660: } tikhomirov@660: }