From def4a94b7468b9809791190e52c89ae98d5094b7 Mon Sep 17 00:00:00 2001 From: Edgard Messias Date: Fri, 14 Feb 2020 16:51:11 -0300 Subject: [PATCH 1/6] feat: Allow select files to commit when choose "changes" (close #472) --- src/changelistItems.ts | 24 ++++++++++++++++++++++++ src/commands/commitWithMessage.ts | 10 +++++----- src/quickPickItems/changeListItem.ts | 11 ++++++++--- src/quickPickItems/fileItem.ts | 22 ++++++++++++++++++++++ 4 files changed, 59 insertions(+), 8 deletions(-) create mode 100644 src/quickPickItems/fileItem.ts diff --git a/src/changelistItems.ts b/src/changelistItems.ts index 6c09cb42..4cef9131 100644 --- a/src/changelistItems.ts +++ b/src/changelistItems.ts @@ -5,6 +5,7 @@ import IgnoredChangeListItem from "./quickPickItems/ignoredChangeListItem"; import NewChangeListItem from "./quickPickItems/newChangeListItem"; import RemoveChangeListItem from "./quickPickItems/removeChangeListItem"; import { Repository } from "./repository"; +import { FileItem } from "./quickPickItems/fileItem"; export function getChangelistPickOptions( repository: Repository, @@ -116,6 +117,29 @@ export async function inputCommitChangelist(repository: Repository) { return choice; } +export async function inputCommitFiles(repository: Repository) { + const choice = await inputCommitChangelist(repository); + if (!choice) { + return; + } + + if (choice.id === "changes") { + const picks = choice.resourceGroup.resourceStates.map(r => new FileItem(repository, r)); + const selected = await window.showQuickPick(picks, { + placeHolder: "Select files to commit", + canPickMany: true + }); + + if (selected) { + return selected.map(s => s.state); + } + + return; + } + + return choice.resourceGroup.resourceStates; +} + export function patchChangelistOptions(repository: Repository) { const picks: QuickPickItem[] = []; diff --git a/src/commands/commitWithMessage.ts b/src/commands/commitWithMessage.ts index d1d5be2a..5c2d4390 100644 --- a/src/commands/commitWithMessage.ts +++ b/src/commands/commitWithMessage.ts @@ -1,6 +1,6 @@ import * as path from "path"; import { window } from "vscode"; -import { inputCommitChangelist } from "../changelistItems"; +import { inputCommitFiles } from "../changelistItems"; import { Status } from "../common/types"; import { inputCommitMessage } from "../messages"; import { Repository } from "../repository"; @@ -13,12 +13,12 @@ export class CommitWithMessage extends Command { } public async execute(repository: Repository) { - const choice = await inputCommitChangelist(repository); - if (!choice) { + const resourceStates = await inputCommitFiles(repository); + if (!resourceStates || resourceStates.length === 0) { return; } - const filePaths = choice.resourceGroup.resourceStates.map(state => { + const filePaths = resourceStates.map(state => { return state.resourceUri.fsPath; }); @@ -32,7 +32,7 @@ export class CommitWithMessage extends Command { } // If files is renamed, the commit need previous file - choice.resourceGroup.resourceStates.forEach(state => { + resourceStates.forEach(state => { if (state instanceof Resource) { if (state.type === Status.ADDED && state.renameResourceUri) { filePaths.push(state.renameResourceUri.fsPath); diff --git a/src/quickPickItems/changeListItem.ts b/src/quickPickItems/changeListItem.ts index 6584e9d3..437b93cb 100644 --- a/src/quickPickItems/changeListItem.ts +++ b/src/quickPickItems/changeListItem.ts @@ -1,16 +1,21 @@ -import { QuickPickItem, SourceControlResourceGroup } from "vscode"; +import { QuickPickItem } from "vscode"; +import { ISvnResourceGroup } from "../common/types"; export default class ChangeListItem implements QuickPickItem { - constructor(protected group: SourceControlResourceGroup) {} + constructor(protected group: ISvnResourceGroup) {} get label(): string { return this.group.id.replace(/^changelist-/, ""); } + get id(): string { + return this.group.id; + } + get description(): string { return this.group.label; } - get resourceGroup(): SourceControlResourceGroup { + get resourceGroup(): ISvnResourceGroup { return this.group; } } diff --git a/src/quickPickItems/fileItem.ts b/src/quickPickItems/fileItem.ts new file mode 100644 index 00000000..0ae221f3 --- /dev/null +++ b/src/quickPickItems/fileItem.ts @@ -0,0 +1,22 @@ +import { QuickPickItem } from "vscode"; +import { Repository } from "../repository"; +import { Resource } from "../resource"; + +export class FileItem implements QuickPickItem { + constructor( + protected _repository: Repository, + protected _state: Resource, + public picked = false + ) { } + + get label(): string { + return this._repository.repository.removeAbsolutePath(this._state.resourceUri.fsPath); + } + + get description(): string { + return this._state.resourceUri.fsPath; + } + get state(): Resource { + return this._state; + } +} From c5765b83eb7c9659d12c91b3877b81a31b15618f Mon Sep 17 00:00:00 2001 From: Edgard Messias Date: Mon, 17 Feb 2020 07:58:52 -0300 Subject: [PATCH 2/6] chore: Fixed tests --- src/changelistItems.ts | 2 +- src/test/commands.test.ts | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/changelistItems.ts b/src/changelistItems.ts index 4cef9131..0e64695b 100644 --- a/src/changelistItems.ts +++ b/src/changelistItems.ts @@ -123,7 +123,7 @@ export async function inputCommitFiles(repository: Repository) { return; } - if (choice.id === "changes") { + if (choice.id === "changes" && choice.resourceGroup.resourceStates.length > 1) { const picks = choice.resourceGroup.resourceStates.map(r => new FileItem(repository, r)); const selected = await window.showQuickPick(picks, { placeHolder: "Select files to commit", diff --git a/src/test/commands.test.ts b/src/test/commands.test.ts index 98d4ff8c..11d241b9 100644 --- a/src/test/commands.test.ts +++ b/src/test/commands.test.ts @@ -61,7 +61,7 @@ suite("Commands Tests", () => { assert.equal(repository.changes.resourceStates.length, 1); }); - test("Commit File", async function() { + test("Commit Single File", async function() { const repository = sourceControlManager.getRepository( checkoutDir ) as Repository; @@ -165,12 +165,28 @@ suite("Commands Tests", () => { assert.equal(repository.changes.resourceStates.length, 0); }); - test("Commit File", async function() { + test("Commit Multiple", async function() { + const file1 = path.join(checkoutDir.fsPath, "file1.txt"); + fs.writeFileSync(file1, "test"); + await commands.executeCommand("svn.openFile", Uri.file(file1)); + + const file2 = path.join(checkoutDir.fsPath, "file2.txt"); + fs.writeFileSync(file2, "test"); + await commands.executeCommand("svn.openFile", Uri.file(file2)); + const repository = sourceControlManager.getRepository( checkoutDir ) as Repository; - repository.inputBox.value = "First Commit"; + repository.inputBox.value = "Multiple Files Commit"; + + await commands.executeCommand("svn.refresh"); + await commands.executeCommand("svn.add", repository.unversioned.resourceStates[0]); + await commands.executeCommand("svn.refresh"); + await commands.executeCommand("svn.add", repository.unversioned.resourceStates[0]); + await commands.executeCommand("svn.refresh"); + testUtil.overrideNextShowQuickPick(0); + await commands.executeCommand("svn.commitWithMessage"); }); From 415a422786e290d33fcef0fe6f7275f5f09eca1c Mon Sep 17 00:00:00 2001 From: Edgard Messias Date: Mon, 17 Feb 2020 08:03:49 -0300 Subject: [PATCH 3/6] chore: Fixed styles --- src/changelistItems.ts | 9 +++++++-- src/quickPickItems/fileItem.ts | 6 ++++-- src/test/commands.test.ts | 12 +++++++++--- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/changelistItems.ts b/src/changelistItems.ts index 0e64695b..374251ff 100644 --- a/src/changelistItems.ts +++ b/src/changelistItems.ts @@ -123,8 +123,13 @@ export async function inputCommitFiles(repository: Repository) { return; } - if (choice.id === "changes" && choice.resourceGroup.resourceStates.length > 1) { - const picks = choice.resourceGroup.resourceStates.map(r => new FileItem(repository, r)); + if ( + choice.id === "changes" && + choice.resourceGroup.resourceStates.length > 1 + ) { + const picks = choice.resourceGroup.resourceStates.map( + r => new FileItem(repository, r) + ); const selected = await window.showQuickPick(picks, { placeHolder: "Select files to commit", canPickMany: true diff --git a/src/quickPickItems/fileItem.ts b/src/quickPickItems/fileItem.ts index 0ae221f3..8ab2b71a 100644 --- a/src/quickPickItems/fileItem.ts +++ b/src/quickPickItems/fileItem.ts @@ -7,10 +7,12 @@ export class FileItem implements QuickPickItem { protected _repository: Repository, protected _state: Resource, public picked = false - ) { } + ) {} get label(): string { - return this._repository.repository.removeAbsolutePath(this._state.resourceUri.fsPath); + return this._repository.repository.removeAbsolutePath( + this._state.resourceUri.fsPath + ); } get description(): string { diff --git a/src/test/commands.test.ts b/src/test/commands.test.ts index 11d241b9..caecc305 100644 --- a/src/test/commands.test.ts +++ b/src/test/commands.test.ts @@ -180,13 +180,19 @@ suite("Commands Tests", () => { repository.inputBox.value = "Multiple Files Commit"; await commands.executeCommand("svn.refresh"); - await commands.executeCommand("svn.add", repository.unversioned.resourceStates[0]); + await commands.executeCommand( + "svn.add", + repository.unversioned.resourceStates[0] + ); await commands.executeCommand("svn.refresh"); - await commands.executeCommand("svn.add", repository.unversioned.resourceStates[0]); + await commands.executeCommand( + "svn.add", + repository.unversioned.resourceStates[0] + ); await commands.executeCommand("svn.refresh"); testUtil.overrideNextShowQuickPick(0); - + await commands.executeCommand("svn.commitWithMessage"); }); From 8a6cc08e8bbb7bbfcf75b3486144881f9608216a Mon Sep 17 00:00:00 2001 From: Edgard Messias Date: Wed, 19 Feb 2020 08:17:37 -0300 Subject: [PATCH 4/6] chore: Added option to set default selection of files on commit --- README.md | 3 +++ package.json | 5 +++++ src/changelistItems.ts | 5 ++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index dc77a47c..173a9130 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,9 @@ Here are all of the extension settings with their default values. To change any // Whether auto refreshing is enabled "svn.autorefresh": true, + // Select all files when commit changes + "svn.commit.changes.selectedAll": true, + // Set file to status resolved after fix conflicts "svn.conflicts.autoResolve": null, diff --git a/package.json b/package.json index 0cff1b69..71b7a6d6 100644 --- a/package.json +++ b/package.json @@ -1008,6 +1008,11 @@ "description": "Whether auto refreshing is enabled", "default": true }, + "svn.commit.changes.selectedAll": { + "type": "boolean", + "description": "Select all files when commit changes", + "default": true + }, "svn.conflicts.autoResolve": { "type": "boolean", "description": "Set file to status resolved after fix conflicts", diff --git a/src/changelistItems.ts b/src/changelistItems.ts index 374251ff..d7a3e2da 100644 --- a/src/changelistItems.ts +++ b/src/changelistItems.ts @@ -127,8 +127,11 @@ export async function inputCommitFiles(repository: Repository) { choice.id === "changes" && choice.resourceGroup.resourceStates.length > 1 ) { + + const selectedAll = configuration.get("commit.changes.selectedAll", true); + const picks = choice.resourceGroup.resourceStates.map( - r => new FileItem(repository, r) + r => new FileItem(repository, r, selectedAll) ); const selected = await window.showQuickPick(picks, { placeHolder: "Select files to commit", From 8fd909ef3808f20ca72402ae46509eef9b56cd63 Mon Sep 17 00:00:00 2001 From: Edgard Messias Date: Wed, 19 Feb 2020 08:19:52 -0300 Subject: [PATCH 5/6] chore: Fixed lint --- src/changelistItems.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/changelistItems.ts b/src/changelistItems.ts index d7a3e2da..d158b928 100644 --- a/src/changelistItems.ts +++ b/src/changelistItems.ts @@ -127,7 +127,6 @@ export async function inputCommitFiles(repository: Repository) { choice.id === "changes" && choice.resourceGroup.resourceStates.length > 1 ) { - const selectedAll = configuration.get("commit.changes.selectedAll", true); const picks = choice.resourceGroup.resourceStates.map( From c2a2f51f8ef2eb84ca241bbbae30fcf3bf49f39d Mon Sep 17 00:00:00 2001 From: Edgard Messias Date: Wed, 19 Feb 2020 08:25:27 -0300 Subject: [PATCH 6/6] chore: Fixed test warning --- src/changelistItems.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/changelistItems.ts b/src/changelistItems.ts index d158b928..428a0c6d 100644 --- a/src/changelistItems.ts +++ b/src/changelistItems.ts @@ -137,7 +137,7 @@ export async function inputCommitFiles(repository: Repository) { canPickMany: true }); - if (selected) { + if (selected !== undefined && selected.length > 0) { return selected.map(s => s.state); }