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