annotate test/org/tmatesoft/hg/test/TestCheckout.java @ 623:fedc54356091

Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 20 May 2013 18:35:13 +0200
parents e1b29756f901
children
rev   line source
526
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2013 TMate Software Ltd
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 *
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 *
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 *
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 * For information on how to redistribute this software under
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14 * the terms of a license other than GNU General Public License
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
15 * contact TMate Software at support@hg4j.com
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 package org.tmatesoft.hg.test;
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
527
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
19 import static org.junit.Assert.assertEquals;
563
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
20 import static org.junit.Assert.assertTrue;
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
21 import static org.tmatesoft.hg.repo.HgRepository.TIP;
536
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 527
diff changeset
22 import static org.tmatesoft.hg.test.RepoUtils.cloneRepoToTempLocation;
527
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
23
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
24 import java.io.File;
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
25 import java.io.FileFilter;
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
26
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
27 import org.junit.Rule;
526
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28 import org.junit.Test;
527
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
29 import org.tmatesoft.hg.core.HgCheckoutCommand;
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
30 import org.tmatesoft.hg.core.Nodeid;
623
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
31 import org.tmatesoft.hg.internal.Internals;
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
32 import org.tmatesoft.hg.internal.RelativePathRewrite;
527
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
33 import org.tmatesoft.hg.repo.HgLookup;
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
34 import org.tmatesoft.hg.repo.HgRepository;
580
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
35 import org.tmatesoft.hg.util.FileInfo;
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
36 import org.tmatesoft.hg.util.FileWalker;
527
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
37 import org.tmatesoft.hg.util.Pair;
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
38 import org.tmatesoft.hg.util.Path;
623
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
39 import org.tmatesoft.hg.util.PathRewrite;
526
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41 /**
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42 *
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 * @author Artem Tikhomirov
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 * @author TMate Software Ltd.
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45 */
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46 public class TestCheckout {
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47
527
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
48 @Rule
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
49 public ErrorCollectorExt errorCollector = new ErrorCollectorExt();
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
50
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
51 private HgRepository repo;
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
52 private ExecHelper eh;
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
53
526
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55 @Test
527
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
56 public void testCleanCheckoutInEmptyDir() throws Exception {
563
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
57 File testRepoLoc = cloneRepoToTempLocation("log-1", "test-checkout-clean", true);
527
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
58 repo = new HgLookup().detect(testRepoLoc);
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
59 // nothing but .hg dir
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
60 assertEquals("[sanity]", 0, testRepoLoc.listFiles(new FilesOnlyFilter()).length);
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
61
563
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
62 new HgCheckoutCommand(repo).clean(true).changeset(1).execute();
527
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
63 errorCollector.assertEquals(2, testRepoLoc.listFiles(new FilesOnlyFilter()).length);
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
64
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
65 Pair<Nodeid, Nodeid> workingCopyParents = repo.getWorkingCopyParents();
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
66 errorCollector.assertEquals("da3461cd828dae8eb5fd11189d40e9df1961f191", workingCopyParents.first().toString());
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
67 errorCollector.assertEquals(Nodeid.NULL, workingCopyParents.second());
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
68 errorCollector.assertEquals(HgRepository.DEFAULT_BRANCH_NAME, repo.getWorkingCopyBranchName());
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
69
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
70 StatusOutputParser statusOutputParser = new StatusOutputParser();
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
71 eh = new ExecHelper(statusOutputParser, testRepoLoc);
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
72 eh.run("hg", "status", "-A");
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
73 errorCollector.assertEquals(2, statusOutputParser.getClean().size());
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
74 errorCollector.assertTrue(statusOutputParser.getClean().contains(Path.create("a")));
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
75 errorCollector.assertTrue(statusOutputParser.getClean().contains(Path.create("b")));
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
76
563
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
77 new HgCheckoutCommand(repo).clean(true).changeset(3).execute();
527
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
78 statusOutputParser.reset();
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
79 eh.run("hg", "status", "-A");
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
80 errorCollector.assertEquals(3, statusOutputParser.getClean().size());
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
81 errorCollector.assertTrue(statusOutputParser.getClean().contains(Path.create("b")));
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
82 errorCollector.assertTrue(statusOutputParser.getClean().contains(Path.create("d")));
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
83 errorCollector.assertTrue(statusOutputParser.getClean().contains(Path.create("dir/b")));
526
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
84 }
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
85
563
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
86 /**
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
87 * Make sure WC is cleared prior to clean checkout
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
88 */
526
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
89 @Test
563
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
90 public void testCleanCheckoutInDirtyDir() throws Exception {
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
91 File repoLoc = cloneRepoToTempLocation("log-1", "test-checkout-dirty", false);
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
92 File untrackedFile = new File(repoLoc, "aaa");
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
93 RepoUtils.createFile(untrackedFile, "shall survive hg co --clean");
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
94 File modifiedFile = new File(repoLoc, "b");
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
95 assertTrue("[sanity]", modifiedFile.canRead());
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
96 final long modifiedFileInitialLen = modifiedFile.length();
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
97 RepoUtils.modifyFileAppend(modifiedFile, "the change shall not survive");
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
98 assertTrue("[sanity]", modifiedFile.length() > modifiedFileInitialLen);
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
99 //
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
100 repo = new HgLookup().detect(repoLoc);
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
101 new HgCheckoutCommand(repo).clean(true).changeset(TIP).execute();
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
102 errorCollector.assertTrue(untrackedFile.canRead());
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
103 errorCollector.assertEquals(modifiedFileInitialLen, modifiedFile.length());
526
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
104 }
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
105
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
106 @Test
527
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
107 public void testBranchCheckout() throws Exception {
536
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 527
diff changeset
108 File testRepoLoc = cloneRepoToTempLocation("log-branches", "test-checkoutBranch", true);
527
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
109 repo = new HgLookup().detect(testRepoLoc);
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
110
563
ca56a36c2eea HgCheckoutCommand: clean parameter, discard changes in WD, test for clean checkout
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
111 new HgCheckoutCommand(repo).clean(true).changeset(3 /*branch test*/).execute();
527
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
112
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
113 StatusOutputParser statusOutputParser = new StatusOutputParser();
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
114 eh = new ExecHelper(statusOutputParser, testRepoLoc);
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
115 eh.run("hg", "status", "-A");
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
116 errorCollector.assertEquals(3, statusOutputParser.getClean().size());
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
117 errorCollector.assertTrue(statusOutputParser.getClean().contains(Path.create("a")));
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
118 errorCollector.assertTrue(statusOutputParser.getClean().contains(Path.create("b")));
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
119 errorCollector.assertTrue(statusOutputParser.getClean().contains(Path.create("c")));
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
120
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
121 errorCollector.assertEquals("test", repo.getWorkingCopyBranchName());
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
122 }
580
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
123
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
124 @Test
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
125 public void testCheckoutLinkAndExec() throws Exception {
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
126 File testRepoLoc = cloneRepoToTempLocation("test-flags", "test-checkout-flags", true);
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
127 repo = new HgLookup().detect(testRepoLoc);
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
128 new HgCheckoutCommand(repo).clean(true).changeset(0).execute();
623
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
129
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
130 Path.Source pathSrc = new Path.SimpleSource(new PathRewrite.Composite(new RelativePathRewrite(testRepoLoc), repo.getToRepoPathHelper()));
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
131 FileWalker fw = new FileWalker(repo, testRepoLoc, pathSrc, null);
580
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
132 int execFound, linkFound, regularFound;
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
133 execFound = linkFound = regularFound = 0;
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
134 while(fw.hasNext()) {
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
135 fw.next();
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
136 FileInfo fi = fw.file();
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
137 boolean executable = fi.isExecutable();
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
138 boolean symlink = fi.isSymlink();
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
139 if (executable) {
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
140 execFound++;
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
141 }
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
142 if (symlink) {
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
143 linkFound++;
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
144 }
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
145 if (!executable && !symlink) {
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
146 regularFound++;
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
147 }
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
148 }
623
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
149 final int expectedExec, expectedLink, expectedRegular;
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
150 if (Internals.runningOnWindows()) {
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
151 expectedExec = expectedLink = 0;
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
152 expectedRegular = 2;
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
153 } else {
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
154 expectedExec = expectedLink = expectedRegular = 1;
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
155 }
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
156 errorCollector.assertEquals("Executable files", expectedExec, execFound);
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
157 errorCollector.assertEquals("Symlink files", expectedLink, linkFound);
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 608
diff changeset
158 errorCollector.assertEquals("Regular files", expectedRegular, regularFound);
580
bd5926e24aa3 Respect unix flags for checkout/revert
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 563
diff changeset
159 }
527
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
160
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
161 private static final class FilesOnlyFilter implements FileFilter {
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
162 public boolean accept(File f) {
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
163 return f.isFile();
47b7bedf0569 Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
164 }
526
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
165 }
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
166 }