Skip to content

Commit af2d648

Browse files
committed
Removed usage of repository.repository (Close #143)
1 parent bc5eff3 commit af2d648

File tree

6 files changed

+45
-22
lines changed

6 files changed

+45
-22
lines changed

src/commands.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,9 @@ export class SvnCommands {
243243
});
244244

245245
try {
246-
const result = await repository.repository.commitFiles(
247-
message,
248-
filePaths
249-
);
246+
const result = await repository.commitFiles(message, filePaths);
250247
window.showInformationMessage(result);
251248
repository.inputBox.value = "";
252-
repository.updateModelState();
253249
} catch (error) {
254250
console.error(error);
255251
window.showErrorMessage(error);
@@ -367,9 +363,8 @@ export class SvnCommands {
367363
return;
368364
}
369365

370-
const result = await repository.repository.commitFiles(message, paths);
366+
const result = await repository.commitFiles(message, paths);
371367
window.showInformationMessage(result);
372-
repository.updateModelState();
373368
} catch (error) {
374369
console.error(error);
375370
window.showErrorMessage("Unable to commit");
@@ -711,7 +706,7 @@ export class SvnCommands {
711706
});
712707

713708
await this.runByRepository(paths, async (repository, paths) =>
714-
repository.repository.revert(paths)
709+
repository.revert(paths)
715710
);
716711
} catch (error) {
717712
console.error(error);
@@ -733,7 +728,7 @@ export class SvnCommands {
733728
@command("svn.patch", { repository: true })
734729
async patch(repository: Repository) {
735730
try {
736-
const result = await repository.repository.patch();
731+
const result = await repository.patch();
737732
// send the patch results to a new tab
738733
workspace
739734
.openTextDocument({ language: "diff", content: result })
@@ -774,8 +769,7 @@ export class SvnCommands {
774769
return state.resourceUri.fsPath;
775770
});
776771

777-
const result = await repository.repository.removeFiles(paths, keepLocal);
778-
repository.updateModelState();
772+
const result = await repository.removeFiles(paths, keepLocal);
779773
} catch (error) {
780774
console.error(error);
781775
window.showErrorMessage("Unable to remove files");
@@ -817,7 +811,7 @@ export class SvnCommands {
817811
@command("svn.log", { repository: true })
818812
async log(repository: Repository) {
819813
try {
820-
const result = await repository.repository.log();
814+
const result = await repository.log();
821815
// send the log results to a new tab
822816
workspace.openTextDocument({ content: result }).then(doc => {
823817
window.showTextDocument(doc);

src/model.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,10 @@ export class Model {
308308
throw new Error("There are no available repositories");
309309
}
310310

311-
const picks: any[] = this.openRepositories.map(repository => {
311+
const picks: any[] = this.repositories.map(repository => {
312312
return {
313-
label: path.basename(repository.repository.root),
314-
repository: repository.repository
313+
label: path.basename(repository.root),
314+
repository: repository
315315
};
316316
});
317317
const placeHolder = "Choose a repository";

src/repository.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,14 @@ export enum RepositoryState {
3939
export enum Operation {
4040
Add = "Add",
4141
AddChangelist = "AddChangelist",
42+
Commit = "Commit",
43+
Log = "Log",
4244
NewBranch = "NewBranch",
45+
Patch = "Patch",
46+
Remove = "Remove",
4347
RemoveChangelist = "RemoveChangelist",
4448
Resolve = "Resolve",
49+
Revert = "Revert",
4550
Show = "Show",
4651
Status = "Status",
4752
SwitchBranch = "SwitchBranch",
@@ -50,6 +55,7 @@ export enum Operation {
5055

5156
function isReadOnly(operation: Operation): boolean {
5257
switch (operation) {
58+
case Operation.Log:
5359
case Operation.Show:
5460
return true;
5561
default:
@@ -550,6 +556,32 @@ export class Repository {
550556
);
551557
}
552558

559+
async commitFiles(message: string, files: any[]) {
560+
return await this.run(Operation.Commit, () =>
561+
this.repository.commitFiles(message, files)
562+
);
563+
}
564+
565+
async revert(files: Uri[] | string[]) {
566+
return await this.run(Operation.Revert, () =>
567+
this.repository.revert(files)
568+
);
569+
}
570+
571+
async patch() {
572+
return await this.run(Operation.Patch, () => this.repository.patch());
573+
}
574+
575+
async removeFiles(files: any[], keepLocal: boolean) {
576+
return await this.run(Operation.Remove, () =>
577+
this.repository.removeFiles(files, keepLocal)
578+
);
579+
}
580+
581+
async log() {
582+
return await this.run(Operation.Log, () => this.repository.log());
583+
}
584+
553585
private async run<T>(
554586
operation: Operation,
555587
runOperation: () => Promise<T> = () => Promise.resolve<any>(null)

src/svn.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ export class Svn {
317317
return this.exec(root, ["switch", path]);
318318
}
319319

320-
revert(files: any[]) {
320+
revert(files: Uri[] | string[]) {
321321
let args = ["revert"];
322322

323323
for (let file of files) {

src/svnRepository.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { workspace } from "vscode";
1+
import { workspace, Uri } from "vscode";
22
import { Svn, CpOptions } from "./svn";
33
import { IFileStatus, parseStatusXml } from "./statusParser";
44
import { parseInfoXml, ISvnInfo } from "./infoParser";
@@ -240,7 +240,7 @@ export class Repository {
240240
return true;
241241
}
242242

243-
async revert(files: any[]) {
243+
async revert(files: Uri[] | string[]) {
244244
const result = await this.svn.revert(files);
245245

246246
return result.stdout;

src/test/repository.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,21 +99,18 @@ suite("Repository Tests", () => {
9999

100100
const file = path.join(checkoutDir.fsPath, "new.txt");
101101

102-
await repository.updateModelState();
103102
fs.writeFileSync(file, "test");
104103

105104
await repository.addFile(file);
106105

107-
await repository.updateModelState();
108106
await timeout(1500); // Wait the debounce time
109107
assert.equal(repository.changes.resourceStates.length, 1);
110108

111-
const message = await repository.repository.commitFiles("First Commit", [
109+
const message = await repository.commitFiles("First Commit", [
112110
file
113111
]);
114112
assert.ok(/Committed revision (.*)\./i.test(message));
115113

116-
await repository.updateModelState();
117114
await timeout(1500); // Wait the debounce time
118115
assert.equal(repository.changes.resourceStates.length, 0);
119116

0 commit comments

Comments
 (0)