Mercurial > hg4j
comparison test/org/tmatesoft/hg/test/TestCheckout.java @ 527:47b7bedf0569
Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 15 Jan 2013 19:46:19 +0100 |
parents | 2f9ed6bcefa2 |
children | 2813a26b8999 |
comparison
equal
deleted
inserted
replaced
526:2f9ed6bcefa2 | 527:47b7bedf0569 |
---|---|
14 * the terms of a license other than GNU General Public License | 14 * the terms of a license other than GNU General Public License |
15 * contact TMate Software at support@hg4j.com | 15 * contact TMate Software at support@hg4j.com |
16 */ | 16 */ |
17 package org.tmatesoft.hg.test; | 17 package org.tmatesoft.hg.test; |
18 | 18 |
19 import static org.junit.Assert.assertEquals; | |
20 | |
21 import java.io.File; | |
22 import java.io.FileFilter; | |
23 | |
19 import org.junit.Assert; | 24 import org.junit.Assert; |
25 import org.junit.Rule; | |
20 import org.junit.Test; | 26 import org.junit.Test; |
27 import org.tmatesoft.hg.core.HgCheckoutCommand; | |
28 import org.tmatesoft.hg.core.Nodeid; | |
29 import org.tmatesoft.hg.repo.HgLookup; | |
30 import org.tmatesoft.hg.repo.HgRepository; | |
31 import org.tmatesoft.hg.util.Pair; | |
32 import org.tmatesoft.hg.util.Path; | |
21 | 33 |
22 /** | 34 /** |
23 * | 35 * |
24 * @author Artem Tikhomirov | 36 * @author Artem Tikhomirov |
25 * @author TMate Software Ltd. | 37 * @author TMate Software Ltd. |
26 */ | 38 */ |
27 public class TestCheckout { | 39 public class TestCheckout { |
28 | 40 |
41 @Rule | |
42 public ErrorCollectorExt errorCollector = new ErrorCollectorExt(); | |
43 | |
44 private HgRepository repo; | |
45 private ExecHelper eh; | |
46 | |
29 | 47 |
30 @Test | 48 @Test |
31 public void testCleanCheckoutInEmptyDir() { | 49 public void testCleanCheckoutInEmptyDir() throws Exception { |
32 Assert.fail("clone without update, checkout, status"); | 50 File testRepoLoc = TestRevert.cloneRepoToTempLocation(Configuration.get().find("log-1"), "test-checkoutClean", true); |
51 repo = new HgLookup().detect(testRepoLoc); | |
52 // nothing but .hg dir | |
53 assertEquals("[sanity]", 0, testRepoLoc.listFiles(new FilesOnlyFilter()).length); | |
54 | |
55 new HgCheckoutCommand(repo).changeset(1).execute(); | |
56 errorCollector.assertEquals(2, testRepoLoc.listFiles(new FilesOnlyFilter()).length); | |
57 | |
58 Pair<Nodeid, Nodeid> workingCopyParents = repo.getWorkingCopyParents(); | |
59 errorCollector.assertEquals("da3461cd828dae8eb5fd11189d40e9df1961f191", workingCopyParents.first().toString()); | |
60 errorCollector.assertEquals(Nodeid.NULL, workingCopyParents.second()); | |
61 errorCollector.assertEquals(HgRepository.DEFAULT_BRANCH_NAME, repo.getWorkingCopyBranchName()); | |
62 | |
63 StatusOutputParser statusOutputParser = new StatusOutputParser(); | |
64 eh = new ExecHelper(statusOutputParser, testRepoLoc); | |
65 eh.run("hg", "status", "-A"); | |
66 errorCollector.assertEquals(2, statusOutputParser.getClean().size()); | |
67 errorCollector.assertTrue(statusOutputParser.getClean().contains(Path.create("a"))); | |
68 errorCollector.assertTrue(statusOutputParser.getClean().contains(Path.create("b"))); | |
69 | |
70 new HgCheckoutCommand(repo).changeset(3).execute(); | |
71 statusOutputParser.reset(); | |
72 eh.run("hg", "status", "-A"); | |
73 errorCollector.assertEquals(3, statusOutputParser.getClean().size()); | |
74 errorCollector.assertTrue(statusOutputParser.getClean().contains(Path.create("b"))); | |
75 errorCollector.assertTrue(statusOutputParser.getClean().contains(Path.create("d"))); | |
76 errorCollector.assertTrue(statusOutputParser.getClean().contains(Path.create("dir/b"))); | |
33 } | 77 } |
34 | 78 |
35 @Test | 79 @Test |
36 public void testCleanCheckoutInDirtyDir() { | 80 public void testCleanCheckoutInDirtyDir() { |
37 Assert.fail("Make sure WC is cleared prior to clean checkout"); | 81 Assert.fail("Make sure WC is cleared prior to clean checkout"); |
38 } | 82 } |
39 | 83 |
40 @Test | 84 @Test |
41 public void testBranchCheckout() { | 85 public void testBranchCheckout() throws Exception { |
42 Assert.fail("Make sure branch file is written"); | 86 File testRepoLoc = TestRevert.cloneRepoToTempLocation(Configuration.get().find("log-branches"), "test-checkoutBranch", true); |
87 repo = new HgLookup().detect(testRepoLoc); | |
88 | |
89 new HgCheckoutCommand(repo).changeset(3 /*branch test*/).execute(); | |
90 | |
91 StatusOutputParser statusOutputParser = new StatusOutputParser(); | |
92 eh = new ExecHelper(statusOutputParser, testRepoLoc); | |
93 eh.run("hg", "status", "-A"); | |
94 errorCollector.assertEquals(3, statusOutputParser.getClean().size()); | |
95 errorCollector.assertTrue(statusOutputParser.getClean().contains(Path.create("a"))); | |
96 errorCollector.assertTrue(statusOutputParser.getClean().contains(Path.create("b"))); | |
97 errorCollector.assertTrue(statusOutputParser.getClean().contains(Path.create("c"))); | |
98 | |
99 errorCollector.assertEquals("test", repo.getWorkingCopyBranchName()); | |
100 } | |
101 | |
102 private static final class FilesOnlyFilter implements FileFilter { | |
103 public boolean accept(File f) { | |
104 return f.isFile(); | |
105 } | |
43 } | 106 } |
44 } | 107 } |