From d6a3d5800019c16df842420be9a1ede6fc857dd6 Mon Sep 17 00:00:00 2001 From: chris Date: Mon, 2 Apr 2018 12:15:57 +0100 Subject: [PATCH 1/3] added option to ignore unversioned files --- package-lock.json | 2 +- package.json | 177 ++++++++++++++++++++++--------------------- src/commands.ts | 51 ++++++++++--- src/propertyItems.ts | 16 ++++ src/repository.ts | 9 ++- src/svnRepository.ts | 29 ++++++- 6 files changed, 184 insertions(+), 100 deletions(-) create mode 100644 src/propertyItems.ts diff --git a/package-lock.json b/package-lock.json index 95b2003f..812afba9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "svn-scm", - "version": "1.26.0", + "version": "1.26.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index ce502fce..bf76cced 100644 --- a/package.json +++ b/package.json @@ -17,18 +17,9 @@ "bugs": { "url": "https://github.com/JohnstonCode/svn-scm/issues" }, - "categories": [ - "Other", - "SCM Providers" - ], - "keywords": [ - "multi-root ready", - "scm", - "svn" - ], - "activationEvents": [ - "*" - ], + "categories": ["Other", "SCM Providers"], + "keywords": ["multi-root ready", "scm", "svn"], + "activationEvents": ["*"], "main": "./out/extension", "scripts": { "vscode:prepublish": "tsc -p ./", @@ -216,6 +207,11 @@ "command": "svn.patchChangeList", "title": "Show patch from changelist", "category": "SVN" + }, + { + "command": "svn.ignore", + "title": "Ignore", + "category": "SVN" } ], "menus": { @@ -238,11 +234,13 @@ }, { "command": "svn.openChangeBase", - "when": "config.svn.enabled && svnOpenRepositoryCount != 0 && svnActiveEditorHasChanges" + "when": + "config.svn.enabled && svnOpenRepositoryCount != 0 && svnActiveEditorHasChanges" }, { "command": "svn.openChangeHead", - "when": "config.svn.enabled && svnOpenRepositoryCount != 0 && svnActiveEditorHasChanges" + "when": + "config.svn.enabled && svnOpenRepositoryCount != 0 && svnActiveEditorHasChanges" }, { "command": "svn.openFile", @@ -298,7 +296,8 @@ }, { "command": "svn.revertSelectedRanges", - "when": "config.svn.enabled && svnOpenRepositoryCount != 0 && svnHasSupportToRegisterDiffCommand == 1" + "when": + "config.svn.enabled && svnOpenRepositoryCount != 0 && svnHasSupportToRegisterDiffCommand == 1" }, { "command": "svn.close", @@ -307,6 +306,10 @@ { "command": "svn.cleanup", "when": "config.svn.enabled && svnOpenRepositoryCount != 0" + }, + { + "command": "svn.ignore", + "when": "false" } ], "scm/title": [ @@ -360,73 +363,93 @@ "scm/resourceState/context": [ { "command": "svn.add", - "when": "config.svn.enabled && scmProvider == svn && scmResourceGroup == unversioned", + "when": + "config.svn.enabled && scmProvider == svn && scmResourceGroup == unversioned", "group": "inline" }, { "command": "svn.add", - "when": "config.svn.enabled && scmProvider == svn && scmResourceGroup == unversioned", + "when": + "config.svn.enabled && scmProvider == svn && scmResourceGroup == unversioned", "group": "1_modification" }, { "command": "svn.openFile", - "when": "config.svn.enabled && scmProvider == svn && scmResourceGroup != external", + "when": + "config.svn.enabled && scmProvider == svn && scmResourceGroup != external", "group": "navigation" }, { "command": "svn.openHEADFile", - "when": "config.svn.enabled && scmProvider == svn && scmResourceGroup != unversioned && scmResourceGroup != external", + "when": + "config.svn.enabled && scmProvider == svn && scmResourceGroup != unversioned && scmResourceGroup != external", "group": "navigation" }, { "command": "svn.openChangeBase", - "when": "config.svn.enabled && scmProvider == svn && scmResourceGroup != unversioned && scmResourceGroup != external", + "when": + "config.svn.enabled && scmProvider == svn && scmResourceGroup != unversioned && scmResourceGroup != external", "group": "navigation" }, { "command": "svn.openChangeHead", - "when": "config.svn.enabled && scmProvider == svn && scmResourceGroup != unversioned && scmResourceGroup != external", + "when": + "config.svn.enabled && scmProvider == svn && scmResourceGroup != unversioned && scmResourceGroup != external", "group": "navigation" }, { "command": "svn.patch", - "when": "config.svn.enabled && scmProvider == svn && scmResourceGroup != unversioned && scmResourceGroup != external && scmResourceGroup != conflicts", + "when": + "config.svn.enabled && scmProvider == svn && scmResourceGroup != unversioned && scmResourceGroup != external && scmResourceGroup != conflicts", "group": "navigation" }, { "command": "svn.resolve", - "when": "config.svn.enabled && scmProvider == svn && scmResourceGroup == conflicts", + "when": + "config.svn.enabled && scmProvider == svn && scmResourceGroup == conflicts", "group": "inline" }, { "command": "svn.resolve", - "when": "config.svn.enabled && scmProvider == svn && scmResourceGroup == conflicts", + "when": + "config.svn.enabled && scmProvider == svn && scmResourceGroup == conflicts", "group": "1_modification" }, { "command": "svn.changelist", - "when": "config.svn.enabled && scmProvider == svn && scmResourceGroup != unversioned && scmResourceGroup != external && scmResourceGroup != conflicts", + "when": + "config.svn.enabled && scmProvider == svn && scmResourceGroup != unversioned && scmResourceGroup != external && scmResourceGroup != conflicts", "group": "inline" }, { "command": "svn.changelist", - "when": "config.svn.enabled && scmProvider == svn && scmResourceGroup != unversioned && scmResourceGroup != external && scmResourceGroup != conflicts", + "when": + "config.svn.enabled && scmProvider == svn && scmResourceGroup != unversioned && scmResourceGroup != external && scmResourceGroup != conflicts", "group": "1_modification" }, { "command": "svn.commit", - "when": "config.svn.enabled && scmProvider == svn && scmResourceGroup != unversioned && scmResourceGroup != external && scmResourceGroup != conflicts", + "when": + "config.svn.enabled && scmProvider == svn && scmResourceGroup != unversioned && scmResourceGroup != external && scmResourceGroup != conflicts", "group": "1_modification" }, { "command": "svn.revert", - "when": "config.svn.enabled && scmProvider == svn && scmResourceGroup != unversioned && scmResourceGroup != external && scmResourceGroup != conflicts", + "when": + "config.svn.enabled && scmProvider == svn && scmResourceGroup != unversioned && scmResourceGroup != external && scmResourceGroup != conflicts", "group": "2_modification" }, { "command": "svn.remove", - "when": "config.svn.enabled && scmProvider == svn && scmResourceGroup != unversioned && scmResourceGroup != external && scmResourceGroup != conflicts", + "when": + "config.svn.enabled && scmProvider == svn && scmResourceGroup != unversioned && scmResourceGroup != external && scmResourceGroup != conflicts", "group": "2_modification" + }, + { + "command": "svn.ignore", + "when": + "config.svn.enabled && scmProvider == svn && scmResourceGroup == unversioned", + "group": "1_modification" } ], "scm/change/title": [ @@ -439,22 +462,26 @@ { "command": "svn.openFile", "group": "navigation", - "when": "config.svn.enabled && svnOpenRepositoryCount != 0 && isInDiffEditor && resourceScheme != extension && resourceScheme != merge-conflicts.conflicts-diff" + "when": + "config.svn.enabled && svnOpenRepositoryCount != 0 && isInDiffEditor && resourceScheme != extension && resourceScheme != merge-conflicts.conflicts-diff" }, { "command": "svn.openChangeBase", "group": "navigation", - "when": "config.svn.enabled && svnOpenRepositoryCount != 0 && svnActiveEditorHasChanges && !isInDiffEditor && resourceScheme == file" + "when": + "config.svn.enabled && svnOpenRepositoryCount != 0 && svnActiveEditorHasChanges && !isInDiffEditor && resourceScheme == file" }, { "command": "svn.openChangeHead", "group": "navigation", - "when": "config.svn.enabled && svnOpenRepositoryCount != 0 && svnActiveEditorHasChanges && !isInDiffEditor && resourceScheme == file" + "when": + "config.svn.enabled && svnOpenRepositoryCount != 0 && svnActiveEditorHasChanges && !isInDiffEditor && resourceScheme == file" }, { "command": "svn.revertSelectedRanges", "group": "2_svn@3", - "when": "config.svn.enabled && svnOpenRepositoryCount != 0 && isInDiffEditor && resourceScheme != merge-conflicts.conflicts-diff && && svnHasSupportToRegisterDiffCommand == 1" + "when": + "config.svn.enabled && svnOpenRepositoryCount != 0 && isInDiffEditor && resourceScheme != merge-conflicts.conflicts-diff && && svnHasSupportToRegisterDiffCommand == 1" } ] }, @@ -473,14 +500,12 @@ }, "svn.decorations.enabled": { "type": "boolean", - "description": "Controls if SVN contributes colors and badges to the explorer and the open (VSCode >= 1.18 with proposed-api)", + "description": + "Controls if SVN contributes colors and badges to the explorer and the open (VSCode >= 1.18 with proposed-api)", "default": true }, "svn.path": { - "type": [ - "string", - "null" - ], + "type": ["string", "null"], "description": "Path to the svn executable", "default": null, "isExecutable": true @@ -492,59 +517,47 @@ }, "svn.diff.withHead": { "type": "boolean", - "description": "Show diff changes using latest revision in the repository. Set false to use latest revision in local folder", + "description": + "Show diff changes using latest revision in the repository. Set false to use latest revision in local folder", "default": true }, "svn.layout.trunkRegex": { - "type": [ - "string", - "null" - ], - "description": "Regex to detect path for 'trunk' in SVN URL, 'null' to disable. (Ex.: '(trunk)', '(main)')", + "type": ["string", "null"], + "description": + "Regex to detect path for 'trunk' in SVN URL, 'null' to disable. (Ex.: '(trunk)', '(main)')", "default": "(trunk)(/.*)?" }, "svn.layout.trunkRegexName": { - "type": [ - "number" - ], + "type": ["number"], "description": "Regex group position for name of trunk", "default": 1 }, "svn.layout.branchesRegex": { - "type": [ - "string", - "null" - ], - "description": "Regex to detect path for 'branches' in SVN URL, 'null' to disable. Subpath use 'branches/[^/]+/([^/]+)(/.*)?' (Ex.: 'branches/...', 'versions/...')", + "type": ["string", "null"], + "description": + "Regex to detect path for 'branches' in SVN URL, 'null' to disable. Subpath use 'branches/[^/]+/([^/]+)(/.*)?' (Ex.: 'branches/...', 'versions/...')", "default": "branches/([^/]+)(/.*)?" }, "svn.layout.branchesRegexName": { - "type": [ - "number" - ], + "type": ["number"], "description": "Regex group position for name of branch", "default": 1 }, "svn.layout.tagsRegex": { - "type": [ - "string", - "null" - ], - "description": "Regex to detect path for 'tags' in SVN URL, 'null' to disable. Subpath use 'tags/[^/]+/([^/]+)(/.*)?'. (Ex.: 'tags/...', 'stamps/...')", + "type": ["string", "null"], + "description": + "Regex to detect path for 'tags' in SVN URL, 'null' to disable. Subpath use 'tags/[^/]+/([^/]+)(/.*)?'. (Ex.: 'tags/...', 'stamps/...')", "default": "tags/([^/]+)(/.*)?" }, "svn.layout.tagRegexName": { - "type": [ - "number" - ], + "type": ["number"], "description": "Regex group position for name of tag", "default": 1 }, "svn.layout.showFullName": { - "type": [ - "boolean" - ], - "description": "Set true to show 'branches/' and false to show only ''", + "type": ["boolean"], + "description": + "Set true to show 'branches/' and false to show only ''", "default": true }, "svn.multipleFolders.enabled": { @@ -561,29 +574,24 @@ "svn.multipleFolders.ignore": { "type": "array", "description": "Folders to ignore using SVN", - "default": [ - "**/.git", - "**/.hg", - "**/vendor", - "**/node_modules" - ] + "default": ["**/.git", "**/.hg", "**/vendor", "**/node_modules"] }, "svn.sourceControl.ignoreOnCommit": { "type": "array", "description": "Changelists to ignore on commit", - "default": [ - "ignore-on-commit" - ] + "default": ["ignore-on-commit"] }, "svn.detectExternals": { "type": "boolean", "default": true, - "description": "Controls whether to automatically detect svn externals." + "description": + "Controls whether to automatically detect svn externals." }, "svn.sourceControl.combineExternalIfSameServer": { "type": "boolean", "default": false, - "description": "Combine the svn external in the main if is from the same server." + "description": + "Combine the svn external in the main if is from the same server." }, "svn.sourceControl.countUnversioned": { "type": "boolean", @@ -608,15 +616,14 @@ }, "svn.update.ignoreExternals": { "type": "boolean", - "description": "Set to ignore externals definitions on update (add --ignore-externals)", + "description": + "Set to ignore externals definitions on update (add --ignore-externals)", "default": true }, "svn.default.encoding": { - "type": [ - "string", - "null" - ], - "description": "Encoding of svn output if the output is not utf-8. When this parameter is null, the encoding is automatically detected. Example: 'windows-1252'.", + "type": ["string", "null"], + "description": + "Encoding of svn output if the output is not utf-8. When this parameter is null, the encoding is automatically detected. Example: 'windows-1252'.", "default": null }, "svn.showUpdateMessage": { @@ -627,4 +634,4 @@ } } } -} \ No newline at end of file +} diff --git a/src/commands.ts b/src/commands.ts index 4444d9c9..7ed3f69f 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -36,6 +36,7 @@ import { } from "./changelistItems"; import { configuration } from "./helpers/configuration"; import { selectBranch } from "./branches"; +import { IgnorePropertyItem } from "./propertyItems"; interface CommandOptions { repository?: boolean; @@ -235,15 +236,13 @@ export class SvnCommands implements IDisposable { repository.changelists.forEach((group, changelist) => { if ( - group.resourceStates.some(state => - { - return resources.some(resource => { - return resource.path === state.resourceUri.path; - }); - } - ) + group.resourceStates.some(state => { + return resources.some(resource => { + return resource.path === state.resourceUri.path; + }); + }) ) { - console.log('canRemove true'); + console.log("canRemove true"); canRemove = true; return false; } @@ -699,7 +698,7 @@ export class SvnCommands implements IDisposable { ); const result = await repository.updateRevision(ignoreExternals); - + if (showUpdateMessage) { window.showInformationMessage(result); } @@ -766,15 +765,15 @@ export class SvnCommands implements IDisposable { await this.showDiffPath(repository, content); }); } - + @command("svn.patchChangeList", { repository: true }) async patchChangeList(repository: Repository): Promise { const changelistName = await getPatchChangelist(repository); - + if (!changelistName) { return; } - + const content = await repository.patchChangelist(changelistName); await this.showDiffPath(repository, content); } @@ -1057,6 +1056,34 @@ export class SvnCommands implements IDisposable { await repository.finishCheckout(); } + @command("svn.ignore") + async propset( + ...resourceStates: SourceControlResourceState[] + ): Promise { + const selection = this.getResourceStates(resourceStates); + + if (selection.length === 0) { + return; + } + + const uris = selection.map(resource => resource.resourceUri); + + await this.runByRepository(uris, async (repository, resources) => { + if (!repository) { + return; + } + + for (const resource of resources) { + try { + await repository.ignore(resource.fsPath); + } catch (error) { + console.log(error); + window.showErrorMessage("Unable to set property"); + } + } + }); + } + private getSCMResource(uri?: Uri): Resource | undefined { uri = uri ? uri diff --git a/src/propertyItems.ts b/src/propertyItems.ts new file mode 100644 index 00000000..d569870c --- /dev/null +++ b/src/propertyItems.ts @@ -0,0 +1,16 @@ +import { QuickPickItem } from "vscode"; +import { Repository } from "./repository"; + +export class IgnorePropertyItem implements QuickPickItem { + get label(): string { + return "Ignore"; + } + + get description(): string { + return "Test"; + } + + async run(repository: Repository, filePath: string) { + return repository.ignore(filePath); + } +} diff --git a/src/repository.ts b/src/repository.ts index 231517e2..76687631 100644 --- a/src/repository.ts +++ b/src/repository.ts @@ -58,7 +58,8 @@ export enum Operation { Show = "Show", Status = "Status", SwitchBranch = "SwitchBranch", - Update = "Update" + Update = "Update", + Ignore = "Ignore" } function isReadOnly(operation: Operation): boolean { @@ -695,6 +696,12 @@ export class Repository { ); } + async ignore(filePath: string) { + return await this.run(Operation.Ignore, () => + this.repository.ignore(filePath) + ); + } + async promptAuth(): Promise { // Prevent multiple prompts for auth if (this.lastPromptAuth) { diff --git a/src/svnRepository.ts b/src/svnRepository.ts index 25f25542..ef415623 100644 --- a/src/svnRepository.ts +++ b/src/svnRepository.ts @@ -329,7 +329,7 @@ export class Repository { const message = result.stdout; return message; } - + async patchChangelist(changelistName: string) { const result = await this.exec(["diff", "--changelist", changelistName]); const message = result.stdout; @@ -404,4 +404,31 @@ export class Repository { return parseSvnList(result.stdout); } + + async ignore(filePath: string) { + const fileName = path.basename(filePath); + const parentDir = path.dirname(filePath); + let currentIgnore = ""; + + try { + const currentIgnoreResult = await this.exec([ + "propget", + "svn:ignore", + parentDir + ]); + + currentIgnore = currentIgnoreResult.stdout.trim(); + } catch (error) {} + + const newIgnore = currentIgnore + "\n" + fileName; + + const result = await this.exec([ + "propset", + "svn:ignore", + newIgnore, + parentDir + ]); + + return result.stdout; + } } From b290c61a096a4d6ff4c9c3b7e6f3a90763bfdd29 Mon Sep 17 00:00:00 2001 From: chris Date: Mon, 2 Apr 2018 12:18:50 +0100 Subject: [PATCH 2/3] Removed unused file --- src/commands.ts | 1 - src/propertyItems.ts | 16 ---------------- 2 files changed, 17 deletions(-) delete mode 100644 src/propertyItems.ts diff --git a/src/commands.ts b/src/commands.ts index 7ed3f69f..5b0285e7 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -36,7 +36,6 @@ import { } from "./changelistItems"; import { configuration } from "./helpers/configuration"; import { selectBranch } from "./branches"; -import { IgnorePropertyItem } from "./propertyItems"; interface CommandOptions { repository?: boolean; diff --git a/src/propertyItems.ts b/src/propertyItems.ts deleted file mode 100644 index d569870c..00000000 --- a/src/propertyItems.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { QuickPickItem } from "vscode"; -import { Repository } from "./repository"; - -export class IgnorePropertyItem implements QuickPickItem { - get label(): string { - return "Ignore"; - } - - get description(): string { - return "Test"; - } - - async run(repository: Repository, filePath: string) { - return repository.ignore(filePath); - } -} From 547d683c0007843d79dceade466bf7290f114ce4 Mon Sep 17 00:00:00 2001 From: chris Date: Mon, 2 Apr 2018 12:47:30 +0100 Subject: [PATCH 3/3] Changed names to addFileToIgnore --- package.json | 6 +++--- src/commands.ts | 6 +++--- src/repository.ts | 4 ++-- src/svnRepository.ts | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index bf76cced..6c9e1498 100644 --- a/package.json +++ b/package.json @@ -209,7 +209,7 @@ "category": "SVN" }, { - "command": "svn.ignore", + "command": "svn.addFileToIgnore", "title": "Ignore", "category": "SVN" } @@ -308,7 +308,7 @@ "when": "config.svn.enabled && svnOpenRepositoryCount != 0" }, { - "command": "svn.ignore", + "command": "svn.addFileToIgnore", "when": "false" } ], @@ -446,7 +446,7 @@ "group": "2_modification" }, { - "command": "svn.ignore", + "command": "svn.addFileToIgnore", "when": "config.svn.enabled && scmProvider == svn && scmResourceGroup == unversioned", "group": "1_modification" diff --git a/src/commands.ts b/src/commands.ts index 5b0285e7..a4eeb7f7 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -1055,8 +1055,8 @@ export class SvnCommands implements IDisposable { await repository.finishCheckout(); } - @command("svn.ignore") - async propset( + @command("svn.addFileToIgnore") + async addFileToIgnore( ...resourceStates: SourceControlResourceState[] ): Promise { const selection = this.getResourceStates(resourceStates); @@ -1074,7 +1074,7 @@ export class SvnCommands implements IDisposable { for (const resource of resources) { try { - await repository.ignore(resource.fsPath); + await repository.addFileToIgnore(resource.fsPath); } catch (error) { console.log(error); window.showErrorMessage("Unable to set property"); diff --git a/src/repository.ts b/src/repository.ts index 76687631..ef33c2c1 100644 --- a/src/repository.ts +++ b/src/repository.ts @@ -696,9 +696,9 @@ export class Repository { ); } - async ignore(filePath: string) { + async addFileToIgnore(filePath: string) { return await this.run(Operation.Ignore, () => - this.repository.ignore(filePath) + this.repository.addFileToIgnore(filePath) ); } diff --git a/src/svnRepository.ts b/src/svnRepository.ts index ef415623..6a302c65 100644 --- a/src/svnRepository.ts +++ b/src/svnRepository.ts @@ -405,7 +405,7 @@ export class Repository { return parseSvnList(result.stdout); } - async ignore(filePath: string) { + async addFileToIgnore(filePath: string) { const fileName = path.basename(filePath); const parentDir = path.dirname(filePath); let currentIgnore = "";