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 1 commit 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;
}
return undefined;
} catch(e) {
console.log(e)
}
}
}
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{
this.mOutputBuffer.push(line);
}
readLineErr(line: string): void{
this.mErrorBuffer.push(line);
}

parse(): Promise<void | undefined>{
return new Promise<void>((resolve, reject) => {
return Promise.all(this.mOutputBuffer);
});
}
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;
}

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";

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;
}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 @@ import {
window as VsCodeWindow,
workspace as VsCodeWorkspace,
} from "vscode";
import { CheckinCommand } from "./commands";
import { CheckinCommand, AddPrivateFileCommand } from "./commands";
import { GetWorkspaceFromPath } from "./cm/commands";
import { IConfig } from "./config";
import { IWorkspaceInfo } from "./models";
Expand Down Expand Up @@ -90,6 +90,7 @@ export class PlasticScm implements Disposable {
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