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

Adding some debug logging #83

Merged
merged 1 commit into from
Feb 2, 2017
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
2 changes: 1 addition & 1 deletion src/contexts/tfvccontext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class TfvcContext implements IRepositoryContext {

//Need to call tf.cmd to get TFVC information (and constructors can't be async)
public async Initialize(): Promise<void> {
Logger.LogDebug(`Looking for TFVC repository at ${this._tfvcFolder})`);
Logger.LogDebug(`Looking for TFVC repository at ${this._tfvcFolder}`);
const tfvc: Tfvc = new Tfvc();
const repo: Repository = tfvc.Open(undefined, this._tfvcFolder);
const tfvcWorkspace: IWorkspace = await repo.FindWorkspace(this._tfvcFolder);
Expand Down
5 changes: 5 additions & 0 deletions src/tfvc/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"use strict";

import { TeamServerContext} from "../contexts/servercontext";
import { Logger } from "../helpers/logger";
import { ITfvcCommand, IExecutionResult } from "./interfaces";
import { Tfvc } from "./tfvc";
import { IArgumentProvider, IWorkspace, IPendingChange } from "./interfaces";
Expand All @@ -26,6 +27,7 @@ export class Repository {
private _versionAlreadyChecked = false;

public constructor(serverContext: TeamServerContext, tfvc: Tfvc, repositoryRootFolder: string, env: any = {}) {
Logger.LogDebug(`TFVC Repository created with repositoryRootFolder='${repositoryRootFolder}'`);
this._serverContext = serverContext;
this._tfvc = tfvc;
this._repositoryRootFolder = repositoryRootFolder;
Expand All @@ -46,17 +48,20 @@ export class Repository {
}

public async FindWorkspace(localPath: string): Promise<IWorkspace> {
Logger.LogDebug(`TFVC Repository.FindWorkspace with localPath='${localPath}'`);
return this.RunCommand<IWorkspace>(
new FindWorkspace(localPath));
}

public async GetStatus(ignoreFiles?: boolean): Promise<IPendingChange[]> {
Logger.LogDebug(`TFVC Repository.GetStatus`);
return this.RunCommand<IPendingChange[]>(
new Status(this._serverContext, ignoreFiles === undefined ? true : ignoreFiles));
}

public async CheckVersion(): Promise<string> {
if (!this._versionAlreadyChecked) {
Logger.LogDebug(`TFVC Repository.CheckVersion`);
// Set the versionAlreadyChecked flag first in case one of the other lines throws
this._versionAlreadyChecked = true;
const version: string = await this.RunCommand<string>(new GetVersion());
Expand Down
11 changes: 11 additions & 0 deletions src/tfvc/tfvc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import * as cp from "child_process";
import { EventEmitter, Event } from "vscode";
import { TeamServerContext } from "../contexts/servercontext";
import { Logger } from "../helpers/logger";
import { Strings } from "../helpers/strings";
import { IDisposable, toDisposable, dispose } from "./util";
import { IArgumentProvider, IExecutionResult } from "./interfaces";
Expand All @@ -27,13 +28,16 @@ export class Tfvc {
public get onOutput(): Event<string> { return this._onOutput.event; }

public constructor(localPath?: string) {
Logger.LogDebug(`TFVC Creating Tfvc object with localPath='${localPath}'`);
if (localPath !== undefined) {
this._tfvcPath = localPath;
} else {
// get the location from settings
const settings = new TfvcSettings();
this._tfvcPath = settings.Location;
Logger.LogDebug(`TFVC Retrieved from settings; localPath='${this._tfvcPath}'`);
if (!this._tfvcPath) {
Logger.LogWarning(`TFVC Couldn't find where the TF command lives on disk.`);
throw new TfvcError({
message: Strings.TfvcLocationMissingError,
tfvcErrorCode: TfvcErrorCodes.TfvcLocationMissing
Expand All @@ -47,12 +51,14 @@ export class Tfvc {
// if it exists, check to ensure that it's a file and not a folder
const stats: any = fs.lstatSync(this._tfvcPath);
if (!stats || !stats.isFile()) {
Logger.LogWarning(`TFVC ${this._tfvcPath} exists but isn't a file.`);
throw new TfvcError({
message: Strings.TfMissingError + this._tfvcPath,
tfvcErrorCode: TfvcErrorCodes.TfvcNotFound
});
}
} else {
Logger.LogWarning(`TFVC ${this._tfvcPath} does not exist.`);
throw new TfvcError({
message: Strings.TfMissingError + this._tfvcPath,
tfvcErrorCode: TfvcErrorCodes.TfvcNotFound
Expand All @@ -67,13 +73,15 @@ export class Tfvc {
public CheckVersion(version: string) {
if (!version) {
// If the version isn't set just return
Logger.LogDebug(`TFVC CheckVersion called without a version.`);
return;
}

// check the version of TFVC command line
const minVersion: TfvcVersion = TfvcVersion.FromString("14.0.4");
const curVersion: TfvcVersion = TfvcVersion.FromString(version);
if (TfvcVersion.Compare(curVersion, minVersion) < 0) {
Logger.LogWarning(`TFVC ${version} is less that the min version of 14.0.4.`);
throw new TfvcError({
message: Strings.TfVersionWarning + minVersion.ToString(),
tfvcErrorCode: TfvcErrorCodes.TfvcMinVersionWarning
Expand Down Expand Up @@ -105,6 +113,7 @@ export class Tfvc {

options.env = _.assign({}, process.env, options.env || {});

Logger.LogDebug(`TFVC: tf ${args.GetArgumentsForDisplay()}`);
if (options.log !== false) {
this.log(`tf ${args.GetArgumentsForDisplay()}\n`);
}
Expand All @@ -120,6 +129,7 @@ export class Tfvc {
}

const result = await Tfvc.execProcess(child);
Logger.LogDebug(`TFVC exit code: ${result.exitCode}`);

if (result.exitCode) {
let tfvcErrorCode: string = null;
Expand All @@ -142,6 +152,7 @@ export class Tfvc {
message = Strings.NotATfvcRepository;
}

Logger.LogDebug(`TFVC errors: ${result.stderr}`);
if (options.log !== false) {
this.log(`${result.stderr}\n`);
}
Expand Down