Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add remove unversioned command #769

Merged
merged 7 commits into from
Jan 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"lint:fix": "npm run lint -- --fix",
"lint": "eslint \"src/**/*.ts\"",
"semantic-release": "semantic-release",
"style-check": "npx prettylint src/**/*.ts",
"style-check": "npx prettylint 'src/**/*.ts'",
"test": "node ./out/test/runTest.js",
"tools:genReadme": "node ./out/tools/generateConfigSectionForReadme.js",
"vscode:prepublish": "npm run lint && npm run build",
Expand Down Expand Up @@ -401,6 +401,11 @@
"title": "Clean up working copy",
"category": "SVN"
},
{
"command": "svn.removeUnversioned",
"title": "Remove unversioned files",
"category": "SVN"
},
{
"command": "svn.patchChangeList",
"title": "Show patch from changelist",
Expand Down Expand Up @@ -552,6 +557,10 @@
"command": "svn.cleanup",
"when": "config.svn.enabled && svnOpenRepositoryCount != 0"
},
{
"command": "svn.removeUnversioned",
"when": "config.svn.enabled && svnOpenRepositoryCount != 0 && isSvn19orGreater"
},
{
"command": "svn.addToIgnoreExplorer",
"when": "false"
Expand Down Expand Up @@ -752,6 +761,10 @@
"command": "svn.cleanup",
"when": "config.svn.enabled && scmProvider == svn"
},
{
"command": "svn.removeUnversioned",
"when": "config.svn.enabled && scmProvider == svn && isSvn19orGreater"
},
{
"command": "svn.patchChangeList",
"when": "config.svn.enabled && scmProvider == svn"
Expand Down
7 changes: 6 additions & 1 deletion src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { PullIncommingChange } from "./commands/pullIncomingChange";
import { Refresh } from "./commands/refresh";
import { RefreshRemoteChanges } from "./commands/refreshRemoteChanges";
import { Remove } from "./commands/remove";
import { RemoveUnversioned } from "./commands/removeUnversioned";
import { RenameExplorer } from "./commands/renameExplorer";
import { Resolve } from "./commands/resolve";
import { ResolveAll } from "./commands/resolveAll";
Expand All @@ -43,7 +44,10 @@ import { Update } from "./commands/update";
import { Upgrade } from "./commands/upgrade";
import { SourceControlManager } from "./source_control_manager";

export function registerCommands(sourceControlManager: SourceControlManager, disposables: Disposable[]) {
export function registerCommands(
sourceControlManager: SourceControlManager,
disposables: Disposable[]
) {
disposables.push(new GetSourceControlManager(sourceControlManager));
disposables.push(new FileOpen());
disposables.push(new OpenFile());
Expand Down Expand Up @@ -71,6 +75,7 @@ export function registerCommands(sourceControlManager: SourceControlManager, dis
disposables.push(new RevertChange());
disposables.push(new Close());
disposables.push(new Cleanup());
disposables.push(new RemoveUnversioned());
disposables.push(new FinishCheckout());
disposables.push(new AddToIgnoreSCM());
disposables.push(new AddToIgnoreExplorer());
Expand Down
22 changes: 22 additions & 0 deletions src/commands/removeUnversioned.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Repository } from "../repository";
import { Command } from "./command";
import { window } from "vscode";

export class RemoveUnversioned extends Command {
constructor() {
super("svn.removeUnversioned", { repository: true });
}

public async execute(repository: Repository) {
const answer = await window.showWarningMessage(
"Are you sure? This will remove all unversioned files except for ignored.",
{ modal: true },
"Yes",
"No"
);
if (answer !== "Yes") {
return;
}
await repository.removeUnversioned();
}
}
7 changes: 3 additions & 4 deletions src/contexts/checkActiveEditor.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { commands, Disposable, window } from "vscode";
import { Disposable, window } from "vscode";
import { Status } from "../common/types";
import { debounce } from "../decorators";
import { SourceControlManager } from "../source_control_manager";
import { IDisposable } from "../util";
import { IDisposable, setVscodeContext } from "../util";

export class CheckActiveEditor implements IDisposable {
private disposables: Disposable[] = [];
Expand All @@ -24,8 +24,7 @@ export class CheckActiveEditor implements IDisposable {

@debounce(100)
private checkHasChangesOnActiveEditor() {
commands.executeCommand(
"setContext",
setVscodeContext(
"svnActiveEditorHasChanges",
this.hasChangesOnActiveEditor()
);
Expand Down
14 changes: 14 additions & 0 deletions src/contexts/isSvn19orGreater.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Disposable } from "vscode";
import * as semver from "semver";
import { setVscodeContext } from "../util";

export class IsSvn19orGreater implements Disposable {
constructor(svnVersion: string) {
const is19orGreater = semver.satisfies(svnVersion, ">= 1.9");

setVscodeContext("isSvn19orGreater", is19orGreater);
}

// eslint-disable-next-line @typescript-eslint/no-empty-function
dispose() {}
}
9 changes: 4 additions & 5 deletions src/contexts/openRepositoryCount.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { commands, Disposable } from "vscode";
import { Disposable } from "vscode";
import { debounce } from "../decorators";
import { SourceControlManager } from "../source_control_manager";
import { IDisposable } from "../util";
import { IDisposable, setVscodeContext } from "../util";

export class OpenRepositoryCount implements IDisposable {
private disposables: Disposable[] = [];
Expand All @@ -24,10 +24,9 @@ export class OpenRepositoryCount implements IDisposable {

@debounce(100)
private checkOpened() {
commands.executeCommand(
"setContext",
setVscodeContext(
"svnOpenRepositoryCount",
`${this.sourceControlManager.repositories.length}`
this.sourceControlManager.repositories.length
);
}

Expand Down
6 changes: 1 addition & 5 deletions src/diffParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ export async function parseDiffXml(content: string): Promise<ISvnPath[]> {
tagNameProcessors: [camelcase]
},
(err, result) => {
if (
err ||
!result.paths ||
!result.paths.path
) {
if (err || !result.paths || !result.paths.path) {
reject();
}

Expand Down
7 changes: 6 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { SvnFinder } from "./svnFinder";
import SvnProvider from "./treeView/dataProviders/svnProvider";
import { toDisposable } from "./util";
import { BranchChangesProvider } from "./historyView/branchChangesProvider";
import { IsSvn19orGreater } from "./contexts/isSvn19orGreater";

async function init(
_context: ExtensionContext,
Expand All @@ -33,7 +34,10 @@ async function init(

const info = await svnFinder.findSvn(pathHint);
const svn = new Svn({ svnPath: info.path, version: info.version });
const sourceControlManager = await new SourceControlManager(svn, ConstructorPolicy.Async);
const sourceControlManager = await new SourceControlManager(
svn,
ConstructorPolicy.Async
);
const contentProvider = new SvnContentProvider(sourceControlManager);

registerCommands(sourceControlManager, disposables);
Expand All @@ -58,6 +62,7 @@ async function init(

disposables.push(new CheckActiveEditor(sourceControlManager));
disposables.push(new OpenRepositoryCount(sourceControlManager));
disposables.push(new IsSvn19orGreater(info.version));

outputChannel.appendLine(`Using svn "${info.version}" from "${info.path}"`);

Expand Down
10 changes: 8 additions & 2 deletions src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ async function showCommitInput(message?: string, filePaths?: string[]) {
Use a content security policy to only allow loading images from https or from our extension directory,
and only allow scripts that have a specific nonce.
-->
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src ${panel.webview.cspSource} https:; script-src ${panel.webview.cspSource} 'unsafe-inline'; style-src ${panel.webview.cspSource};">
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src ${
panel.webview.cspSource
} https:; script-src ${panel.webview.cspSource} 'unsafe-inline'; style-src ${
panel.webview.cspSource
};">

<title>Commit Message</title>
<link rel="stylesheet" href="${styleUri}">
Expand Down Expand Up @@ -178,7 +182,9 @@ async function showCommitInput(message?: string, filePaths?: string[]) {
"svn.getSourceControlManager",
""
)) as SourceControlManager;
repository = await sourceControlManager.getRepositoryFromUri(Uri.file(filePaths[0]));
repository = await sourceControlManager.getRepositoryFromUri(
Uri.file(filePaths[0])
);
}

const message = await commands.executeCommand(
Expand Down
11 changes: 10 additions & 1 deletion src/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,10 @@ export class Repository implements IRemoteRepository {
}

if (actionForDeletedFiles === "remove") {
return this.removeFiles(uris.map(uri => uri.fsPath), false);
return this.removeFiles(
uris.map(uri => uri.fsPath),
false
);
} else if (actionForDeletedFiles === "prompt") {
return commands.executeCommand("svn.promptRemove", ...uris);
}
Expand Down Expand Up @@ -862,6 +865,12 @@ export class Repository implements IRemoteRepository {
return this.run(Operation.CleanUp, () => this.repository.cleanup());
}

public async removeUnversioned() {
return this.run(Operation.CleanUp, () =>
this.repository.removeUnversioned()
);
}

public async getInfo(path: string, revision?: string): Promise<ISvnInfo> {
return this.run(Operation.Info, () =>
this.repository.getInfo(path, revision, true)
Expand Down
2 changes: 1 addition & 1 deletion src/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class Resource implements SourceControlResourceState {
faded,
tooltip,
light,
dark,
dark
};
}

Expand Down
4 changes: 3 additions & 1 deletion src/statusParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ function processEntry(
}

const wcStatus: IWcStatus = {
locked: !!entry.wcStatus.wcLocked && entry.wcStatus.wcLocked === "true" || !!(entry.reposStatus && entry.reposStatus.lock),
locked:
(!!entry.wcStatus.wcLocked && entry.wcStatus.wcLocked === "true") ||
!!(entry.reposStatus && entry.reposStatus.lock),
switched: !!entry.wcStatus.switched && entry.wcStatus.switched === "true"
};

Expand Down
2 changes: 1 addition & 1 deletion src/svn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class Svn {
this.svnPath = options.svnPath;
}

private logOutput(output: string): void {
public logOutput(output: string): void {
this._onOutput.emit("log", output);
}

Expand Down
9 changes: 5 additions & 4 deletions src/svnContentProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ export class SvnContentProvider

constructor(private sourceControlManager: SourceControlManager) {
this.disposables.push(
sourceControlManager.onDidChangeRepository(this.onDidChangeRepository, this),
sourceControlManager.onDidChangeRepository(
this.onDidChangeRepository,
this
),
workspace.registerTextDocumentContentProvider("svn", this)
);

Expand Down Expand Up @@ -79,8 +82,7 @@ export class SvnContentProvider

const keys = Object.keys(this.cache);

cacheLoop:
for (const key of keys) {
cacheLoop: for (const key of keys) {
const uri = this.cache[key].uri;
const fsPath = uri.fsPath;

Expand All @@ -91,7 +93,6 @@ export class SvnContentProvider
}
}
}

}

public async provideTextDocumentContent(uri: Uri): Promise<string> {
Expand Down
8 changes: 8 additions & 0 deletions src/svnRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,14 @@ export class Repository {
return result.stdout;
}

public async removeUnversioned() {
const result = await this.exec(["cleanup", "--remove-unversioned"]);

this.svn.logOutput(result.stdout);

return result.stdout;
}

public async finishCheckout() {
const info = await this.getInfo();

Expand Down
13 changes: 9 additions & 4 deletions src/treeView/dataProviders/svnProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,22 @@ export default class SvnProvider implements TreeDataProvider<BaseNode> {
}

public async getChildren(element?: BaseNode): Promise<BaseNode[]> {
if (!this.sourceControlManager || this.sourceControlManager.openRepositories.length === 0) {
if (
!this.sourceControlManager ||
this.sourceControlManager.openRepositories.length === 0
) {
return Promise.resolve([]);
}

if (element) {
return element.getChildren();
}

const repositories = this.sourceControlManager.openRepositories.map(repository => {
return new RepositoryNode(repository.repository, this);
});
const repositories = this.sourceControlManager.openRepositories.map(
repository => {
return new RepositoryNode(repository.repository, this);
}
);

return repositories;
}
Expand Down
6 changes: 5 additions & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as path from "path";
import { Event } from "vscode";
import { Event, commands } from "vscode";
import { Operation } from "./common/types";
import { exists, lstat, readdir, rmdir, unlink } from "./fs";

Expand Down Expand Up @@ -196,3 +196,7 @@ export async function isSvnFolder(

return isSvnFolder(parent, true);
}

export function setVscodeContext(key: string, value: any) {
commands.executeCommand("setContext", key, value);
}
12 changes: 9 additions & 3 deletions src/vscodeModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ function loadVSCodeModule(id: string) {
module.paths.unshift(`${baseDir}/node_modules`);
return require(id);
} catch (eb) {
vscode.window.showErrorMessage(`Missing dependency, go to "${baseDir}" and run: npm install ${id}`);
vscode.window.showErrorMessage(
`Missing dependency, go to "${baseDir}" and run: npm install ${id}`
);
}
}

export const iconv = loadVSCodeModule("iconv-lite") as typeof import("iconv-lite");
export const jschardet = loadVSCodeModule("jschardet") as typeof import("jschardet");
export const iconv = loadVSCodeModule(
"iconv-lite"
) as typeof import("iconv-lite");
export const jschardet = loadVSCodeModule(
"jschardet"
) as typeof import("jschardet");