Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Fix up status command for tf.exe support #123

Merged
merged 2 commits into from
Feb 23, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions src/tfvc/commands/commandhelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ export class CommandHelper {
}

public static async ParseXml(xml: string): Promise<any> {
if (!xml) {
return;
}

return new Promise<any>((resolve, reject) => {
parseString(
xml,
Expand Down
7 changes: 2 additions & 5 deletions src/tfvc/commands/getinfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,11 @@ export class GetInfo implements ITfvcCommand<IItemInfo[]> {
return itemInfos;
}

const lines: string[] = CommandHelper.SplitIntoLines(executionResult.stdout);
const lines: string[] = CommandHelper.SplitIntoLines(executionResult.stdout, true, true);
let curMode: string = ""; // "" is local mode, "server" is server mode
let curItem: IItemInfo;
for (let i: number = 0; i < lines.length; i++) {
const line: string = lines[i];
if (!line || line.trim().length === 0) {
continue;
}
if (line.toLowerCase().startsWith("local information:")) {
// We are starting a new Info section for the next item.
// So, finish off any in progress item and start a new one.
Expand All @@ -84,7 +81,7 @@ export class GetInfo implements ITfvcCommand<IItemInfo[]> {
// Add the property to the current item
const colonPos: number = line.indexOf(":");
if (colonPos > 0) {
const propertyName = this.getPropertyName(curMode + line.slice(0, colonPos).trim().toLowerCase());
const propertyName: string = this.getPropertyName(curMode + line.slice(0, colonPos).trim().toLowerCase());
if (propertyName) {
const propertyValue = colonPos + 1 < line.length ? line.slice(colonPos + 1).trim() : "";
curItem[propertyName] = propertyValue;
Expand Down
104 changes: 102 additions & 2 deletions src/tfvc/commands/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,108 @@ export class Status implements ITfvcCommand<IPendingChange[]> {
return this.GetOptions();
}

/*
Parses the output of the status command when formatted as detailed
SAMPLE
$/jeyou/README.md;C19
User : Jeff Young (TFS)
Date : Wednesday, February 22, 2017 1:47:26 PM
Lock : none
Change : edit
Workspace : jeyou-dev00-tfexe-OnPrem
Local item : [JEYOU-DEV00] C:\repos\TfExe.Tfvc.L2VSCodeExtension.RC.TFS\README.md
File type : utf-8

-------------------------------------------------------------------------------------------------------------------------------------------------------------
Detected Changes:
-------------------------------------------------------------------------------------------------------------------------------------------------------------
$/jeyou/therightstuff.txt
User : Jeff Young (TFS)
Date : Wednesday, February 22, 2017 11:48:34 AM
Lock : none
Change : add
Workspace : jeyou-dev00-tfexe-OnPrem
Local item : [JEYOU-DEV00] C:\repos\TfExe.Tfvc.L2VSCodeExtension.RC.TFS\therightstuff.txt

1 change(s), 0 detected change(s)
*/
public async ParseExeOutput(executionResult: IExecutionResult): Promise<IPendingChange[]> {
//TODO: Parse this with format:detailed
return this.ParseOutput(executionResult);
// Throw if any errors are found in stderr or if exitcode is not 0
CommandHelper.ProcessErrors(this.GetArguments().GetCommand(), executionResult);

let changes: IPendingChange[] = [];
if (!executionResult.stdout) {
return changes;
}

const lines: string[] = CommandHelper.SplitIntoLines(executionResult.stdout, true, false); //leave empty lines
let detectedChanges: boolean = false;
let curChange: IPendingChange;
for (let i: number = 0; i < lines.length; i++) {
const line: string = lines[i];
if (line.indexOf(" detected change(s)") > 0) {
//This tells us we're done
break;
}

if (!line || line.trim().length === 0) {
//If we have a curChange, we're finished with it
if (curChange !== undefined) {
changes.push(curChange);
curChange = undefined;
}
continue;
}

if (line.indexOf("--------") === 0 || line.toLowerCase().startsWith("detected changes: ")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like you could use startswith instead of indexOf === 0 here. It would make it a bit easier to read.

//Starting Detected Changes...
detectedChanges = true;
continue;
}

if (line.startsWith("$/")) {
//$/jeyou/README.md;C19 //versioned
//$/jeyou/README.md //isCandidate
let parts: string[] = line.split(";C");

curChange = { changeType: undefined, computer: undefined, date: undefined, localItem: undefined,
sourceItem: undefined, lock: undefined, owner: undefined,
serverItem: (parts && parts.length >= 1 ? parts[0] : undefined),
version: (parts && parts.length === 2 ? parts[1] : "0"),
workspace: undefined, isCandidate: detectedChanges };
} else {
// Add the property to the current item
const colonPos: number = line.indexOf(":");
if (colonPos > 0) {
const propertyName = this.getPropertyName(line.slice(0, colonPos).trim().toLowerCase());
if (propertyName) {
let propertyValue: string = colonPos + 1 < line.length ? line.slice(colonPos + 1).trim() : "";
if (propertyName.toLowerCase() === "localitem") {
//Local item : [JEYOU-DEV00] C:\repos\TfExe.Tfvc.L2VSCodeExtension.RC.TFS\README.md
let parts: string[] = propertyValue.split("] ");
curChange["computer"] = parts[0].substr(1); //pop off the beginning [
propertyValue = parts[1];
}
curChange[propertyName] = propertyValue;
}
}
}
}

return changes;
}

private getPropertyName(name: string): string {
switch (name) {
case "local item": return "localItem";
case "source item": return "sourceItem";
case "user": return "owner"; //TODO: I don't think this is accurate
case "date": return "date";
case "lock": return "lock";
case "change": return "changeType";
case "workspace": return "workspace";
}
return undefined;
}

private add(changes: IPendingChange[], newChange: IPendingChange, ignoreFolders: boolean) {
Copy link
Member

@jpricket jpricket Feb 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't look like you are using add or convert at all

Expand Down Expand Up @@ -140,4 +239,5 @@ export class Status implements ITfvcCommand<IPendingChange[]> {
isCandidate: isCandidate
};
}

}
5 changes: 5 additions & 0 deletions test/tfvc/commands/commandhelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,11 @@ describe("Tfvc-CommandHelper", function() {
assert.equal(CommandHelper.TrimToXml(""), "");
});

it("should verify ParseXml - undefined input", async function() {
let xml: any = await CommandHelper.ParseXml(undefined);
assert.isUndefined(xml);
});

it("should verify ParseXml", async function() {
let text: string = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<one attr1=\"35\" attr2=\"two\"><child1 attr1=\"44\" attr2=\"55\" attr3=\"three\"/><child2>child two</child2>\r\n</one>\n\n";
let xml: any = await CommandHelper.ParseXml(text);
Expand Down
Loading