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

add private file #513

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@
"category": "Plastic SCM",
"title": "Open File",
"icon": "$(go-to-file)"
},
{
"command": "plastic-scm.addPrivateFile",
"category": "Plastic SCM",
"title": "Add Private File",
"icon": "$(add)"
}
],
"menus": {
Expand All @@ -114,6 +120,11 @@
"command": "plastic-scm.openFile",
"when": "scmProvider == plastic-scm && scmResourceGroup == status",
"group": "inline@1"
},
{
"command": "plastic-scm.addPrivateFile",
"when": "scmProvider == plastic-scm && scmResourceGroup == status",
"group": "inline@1"
}
]
}
Expand Down
33 changes: 33 additions & 0 deletions src/cm/commands/add/add.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

import { ICmParser, ICmResult, ICmShell } from "../../shell";
import { AddParser } from "./addParser";

export class Add {

public static async run(
shell: ICmShell,
paths: string[] | undefined
): Promise<void | undefined> {

if (!paths) {
return;
}

const args: string[] = [
...paths,
`--format='ADD {0}'`,
`--errorformat='ERR {0}'`,
];

const parser: ICmParser<void> = new AddParser();
try {
const result: ICmResult<void> = await shell.exec("add", args, parser);
if (!result.success || result.error) {
throw result.error;

Check failure on line 26 in src/cm/commands/add/add.ts

View workflow job for this annotation

GitHub Actions / Testing on ubuntu-latest

Expected an error object to be thrown

Check failure on line 26 in src/cm/commands/add/add.ts

View workflow job for this annotation

GitHub Actions / Testing on macOS-latest

Expected an error object to be thrown
}
return undefined;
} catch(e) {
console.log(e)

Check warning on line 30 in src/cm/commands/add/add.ts

View workflow job for this annotation

GitHub Actions / Testing on ubuntu-latest

Unexpected console statement

Check warning on line 30 in src/cm/commands/add/add.ts

View workflow job for this annotation

GitHub Actions / Testing on macOS-latest

Unexpected console statement
}
}
}
38 changes: 38 additions & 0 deletions src/cm/commands/add/addParser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

import * as os from "os";
import { ICmParser } from "../../shell";

export class AddParser implements ICmParser<void> {
private readonly mOutputBuffer: string[] = [];
private readonly mErrorBuffer: string[] = [];

readLineOut(line: string): void{

Check warning on line 9 in src/cm/commands/add/addParser.ts

View workflow job for this annotation

GitHub Actions / Testing on ubuntu-latest

Missing accessibility modifier on method definition readLineOut

Check warning on line 9 in src/cm/commands/add/addParser.ts

View workflow job for this annotation

GitHub Actions / Testing on macOS-latest

Missing accessibility modifier on method definition readLineOut
this.mOutputBuffer.push(line);
}
readLineErr(line: string): void{

Check warning on line 12 in src/cm/commands/add/addParser.ts

View workflow job for this annotation

GitHub Actions / Testing on ubuntu-latest

Missing accessibility modifier on method definition readLineErr

Check warning on line 12 in src/cm/commands/add/addParser.ts

View workflow job for this annotation

GitHub Actions / Testing on macOS-latest

Missing accessibility modifier on method definition readLineErr
this.mErrorBuffer.push(line);
}

parse(): Promise<void | undefined>{

Check warning on line 16 in src/cm/commands/add/addParser.ts

View workflow job for this annotation

GitHub Actions / Testing on ubuntu-latest

Missing accessibility modifier on method definition parse

Check warning on line 16 in src/cm/commands/add/addParser.ts

View workflow job for this annotation

GitHub Actions / Testing on macOS-latest

Missing accessibility modifier on method definition parse
return new Promise<void>((resolve, reject) => {

Check failure on line 17 in src/cm/commands/add/addParser.ts

View workflow job for this annotation

GitHub Actions / Testing on ubuntu-latest

Promise returned in function argument where a void return was expected

Check failure on line 17 in src/cm/commands/add/addParser.ts

View workflow job for this annotation

GitHub Actions / Testing on ubuntu-latest

'resolve' is defined but never used

Check failure on line 17 in src/cm/commands/add/addParser.ts

View workflow job for this annotation

GitHub Actions / Testing on ubuntu-latest

'reject' is defined but never used

Check failure on line 17 in src/cm/commands/add/addParser.ts

View workflow job for this annotation

GitHub Actions / Testing on macOS-latest

Promise returned in function argument where a void return was expected

Check failure on line 17 in src/cm/commands/add/addParser.ts

View workflow job for this annotation

GitHub Actions / Testing on macOS-latest

'resolve' is defined but never used

Check failure on line 17 in src/cm/commands/add/addParser.ts

View workflow job for this annotation

GitHub Actions / Testing on macOS-latest

'reject' is defined but never used
return Promise.all(this.mOutputBuffer);
});

Check warning on line 19 in src/cm/commands/add/addParser.ts

View workflow job for this annotation

GitHub Actions / Testing on ubuntu-latest

Missing accessibility modifier on method definition getError

Check warning on line 19 in src/cm/commands/add/addParser.ts

View workflow job for this annotation

GitHub Actions / Testing on macOS-latest

Missing accessibility modifier on method definition getError
}
getError(): Error | undefined{
var errMsg = this.mOutputBuffer.filter((line) => line.startsWith("ERR"));

if(this.mErrorBuffer.length > 0){
return new Error(this.mErrorBuffer.concat(errMsg).join(os.EOL))
}

if(errMsg.length > 0){
return new Error(errMsg.join(os.EOL))
}

return undefined;
}

Check warning on line 33 in src/cm/commands/add/addParser.ts

View workflow job for this annotation

GitHub Actions / Testing on ubuntu-latest

Missing accessibility modifier on method definition getOutputLines

Check warning on line 33 in src/cm/commands/add/addParser.ts

View workflow job for this annotation

GitHub Actions / Testing on macOS-latest

Missing accessibility modifier on method definition getOutputLines

getOutputLines(): string[]{
return this.mOutputBuffer.concat(this.mErrorBuffer);
}
}
1 change: 1 addition & 0 deletions src/cm/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export { GetFile } from "./getFile/getFile";
export { GetWorkspaceFromPath } from "./getWorkspaceFromPath/getWorkspaceFromPath";
export { Status } from "./status/status";
export { Checkin } from "./checkin/checkin";
export { Add } from "./add/add";
55 changes: 55 additions & 0 deletions src/commands/addPrivateFile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { commands, Disposable} from "vscode";
import {
Add as CmAddCommand,
} from "../cm/commands";
import { PlasticScm } from "../plasticScm";
import { PlasticScmResource } from "../plasticScmResource";
import { Workspace } from "../workspace";
import { WorkspaceOperation } from "../workspaceOperations";
import { ChangeType } from "../models";

