Skip to content

Commit 953acf8

Browse files
committed
Fixed changelist and commit in command palette
1 parent af2d648 commit 953acf8

File tree

7 files changed

+194
-92
lines changed

7 files changed

+194
-92
lines changed

icons/dark/check.svg

Lines changed: 1 addition & 0 deletions
Loading

icons/light/check.svg

Lines changed: 1 addition & 0 deletions
Loading

package.json

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,20 @@
8282
{
8383
"command": "svn.commit",
8484
"title": "Commit Selected",
85-
"category": "SVN"
85+
"category": "SVN",
86+
"icon": {
87+
"light": "icons/light/check.svg",
88+
"dark": "icons/dark/check.svg"
89+
}
90+
},
91+
{
92+
"command": "svn.commitWithMessage",
93+
"title": "Commit Changes",
94+
"category": "SVN",
95+
"icon": {
96+
"light": "icons/light/check.svg",
97+
"dark": "icons/dark/check.svg"
98+
}
8699
},
87100
{
88101
"command": "svn.openChangeBase",
@@ -137,12 +150,12 @@
137150
},
138151
{
139152
"command": "svn.update",
140-
"title": "Svn update",
153+
"title": "Update",
141154
"category": "SVN"
142155
},
143156
{
144157
"command": "svn.patch",
145-
"title": "Svn patch",
158+
"title": "Show diff patch",
146159
"category": "SVN"
147160
},
148161
{
@@ -178,13 +191,34 @@
178191
{
179192
"command": "svn.openChangeHead",
180193
"when": "config.svn.enabled && svnOpenRepositoryCount != 0"
194+
},
195+
{
196+
"command": "svn.addChangelist",
197+
"when": "config.svn.enabled && svnOpenRepositoryCount != 0"
198+
},
199+
{
200+
"command": "svn.removeChangelist",
201+
"when": "config.svn.enabled && svnOpenRepositoryCount != 0"
202+
},
203+
{
204+
"command": "svn.commit",
205+
"when": "config.svn.enabled && svnOpenRepositoryCount != 0"
206+
},
207+
{
208+
"command": "svn.commitWithMessage",
209+
"when": "false"
181210
}
182211
],
183212
"scm/title": [
213+
{
214+
"command": "svn.commitWithMessage",
215+
"group": "navigation",
216+
"when": "config.svn.enabled && scmProvider == svn"
217+
},
184218
{
185219
"command": "svn.refresh",
186220
"group": "navigation",
187-
"when": "scmProvider == svn"
221+
"when": "config.svn.enabled && scmProvider == svn"
188222
},
189223
{
190224
"command": "svn.switchBranch",

src/commands.ts

Lines changed: 132 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -269,106 +269,163 @@ export class SvnCommands {
269269
}
270270

271271
@command("svn.addChangelist")
272-
async addChangelist(resource: Resource) {
273-
const repository = this.model.getRepository(resource.resourceUri.fsPath);
272+
async addChangelist(
273+
...resourceStates: SourceControlResourceState[]
274+
): Promise<void> {
275+
if (
276+
resourceStates.length === 0 ||
277+
!(resourceStates[0].resourceUri instanceof Uri)
278+
) {
279+
const resource = this.getSCMResource();
274280

275-
if (!repository) {
276-
return;
281+
if (!resource) {
282+
return;
283+
}
284+
285+
resourceStates = [resource];
277286
}
278287

279-
const picks: QuickPickItem[] = [];
288+
const selection = resourceStates.filter(
289+
s => s instanceof Resource
290+
) as Resource[];
280291

281-
repository.changelists.forEach((group, changelist) => {
282-
if (group.resourceStates.length) {
283-
picks.push(new ChangeListItem(group));
292+
const uris = selection.map(resource => resource.resourceUri);
293+
294+
await this.runByRepository(uris, async (repository, resources) => {
295+
if (!repository) {
296+
return;
284297
}
285-
});
286-
picks.push(new NewChangeListItem());
287298

288-
const selectedChoice: any = await window.showQuickPick(picks, {});
289-
if (!selectedChoice) {
290-
return;
291-
}
299+
const picks: QuickPickItem[] = [];
292300

293-
let changelistName = "";
301+
repository.changelists.forEach((group, changelist) => {
302+
if (group.resourceStates.length) {
303+
picks.push(new ChangeListItem(group));
304+
}
305+
});
306+
picks.push(new NewChangeListItem());
294307

295-
if (selectedChoice instanceof NewChangeListItem) {
296-
const newChangelistName = await window.showInputBox();
297-
if (!newChangelistName) {
308+
const selectedChoice: any = await window.showQuickPick(picks, {});
309+
if (!selectedChoice) {
298310
return;
299311
}
300-
changelistName = newChangelistName;
301-
} else if (selectedChoice instanceof ChangeListItem) {
302-
changelistName = selectedChoice.resourceGroup.id.replace(
303-
/^changelist-/,
304-
""
305-
);
306-
} else {
307-
return;
308-
}
309312

310-
try {
311-
await repository.addChangelist(
312-
resource.resourceUri.fsPath,
313-
changelistName
314-
);
315-
} catch (error) {
316-
console.log(error);
317-
window.showErrorMessage(
318-
`Unable to add file "${
319-
resource.resourceUri.fsPath
320-
}" to changelist "${changelistName}"`
321-
);
322-
}
313+
let changelistName = "";
314+
315+
if (selectedChoice instanceof NewChangeListItem) {
316+
const newChangelistName = await window.showInputBox();
317+
if (!newChangelistName) {
318+
return;
319+
}
320+
changelistName = newChangelistName;
321+
} else if (selectedChoice instanceof ChangeListItem) {
322+
changelistName = selectedChoice.resourceGroup.id.replace(
323+
/^changelist-/,
324+
""
325+
);
326+
} else {
327+
return;
328+
}
329+
330+
const paths = resources.map(resource => resource.fsPath);
331+
332+
try {
333+
await repository.addChangelist(paths, changelistName);
334+
} catch (error) {
335+
console.log(error);
336+
window.showErrorMessage(
337+
`Unable to add file
338+
"${paths.join(",")}" to changelist "${changelistName}"`
339+
);
340+
}
341+
});
323342
}
324343

325344
@command("svn.removeChangelist")
326-
async removeChangelist(resource: Resource) {
327-
const repository = this.model.getRepository(resource.resourceUri.fsPath);
345+
async removeChangelist(
346+
...resourceStates: SourceControlResourceState[]
347+
): Promise<void> {
348+
if (
349+
resourceStates.length === 0 ||
350+
!(resourceStates[0].resourceUri instanceof Uri)
351+
) {
352+
const resource = this.getSCMResource();
328353

329-
if (!repository) {
330-
return;
331-
}
354+
if (!resource) {
355+
return;
356+
}
332357

333-
try {
334-
await repository.removeChangelist(resource.resourceUri.fsPath);
335-
} catch (error) {
336-
console.log(error);
337-
window.showErrorMessage(
338-
`Unable to remove file "${resource.resourceUri.fsPath}" from changelist`
339-
);
358+
resourceStates = [resource];
340359
}
341-
}
342360

343-
@command("svn.commit", { repository: true })
344-
async commit(
345-
repository: Repository,
346-
...resourceStates: Resource[]
347-
): Promise<void> {
348-
try {
349-
const paths = resourceStates.map(state => {
350-
return state.resourceUri.fsPath;
351-
});
361+
const selection = resourceStates.filter(
362+
s => s instanceof Resource
363+
) as Resource[];
352364

353-
// If files is renamed, the commit need previous file
354-
resourceStates.forEach(state => {
355-
if (state.type === Status.ADDED && state.renameResourceUri) {
356-
paths.push(state.renameResourceUri.fsPath);
357-
}
358-
});
365+
const uris = selection.map(resource => resource.resourceUri);
359366

360-
const message = await inputCommitMessage();
367+
await this.runByRepository(uris, async (repository, resources) => {
368+
if (!repository) {
369+
return;
370+
}
371+
372+
const paths = resources.map(resource => resource.fsPath);
361373

362-
if (message === undefined) {
374+
try {
375+
await repository.removeChangelist(paths);
376+
} catch (error) {
377+
console.log(error);
378+
window.showErrorMessage(
379+
`Unable to remove file "${paths.join(",")}" from changelist`
380+
);
381+
}
382+
});
383+
}
384+
385+
@command("svn.commit")
386+
async commit(...resources: SourceControlResourceState[]): Promise<void> {
387+
if (resources.length === 0 || !(resources[0].resourceUri instanceof Uri)) {
388+
const resource = this.getSCMResource();
389+
390+
if (!resource) {
363391
return;
364392
}
365393

366-
const result = await repository.commitFiles(message, paths);
367-
window.showInformationMessage(result);
368-
} catch (error) {
369-
console.error(error);
370-
window.showErrorMessage("Unable to commit");
394+
resources = [resource];
371395
}
396+
397+
const selection = resources.filter(
398+
s => s instanceof Resource
399+
) as Resource[];
400+
401+
const uris = selection.map(resource => resource.resourceUri);
402+
selection.forEach(resource => {
403+
if (resource.type === Status.ADDED && resource.renameResourceUri) {
404+
uris.push(resource.renameResourceUri);
405+
}
406+
});
407+
408+
await this.runByRepository(uris, async (repository, resources) => {
409+
if (!repository) {
410+
return;
411+
}
412+
413+
const paths = resources.map(resource => resource.fsPath);
414+
415+
try {
416+
const message = await inputCommitMessage();
417+
418+
if (message === undefined) {
419+
return;
420+
}
421+
422+
const result = await repository.commitFiles(message, paths);
423+
window.showInformationMessage(result);
424+
} catch (error) {
425+
console.error(error);
426+
window.showErrorMessage("Unable to commit");
427+
}
428+
});
372429
}
373430

374431
@command("svn.refresh", { repository: true })

src/repository.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -512,13 +512,13 @@ export class Repository {
512512
);
513513
}
514514

515-
async addChangelist(filePath: string, changelist: string) {
515+
async addChangelist(filePaths: string | string[], changelist: string) {
516516
return await this.run(Operation.AddChangelist, () =>
517-
this.repository.addChangelist(filePath, changelist)
517+
this.repository.addChangelist(filePaths, changelist)
518518
);
519519
}
520520

521-
async removeChangelist(changelist: string) {
521+
async removeChangelist(changelist: string | string[]) {
522522
return await this.run(Operation.RemoveChangelist, () =>
523523
this.repository.removeChangelist(changelist)
524524
);

src/svn.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,23 @@ export class Svn {
257257
return this.exec("", ["add", path]);
258258
}
259259

260-
addChangelist(path: string, changelist: string) {
261-
path = path.replace(/\\/g, "/");
262-
return this.exec("", ["changelist", changelist, path]);
260+
addChangelist(filePaths: string | string[], changelist: string) {
261+
if (!Array.isArray(filePaths)) {
262+
filePaths = [filePaths];
263+
}
264+
265+
filePaths = filePaths.map(path => path.replace(/\\/g, "/"));
266+
267+
return this.exec("", ["changelist", changelist, ...filePaths]);
263268
}
264269

265-
removeChangelist(path: string) {
266-
path = path.replace(/\\/g, "/");
267-
return this.exec("", ["changelist", path, "--remove"]);
270+
removeChangelist(filePaths: string | string[]) {
271+
if (!Array.isArray(filePaths)) {
272+
filePaths = [filePaths];
273+
}
274+
275+
filePaths = filePaths.map(path => path.replace(/\\/g, "/"));
276+
return this.exec("", ["changelist", ...filePaths, "--remove"]);
268277
}
269278

270279
show(path: string, revision?: string, options: CpOptions = {}) {

src/svnRepository.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ export class Repository {
7171
return this.svn.add(filePath);
7272
}
7373

74-
addChangelist(filePath: string, changelist: string) {
75-
return this.svn.addChangelist(filePath, changelist);
74+
addChangelist(filePaths: string | string[], changelist: string) {
75+
return this.svn.addChangelist(filePaths, changelist);
7676
}
7777

78-
removeChangelist(filePath: string) {
79-
return this.svn.removeChangelist(filePath);
78+
removeChangelist(filePaths: string | string[]) {
79+
return this.svn.removeChangelist(filePaths);
8080
}
8181

8282
async getCurrentBranch(): Promise<string> {

0 commit comments

Comments
 (0)