comparison test/org/tmatesoft/hg/test/TestPull.java @ 660:4fd317a2fecf

Pull: phase1 get remote changes and add local revisions
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 09 Jul 2013 21:46:45 +0200
parents
children 46b56864b483
comparison
equal deleted inserted replaced
658:d10399f80f4e 660:4fd317a2fecf
1 /*
2 * Copyright (c) 2013 TMate Software Ltd
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * For information on how to redistribute this software under
14 * the terms of a license other than GNU General Public License
15 * contact TMate Software at support@hg4j.com
16 */
17 package org.tmatesoft.hg.test;
18
19 import static org.tmatesoft.hg.repo.HgRepository.TIP;
20
21 import java.io.File;
22 import java.util.List;
23
24 import org.junit.Rule;
25 import org.junit.Test;
26 import org.tmatesoft.hg.core.HgIncomingCommand;
27 import org.tmatesoft.hg.core.HgPullCommand;
28 import org.tmatesoft.hg.core.Nodeid;
29 import org.tmatesoft.hg.repo.HgLookup;
30 import org.tmatesoft.hg.repo.HgRemoteRepository;
31 import org.tmatesoft.hg.repo.HgRepository;
32
33 /**
34 *
35 * @author Artem Tikhomirov
36 * @author TMate Software Ltd.
37 */
38 public class TestPull {
39
40 @Rule
41 public ErrorCollectorExt errorCollector = new ErrorCollectorExt();
42
43 @Test
44 public void testPullToEmpty() throws Exception {
45 File srcRepoLoc = RepoUtils.cloneRepoToTempLocation("test-annotate", "test-pull2empty-src", false);
46 File dstRepoLoc = RepoUtils.initEmptyTempRepo("test-pull2empty-dst");
47 HgServer server = new HgServer().start(srcRepoLoc);
48 try {
49 final HgLookup hgLookup = new HgLookup();
50 final HgRemoteRepository srcRemote = hgLookup.detect(server.getURL());
51 HgRepository dstRepo = hgLookup.detect(dstRepoLoc);
52 HgPullCommand cmd = new HgPullCommand(dstRepo).source(srcRemote);
53 cmd.execute();
54 final HgRepository srcRepo = hgLookup.detect(srcRepoLoc);
55 checkRepositoriesAreSame(srcRepo, dstRepo);
56 final List<Nodeid> incoming = new HgIncomingCommand(dstRepo).against(srcRemote).executeLite();
57 errorCollector.assertTrue(incoming.toString(), incoming.isEmpty());
58 RepoUtils.assertHgVerifyOk(errorCollector, dstRepoLoc);
59 } finally {
60 server.stop();
61 }
62 }
63
64 // test when pull comes with new file (if AddRevInspector/RevlogStreamWriter is ok with file that doesn't exist
65
66 private void checkRepositoriesAreSame(HgRepository srcRepo, HgRepository dstRepo) {
67 // XXX copy of TestPush#checkRepositoriesAreSame
68 errorCollector.assertEquals(srcRepo.getChangelog().getRevisionCount(), dstRepo.getChangelog().getRevisionCount());
69 errorCollector.assertEquals(srcRepo.getChangelog().getRevision(0), dstRepo.getChangelog().getRevision(0));
70 errorCollector.assertEquals(srcRepo.getChangelog().getRevision(TIP), dstRepo.getChangelog().getRevision(TIP));
71 }
72 }