Check failure on line 9 in src/commands/addPrivateFile.ts

View workflow job for this annotation

GitHub Actions / Testing on ubuntu-latest

Imports should be sorted alphabetically

Check failure on line 9 in src/commands/addPrivateFile.ts

View workflow job for this annotation

GitHub Actions / Testing on macOS-latest

Imports should be sorted alphabetically

export class AddPrivateFileCommand implements Disposable {
private readonly mPlasticScm: PlasticScm;
private readonly mDisposable?: Disposable;

public constructor(plasticScm: PlasticScm) {
this.mPlasticScm = plasticScm;
this.mDisposable = commands.registerCommand(
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
"plastic-scm.addPrivateFile", args => execute(args, plasticScm));
}

public dispose(): void {
if (this.mDisposable) {
this.mDisposable.dispose();
}
}
}

async function execute(arg: any, mPlasticScm: PlasticScm) {
const workspace: Workspace | undefined = arg instanceof Workspace ?
arg as Workspace :
await mPlasticScm.promptUserToPickWorkspace();

if (!workspace) {
return;
}

if (workspace.operations.isRunning(WorkspaceOperation.Checkin)) {
return;
}

let resources: PlasticScmResource[];
if (!(arg instanceof PlasticScmResource)) {
resources = arg.resourceStates;

Check failure on line 44 in src/commands/addPrivateFile.ts

View workflow job for this annotation

GitHub Actions / Testing on ubuntu-latest

Unsafe assignment of an `any` value

Check failure on line 44 in src/commands/addPrivateFile.ts

View workflow job for this annotation

GitHub Actions / Testing on ubuntu-latest

Unsafe member access .resourceStates on an `any` value

Check failure on line 44 in src/commands/addPrivateFile.ts

View workflow job for this annotation

GitHub Actions / Testing on macOS-latest

Unsafe assignment of an `any` value

Check failure on line 44 in src/commands/addPrivateFile.ts

View workflow job for this annotation

GitHub Actions / Testing on macOS-latest

Unsafe member access .resourceStates on an `any` value
}else {
resources = [arg];
}

const paths = resources.filter(r => r.type === ChangeType.Private).map(r => r.resourceUri.fsPath);

if (paths.length === 0) {
return;
}
await CmAddCommand.run(workspace.shell, paths);
}
1 change: 1 addition & 0 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./checkin";
export * from "./addPrivateFile";
3 changes: 2 additions & 1 deletion src/plasticScm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
window as VsCodeWindow,
workspace as VsCodeWorkspace,
} from "vscode";
import { CheckinCommand } from "./commands";
import { CheckinCommand, AddPrivateFileCommand } from "./commands";

Check failure on line 10 in src/plasticScm.ts

View workflow job for this annotation

GitHub Actions / Testing on ubuntu-latest

Imports should be sorted alphabetically

Check failure on line 10 in src/plasticScm.ts

View workflow job for this annotation

GitHub Actions / Testing on macOS-latest

Imports should be sorted alphabetically
import { GetWorkspaceFromPath } from "./cm/commands";
import { IConfig } from "./config";
import { IWorkspaceInfo } from "./models";
Expand Down Expand Up @@ -90,6 +90,7 @@
this.mDisposables.push(new RefreshCommand(this));
this.mDisposables.push(new OpenFileCommand(this));
this.mDisposables.push(new PlasticScmDecorations(this));
this.mDisposables.push(new AddPrivateFileCommand(this));
}
}

Expand Down
Loading