Skip to content

Commit 90fd8a2

Browse files
committed
Rework on repository.ts (Close #141)
* Moved inputs and alerts to commands.ts * Check repository is locked on run command (retryRun) * Get branch list only on switch command * Update status only after commands
1 parent 4d6dbd6 commit 90fd8a2

File tree

7 files changed

+344
-144
lines changed

7 files changed

+344
-144
lines changed

package.json

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,11 @@
317317
"description": "Whether svn is enabled",
318318
"default": true
319319
},
320+
"svn.autorefresh": {
321+
"type": "boolean",
322+
"description": "Whether auto refreshing is enabled",
323+
"default": true
324+
},
320325
"svn.decorations.enabled": {
321326
"type": "boolean",
322327
"description":
@@ -360,13 +365,6 @@
360365
"How frequently (in minutes) to check branch changes. Set to `0` to avoid periodic checks.",
361366
"default": 5
362367
},
363-
"svn.newsCommits.update": {
364-
"type": "number",
365-
"minimum": 0,
366-
"description":
367-
"How frequently (in minutes) to check news commits. Set to `0` to avoid periodic checks.",
368-
"default": 5
369-
},
370368
"svn.multipleFolders.enabled": {
371369
"type": "boolean",
372370
"description": "Allow to find subfolders using SVN",

src/commands.ts

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ import {
88
workspace,
99
SourceControlResourceGroup,
1010
ViewColumn,
11-
SourceControlResourceState
11+
SourceControlResourceState,
12+
ProgressLocation
1213
} from "vscode";
1314
import { inputCommitMessage } from "./messages";
14-
import { Svn, Status } from "./svn";
15+
import { Svn, Status, SvnErrorCodes } from "./svn";
1516
import { Model } from "./model";
1617
import { Repository } from "./repository";
1718
import { Resource } from "./resource";
@@ -84,7 +85,20 @@ class SwitchBranchItem implements QuickPickItem {
8485
}
8586

8687
async run(repository: Repository): Promise<void> {
87-
await repository.switchBranch(this.ref);
88+
try {
89+
await repository.switchBranch(this.ref);
90+
} catch (error) {
91+
if (error.svnErrorCode === SvnErrorCodes.NotShareCommonAncestry) {
92+
window.showErrorMessage(
93+
`Path '${
94+
repository.workspaceRoot
95+
}' does not share common version control ancestry with the requested switch location.`
96+
);
97+
return;
98+
}
99+
100+
window.showErrorMessage("Unable to switch branch");
101+
}
88102
}
89103
}
90104

@@ -235,7 +249,7 @@ export class SvnCommands {
235249
);
236250
window.showInformationMessage(result);
237251
repository.inputBox.value = "";
238-
repository.update();
252+
repository.updateModelState();
239253
} catch (error) {
240254
console.error(error);
241255
window.showErrorMessage(error);
@@ -355,7 +369,7 @@ export class SvnCommands {
355369

356370
const result = await repository.repository.commitFiles(message, paths);
357371
window.showInformationMessage(result);
358-
repository.update();
372+
repository.updateModelState();
359373
} catch (error) {
360374
console.error(error);
361375
window.showErrorMessage("Unable to commit");
@@ -364,8 +378,7 @@ export class SvnCommands {
364378

365379
@command("svn.refresh", { repository: true })
366380
async refresh(repository: Repository) {
367-
repository.update();
368-
repository.updateBranches();
381+
await repository.status();
369382
}
370383

371384
@command("svn.openResourceBase")
@@ -635,12 +648,19 @@ export class SvnCommands {
635648

636649
@command("svn.switchBranch", { repository: true })
637650
async switchBranch(repository: Repository) {
638-
const branches = repository.branches.map(
639-
branch => new SwitchBranchItem(branch)
651+
const branchesPromise = repository.getBranches();
652+
653+
window.withProgress(
654+
{ location: ProgressLocation.Window, title: "Checking remote branches" },
655+
() => branchesPromise
640656
);
657+
658+
const branches = await branchesPromise;
659+
660+
const branchPicks = branches.map(branch => new SwitchBranchItem(branch));
641661
const placeHolder = "Pick a branch to switch to.";
642662
const createBranch = new CreateBranchItem(this);
643-
const picks = [createBranch, ...branches];
663+
const picks = [createBranch, ...branchPicks];
644664

645665
const choice = await window.showQuickPick(picks, { placeHolder });
646666

@@ -755,7 +775,7 @@ export class SvnCommands {
755775
});
756776

757777
const result = await repository.repository.removeFiles(paths, keepLocal);
758-
repository.update();
778+
repository.updateModelState();
759779
} catch (error) {
760780
console.error(error);
761781
window.showErrorMessage("Unable to remove files");
@@ -782,7 +802,15 @@ export class SvnCommands {
782802
return;
783803
}
784804

785-
await repository.resolve(conflict.resourceUri.path, choice.label);
805+
try {
806+
const response = await repository.resolve(
807+
conflict.resourceUri.path,
808+
choice.label
809+
);
810+
window.showInformationMessage(response);
811+
} catch (error) {
812+
window.showErrorMessage(error.stderr);
813+
}
786814
}
787815
}
788816

src/decorationProvider.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ class SvnDecorationProvider implements DecorationProvider {
9696
constructor(private repository: Repository) {
9797
this.disposables.push(
9898
window.registerDecorationProvider(this),
99-
// repository.onDidRunOperation(this.onDidRunOperation, this)
100-
repository.onDidChangeStatus(this.onDidRunOperation, this)
99+
repository.onDidRunOperation(this.onDidRunOperation, this)
101100
);
102101
}
103102

0 commit comments

Comments
 (0)