annotate test/org/tmatesoft/hg/test/RepoUtils.java @ 677:1c49c0cee540

Report line number at the first appearance, like 'hg annotate -l' does
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 18 Jul 2013 18:47:45 +0200
parents 4fd317a2fecf
children 42b88709e41d
rev   line source
536
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2013 TMate Software Ltd
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 *
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 *
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 *
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 * For information on how to redistribute this software under
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14 * the terms of a license other than GNU General Public License
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
15 * contact TMate Software at support@hg4j.com
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 package org.tmatesoft.hg.test;
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
19 import static org.junit.Assert.assertEquals;
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20 import static org.junit.Assert.assertTrue;
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: 622
diff changeset
21 import static org.tmatesoft.hg.util.LogFacility.Severity.Debug;
536
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23 import java.io.File;
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24 import java.io.FileOutputStream;
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
25 import java.io.FileWriter;
536
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26 import java.io.IOException;
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 import java.util.ArrayList;
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: 622
diff changeset
28 import java.util.Arrays;
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
29 import java.util.Iterator;
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
30 import java.util.LinkedList;
637
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
31 import java.util.List;
536
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32
635
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 631
diff changeset
33 import junit.framework.Assert;
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 631
diff changeset
34
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: 622
diff changeset
35 import org.tmatesoft.hg.core.HgException;
637
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
36 import org.tmatesoft.hg.core.HgInitCommand;
653
629a7370554c Tests for recent changes in HgParentChildMap and RepositoryComparator (outgoing to respect drafts and Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 637
diff changeset
37 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: 622
diff changeset
38 import org.tmatesoft.hg.internal.FileUtils;
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
39 import org.tmatesoft.hg.internal.StreamLogFacility;
536
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40 import org.tmatesoft.hg.repo.HgRepository;
637
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
41 import org.tmatesoft.hg.util.CancelledException;
536
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 /**
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 *
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45 * @author Artem Tikhomirov
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46 * @author TMate Software Ltd.
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47 */
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48 public class RepoUtils {
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49
637
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
50 static File initEmptyTempRepo(String dirName) throws IOException, HgException {
536
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
51 File dest = createEmptyDir(dirName);
637
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
52 try {
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
53 new HgInitCommand().location(dest).revlogV1().execute();
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
54 } catch (CancelledException ex) {
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
55 Assert.fail(ex.toString());
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
56 }
536
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57 return dest;
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58 }
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
59
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60 static File createEmptyDir(String dirName) throws IOException {
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61 File dest = new File(Configuration.get().getTempDir(), dirName);
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
62 if (dest.exists()) {
637
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
63 rmdir(dest);
536
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 }
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65 dest.mkdirs();
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66 return dest;
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
67 }
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
68
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: 622
diff changeset
69 static File cloneRepoToTempLocation(String configRepoName, String name, boolean noupdate) throws HgException, IOException, InterruptedException {
536
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
70 return cloneRepoToTempLocation(Configuration.get().find(configRepoName), name, noupdate);
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
71 }
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
72
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73 static File cloneRepoToTempLocation(HgRepository repo, String name, boolean noupdate) throws IOException, InterruptedException {
631
8a5cdcb27b8f AIOOBE in HgManifest.RevisionMapper. Provide more details about exception context. Create lock file atomically. Test concurrent pull-rebase and read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 623
diff changeset
74 return cloneRepoToTempLocation(repo.getWorkingDir(), name, noupdate, false);
8a5cdcb27b8f AIOOBE in HgManifest.RevisionMapper. Provide more details about exception context. Create lock file atomically. Test concurrent pull-rebase and read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 623
diff changeset
75 }
8a5cdcb27b8f AIOOBE in HgManifest.RevisionMapper. Provide more details about exception context. Create lock file atomically. Test concurrent pull-rebase and read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 623
diff changeset
76
8a5cdcb27b8f AIOOBE in HgManifest.RevisionMapper. Provide more details about exception context. Create lock file atomically. Test concurrent pull-rebase and read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 623
diff changeset
77 static File cloneRepoToTempLocation(File repoLoc, String name, boolean noupdate, boolean usePull) throws IOException, InterruptedException {
536
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
78 File testRepoLoc = createEmptyDir(name);
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
79 ExecHelper eh = new ExecHelper(new OutputParser.Stub(), testRepoLoc.getParentFile());
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
80 ArrayList<String> cmd = new ArrayList<String>();
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
81 cmd.add("hg");
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
82 cmd.add("clone");
536
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
83 if (noupdate) {
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
84 cmd.add("--noupdate");
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
85 }
631
8a5cdcb27b8f AIOOBE in HgManifest.RevisionMapper. Provide more details about exception context. Create lock file atomically. Test concurrent pull-rebase and read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 623
diff changeset
86 if (usePull) {
8a5cdcb27b8f AIOOBE in HgManifest.RevisionMapper. Provide more details about exception context. Create lock file atomically. Test concurrent pull-rebase and read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 623
diff changeset
87 cmd.add("--pull");
8a5cdcb27b8f AIOOBE in HgManifest.RevisionMapper. Provide more details about exception context. Create lock file atomically. Test concurrent pull-rebase and read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 623
diff changeset
88 }
8a5cdcb27b8f AIOOBE in HgManifest.RevisionMapper. Provide more details about exception context. Create lock file atomically. Test concurrent pull-rebase and read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 623
diff changeset
89 cmd.add(repoLoc.toString());
536
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
90 cmd.add(testRepoLoc.getName());
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
91 eh.run(cmd.toArray(new String[cmd.size()]));
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
92 assertEquals("[sanity]", 0, eh.getExitValue());
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
93 return testRepoLoc;
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
94 }
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: 622
diff changeset
95
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
96 static File copyRepoToTempLocation(String configRepoName, String newRepoName) throws HgException, IOException {
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
97 File testRepoLoc = createEmptyDir(newRepoName);
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
98 final File srcDir = Configuration.get().find(configRepoName).getWorkingDir();
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
99 Iterator<File> it = new Iterator<File>() {
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
100 private final LinkedList<File> queue = new LinkedList<File>();
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
101 {
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
102 queue.addAll(Arrays.asList(srcDir.listFiles()));
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
103 }
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
104 public boolean hasNext() {
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
105 return !queue.isEmpty();
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
106 }
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
107 public File next() {
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
108 File n = queue.removeFirst();
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
109 if (n.isDirectory()) {
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
110 queue.addAll(Arrays.asList(n.listFiles()));
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
111 }
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
112 return n;
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
113 }
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
114 public void remove() {
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
115 throw new UnsupportedOperationException();
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
116 }
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
117 };
654
12a4f60ea972 1) Console push tool. 2) Pass class to blame into FileUtils
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 653
diff changeset
118 FileUtils fu = new FileUtils(new StreamLogFacility(Debug, true, System.err), RepoUtils.class);
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: 622
diff changeset
119 String srcPrefix = srcDir.getAbsolutePath();
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
120 while (it.hasNext()) {
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
121 File next = it.next();
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
122 assert next.getAbsolutePath().startsWith(srcPrefix);
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
123 String relPath = next.getAbsolutePath().substring(srcPrefix.length());
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
124 File dest = new File(testRepoLoc, relPath);
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
125 if (next.isDirectory()) {
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
126 dest.mkdir();
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
127 } 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: 622
diff changeset
128 fu.copy(next, dest);
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
129 dest.setLastModified(next.lastModified());
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
130 }
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
131 }
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
132 return testRepoLoc;
fedc54356091 Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
133 }
536
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
134
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
135 static void modifyFileAppend(File f, Object content) throws IOException {
536
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
136 assertTrue(f.isFile());
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
137 FileOutputStream fos = new FileOutputStream(f, true);
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
138 if (content == null) {
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
139 content = "XXX".getBytes();
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
140 }
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
141 if (content instanceof byte[]) {
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
142 fos.write((byte[]) content);
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
143 } else {
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
144 fos.write(String.valueOf(content).getBytes());
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
145 }
536
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
146 fos.close();
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
147 }
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
148
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
149 static void createFile(File f, Object content) throws IOException {
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
150 if (content == null) {
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
151 f.createNewFile();
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
152 return;
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
153 }
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
154 if (content instanceof byte[]) {
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
155 FileOutputStream fos = new FileOutputStream(f);
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
156 fos.write((byte[]) content);
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
157 fos.close();
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
158 } else {
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
159 FileWriter fw = new FileWriter(f);
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
160 fw.write(String.valueOf(content));
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
161 fw.close();
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
162 }
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
163 }
635
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 631
diff changeset
164
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 631
diff changeset
165 static void exec(File wd, int expectedRetVal, String... args) throws Exception {
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 631
diff changeset
166 OutputParser.Stub s = new OutputParser.Stub();
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 631
diff changeset
167 try {
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 631
diff changeset
168 ExecHelper eh = new ExecHelper(s, wd);
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 631
diff changeset
169 eh.run(args);
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 631
diff changeset
170 Assert.assertEquals(expectedRetVal, eh.getExitValue());
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 631
diff changeset
171 } catch (Exception ex) {
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 631
diff changeset
172 System.err.println(s.result());
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 631
diff changeset
173 throw ex;
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 631
diff changeset
174 }
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 631
diff changeset
175 }
637
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
176
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
177 static void rmdir(File dest) throws IOException {
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
178 LinkedList<File> queue = new LinkedList<File>();
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
179 queue.addAll(Arrays.asList(dest.listFiles()));
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
180 while (!queue.isEmpty()) {
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
181 File next = queue.removeFirst();
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
182 if (next.isDirectory()) {
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
183 List<File> files = Arrays.asList(next.listFiles());
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
184 if (!files.isEmpty()) {
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
185 queue.addAll(files);
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
186 queue.add(next);
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
187 }
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
188 // fall through
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
189 }
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
190 next.delete();
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
191 }
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
192 dest.delete();
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
193 }
653
629a7370554c Tests for recent changes in HgParentChildMap and RepositoryComparator (outgoing to respect drafts and Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 637
diff changeset
194
629a7370554c Tests for recent changes in HgParentChildMap and RepositoryComparator (outgoing to respect drafts and Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 637
diff changeset
195 static Nodeid[] allRevisions(HgRepository repo) {
629a7370554c Tests for recent changes in HgParentChildMap and RepositoryComparator (outgoing to respect drafts and Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 637
diff changeset
196 Nodeid[] allRevs = new Nodeid[repo.getChangelog().getRevisionCount()];
629a7370554c Tests for recent changes in HgParentChildMap and RepositoryComparator (outgoing to respect drafts and Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 637
diff changeset
197 for (int i = 0; i < allRevs.length; i++) {
629a7370554c Tests for recent changes in HgParentChildMap and RepositoryComparator (outgoing to respect drafts and Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 637
diff changeset
198 allRevs[i] = repo.getChangelog().getRevision(i);
629a7370554c Tests for recent changes in HgParentChildMap and RepositoryComparator (outgoing to respect drafts and Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 637
diff changeset
199 }
629a7370554c Tests for recent changes in HgParentChildMap and RepositoryComparator (outgoing to respect drafts and Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 637
diff changeset
200 return allRevs;
629a7370554c Tests for recent changes in HgParentChildMap and RepositoryComparator (outgoing to respect drafts and Issue 47)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 637
diff changeset
201 }
660
4fd317a2fecf Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 654
diff changeset
202
4fd317a2fecf Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 654
diff changeset
203 static void assertHgVerifyOk(ErrorCollectorExt errorCollector, File repoLoc) throws InterruptedException, IOException {
4fd317a2fecf Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 654
diff changeset
204 ExecHelper verifyRun = new ExecHelper(new OutputParser.Stub(), repoLoc);
4fd317a2fecf Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 654
diff changeset
205 verifyRun.run("hg", "verify");
4fd317a2fecf Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 654
diff changeset
206 errorCollector.assertEquals("hg verify", 0, verifyRun.getExitValue());
4fd317a2fecf Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 654
diff changeset
207 }
536
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
208 }