-
-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathrepository.test.ts
131 lines (103 loc) · 3.9 KB
/
repository.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import * as assert from "assert";
import * as fs from "original-fs";
import * as path from "path";
import { commands, Uri, window, workspace } from "vscode";
import { SourceControlManager } from "../source_control_manager";
import { Repository } from "../repository";
import * as testUtil from "./testUtil";
suite("Repository Tests", () => {
let repoUri: Uri;
let checkoutDir: Uri;
let sourceControlManager: SourceControlManager;
suiteSetup(async () => {
await testUtil.activeExtension();
repoUri = await testUtil.createRepoServer();
await testUtil.createStandardLayout(testUtil.getSvnUrl(repoUri));
checkoutDir = await testUtil.createRepoCheckout(
testUtil.getSvnUrl(repoUri) + "/trunk"
);
sourceControlManager = (await commands.executeCommand(
"svn.getSourceControlManager",
checkoutDir
)) as SourceControlManager;
});
suiteTeardown(() => {
sourceControlManager.openRepositories.forEach(repository =>
repository.dispose()
);
testUtil.destroyAllTempPaths();
});
test("Empty Open Repository", async function () {
assert.equal(sourceControlManager.repositories.length, 0);
});
test("Try Open Repository", async function () {
await sourceControlManager.tryOpenRepository(checkoutDir.fsPath);
assert.equal(sourceControlManager.repositories.length, 1);
});
test("Try Open Repository Again", async () => {
await sourceControlManager.tryOpenRepository(checkoutDir.fsPath);
assert.equal(sourceControlManager.repositories.length, 1);
});
test("Try get repository from Uri", () => {
const repository = sourceControlManager.getRepository(checkoutDir);
assert.ok(repository);
});
test("Try get repository from string", () => {
const repository = sourceControlManager.getRepository(checkoutDir.fsPath);
assert.ok(repository);
});
test("Try get repository from repository", () => {
const repository = sourceControlManager.getRepository(checkoutDir.fsPath);
const repository2 = sourceControlManager.getRepository(repository);
assert.ok(repository2);
assert.equal(repository, repository2);
});
test("Try get current branch name", async () => {
const repository: Repository | null = sourceControlManager.getRepository(
checkoutDir.fsPath
);
if (!repository) {
return;
}
const name = await repository.getCurrentBranch();
assert.equal(name, "trunk");
});
test("Try commit file", async function () {
this.timeout(60000);
const repository: Repository | null = sourceControlManager.getRepository(
checkoutDir.fsPath
);
if (!repository) {
return;
}
assert.equal(repository.changes.resourceStates.length, 0);
const file = path.join(checkoutDir.fsPath, "new.txt");
fs.writeFileSync(file, "test");
const document = await workspace.openTextDocument(file);
await window.showTextDocument(document);
await repository.addFiles([file]);
assert.equal(repository.changes.resourceStates.length, 1);
const message = await repository.commitFiles("First Commit", [file]);
assert.ok(/1 file commited: revision (.*)\./i.test(message));
assert.equal(repository.changes.resourceStates.length, 0);
const remoteContent = await repository.show(file, "HEAD");
assert.equal(remoteContent, "test");
});
test("Try switch branch", async function () {
this.timeout(60000);
const newCheckoutDir = await testUtil.createRepoCheckout(
testUtil.getSvnUrl(repoUri) + "/trunk"
);
await sourceControlManager.tryOpenRepository(newCheckoutDir.fsPath);
const newRepository: Repository | null = sourceControlManager.getRepository(
newCheckoutDir.fsPath
);
if (!newRepository) {
return;
}
assert.ok(newRepository);
await newRepository.newBranch("branches/test");
const currentBranch = await newRepository.getCurrentBranch();
assert.equal(currentBranch, "branches/test");
});
});