annotate test/org/tmatesoft/hg/test/RepoUtils.java @ 709:497e697636fc

Report merged lines as changed block if possible, not as a sequence of added/deleted blocks. To facilitate access to merge parent lines AddBlock got mergeLineAt() method that reports index of the line in the second parent (if any), while insertedAt() has been changed to report index in the first parent always
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 21 Aug 2013 16:23:27 +0200
parents 42b88709e41d
children
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;
536
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31
635
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 631
diff changeset
32 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
33
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
34 import org.tmatesoft.hg.core.HgException;
637
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
35 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
36 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
37 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
38 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
39 import org.tmatesoft.hg.repo.HgRepository;
637
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
40 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
41
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 * @author Artem Tikhomirov
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45 * @author TMate Software Ltd.
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46 */
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47 public class RepoUtils {
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48
637
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
49 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
50 File dest = createEmptyDir(dirName);
637
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
51 try {
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
52 new HgInitCommand().location(dest).revlogV1().execute();
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
53 } catch (CancelledException ex) {
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
54 Assert.fail(ex.toString());
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
55 }
536
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
56 return dest;
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57 }
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 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
60 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
61 if (dest.exists()) {
637
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
62 rmdir(dest);
536
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
63 }
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 dest.mkdirs();
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65 return dest;
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66 }
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
67
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
68 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
69 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
70 }
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 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
73 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
74 }
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 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
77 File testRepoLoc = createEmptyDir(name);
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
78 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
79 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
80 cmd.add("hg");
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
81 cmd.add("clone");
536
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
82 if (noupdate) {
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
83 cmd.add("--noupdate");
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
84 }
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
85 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
86 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
87 }
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 cmd.add(repoLoc.toString());
536
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
89 cmd.add(testRepoLoc.getName());
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
90 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
91 assertEquals("[sanity]", 0, eh.getExitValue());
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
92 return testRepoLoc;
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
93 }
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
94
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 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
96 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
97 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
98 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
99 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
100 {
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 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
102 }
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 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
104 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
105 }
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 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
107 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
108 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
109 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
110 }
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 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
112 }
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 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
114 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
115 }
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 };
654
12a4f60ea972 1) Console push tool. 2) Pass class to blame into FileUtils
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 653
diff changeset
117 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
118 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
119 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
120 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
121 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
122 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
123 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
124 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
125 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
126 } 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
127 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
128 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
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: 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 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
132 }
536
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
133
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
134 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
135 assertTrue(f.isFile());
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
136 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
137 if (content == null) {
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
138 content = "XXX".getBytes();
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
139 }
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
140 if (content instanceof byte[]) {
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
141 fos.write((byte[]) content);
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
142 } else {
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
143 fos.write(String.valueOf(content).getBytes());
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
144 }
536
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
145 fos.close();
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
146 }
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
147
559
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
148 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
149 if (content == null) {
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
150 f.createNewFile();
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
151 return;
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
152 }
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
153 if (content instanceof byte[]) {
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
154 FileOutputStream fos = new FileOutputStream(f);
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
155 fos.write((byte[]) content);
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
156 fos.close();
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
157 } else {
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
158 FileWriter fw = new FileWriter(f);
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
159 fw.write(String.valueOf(content));
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
160 fw.close();
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
161 }
6ca3d0c5b4bc Commit: tests and fixes for defects discovered
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 536
diff changeset
162 }
635
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 631
diff changeset
163
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 631
diff changeset
164 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
165 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
166 try {
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 631
diff changeset
167 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
168 eh.run(args);
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 631
diff changeset
169 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
170 } catch (Exception ex) {
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 631
diff changeset
171 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
172 throw ex;
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 631
diff changeset
173 }
4ec2d44e2bf3 Compound test scenario for checkout, add, remove, revert and commit
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 631
diff changeset
174 }
637
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
175
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
176 static void rmdir(File dest) throws IOException {
707
42b88709e41d Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 660
diff changeset
177 FileUtils.rmdir(dest);
637
4a0bab2c6da1 HgInitCommand: expose repo init functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 635
diff changeset
178 }
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
179
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
180 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
181 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
182 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
183 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
184 }
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
185 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
186 }
660
4fd317a2fecf Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 654
diff changeset
187
4fd317a2fecf Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 654
diff changeset
188 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
189 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
190 verifyRun.run("hg", "verify");
4fd317a2fecf Pull: phase1 get remote changes and add local revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 654
diff changeset
191 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
192 }
536
2813a26b8999 Tests: refactor various utility methods to a single location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
193 }