From 2c69e4e50fd4f5ffd715a9b1dbb3340c08d0380d Mon Sep 17 00:00:00 2001 From: Joao Moreno Date: Mon, 13 Feb 2017 16:43:01 +0100 Subject: [PATCH] git: renames fixes #18654 --- extensions/git/src/commands.ts | 29 ++++++++++++++++++++--------- extensions/git/src/model.ts | 22 ++++++++++++++++------ 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 10af98114e3..3746ab9b9f1 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -113,13 +113,13 @@ export class CommandCenter { const right = this.getRightResource(resource); const title = this.getTitle(resource); - if (!left) { - if (!right) { - // TODO - console.error('oh no'); - return; - } + if (!right) { + // TODO + console.error('oh no'); + return; + } + if (!left) { return await commands.executeCommand('vscode.open', right); } @@ -130,11 +130,11 @@ export class CommandCenter { switch (resource.type) { case Status.INDEX_MODIFIED: case Status.INDEX_RENAMED: - return resource.uri.with({ scheme: 'git', query: 'HEAD' }); + return resource.original.with({ scheme: 'git', query: 'HEAD' }); case Status.MODIFIED: - const uriString = resource.uri.toString(); - const [indexStatus] = this.model.indexGroup.resources.filter(r => r.uri.toString() === uriString); + const uriString = resource.original.toString(); + const [indexStatus] = this.model.indexGroup.resources.filter(r => r.original.toString() === uriString); if (indexStatus) { return resource.uri.with({ scheme: 'git' }); @@ -149,6 +149,8 @@ export class CommandCenter { case Status.INDEX_MODIFIED: case Status.INDEX_ADDED: case Status.INDEX_COPIED: + return resource.uri.with({ scheme: 'git' }); + case Status.INDEX_RENAMED: return resource.uri.with({ scheme: 'git' }); @@ -159,6 +161,15 @@ export class CommandCenter { case Status.MODIFIED: case Status.UNTRACKED: case Status.IGNORED: + const uriString = resource.uri.toString(); + const [indexStatus] = this.model.indexGroup.resources.filter(r => r.uri.toString() === uriString); + + if (indexStatus && indexStatus.rename) { + return indexStatus.rename; + } + + return resource.uri; + case Status.BOTH_MODIFIED: return resource.uri; } diff --git a/extensions/git/src/model.ts b/extensions/git/src/model.ts index f894ad1998f..80fd9d7191d 100644 --- a/extensions/git/src/model.ts +++ b/extensions/git/src/model.ts @@ -43,8 +43,17 @@ export enum Status { export class Resource implements SCMResource { - get uri(): Uri { return this._uri; } + get uri(): Uri { + if (this.rename && (this._type === Status.MODIFIED || this._type === Status.DELETED || this._type === Status.INDEX_RENAMED)) { + return this.rename; + } + + return this._uri; + } + get type(): Status { return this._type; } + get original(): Uri { return this._uri; } + get rename(): Uri | undefined { return this._rename; } private static Icons = { light: { @@ -110,8 +119,8 @@ export class Resource implements SCMResource { return { strikeThrough: this.strikeThrough, light, dark }; } - constructor(private _uri: Uri, private _type: Status) { - + constructor(private _uri: Uri, private _type: Status, private _rename?: Uri) { + // console.log(this); } } @@ -435,6 +444,7 @@ export class Model { status.forEach(raw => { const uri = Uri.file(path.join(this.repositoryRoot, raw.path)); + const renameUri = raw.rename ? Uri.file(path.join(this.repositoryRoot, raw.rename)) : undefined; switch (raw.x + raw.y) { case '??': return workingTree.push(new Resource(uri, Status.UNTRACKED)); @@ -454,13 +464,13 @@ export class Model { case 'M': index.push(new Resource(uri, Status.INDEX_MODIFIED)); isModifiedInIndex = true; break; case 'A': index.push(new Resource(uri, Status.INDEX_ADDED)); break; case 'D': index.push(new Resource(uri, Status.INDEX_DELETED)); break; - case 'R': index.push(new Resource(uri, Status.INDEX_RENAMED/*, raw.rename*/)); break; + case 'R': index.push(new Resource(uri, Status.INDEX_RENAMED, renameUri)); break; case 'C': index.push(new Resource(uri, Status.INDEX_COPIED)); break; } switch (raw.y) { - case 'M': workingTree.push(new Resource(uri, Status.MODIFIED/*, raw.rename*/)); break; - case 'D': workingTree.push(new Resource(uri, Status.DELETED/*, raw.rename*/)); break; + case 'M': workingTree.push(new Resource(uri, Status.MODIFIED, renameUri)); break; + case 'D': workingTree.push(new Resource(uri, Status.DELETED, renameUri)); break; } });