From bfd310fa8d72652a85a3329c2345a195d52a7b0c Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Thu, 25 Apr 2019 00:06:48 -0400 Subject: [PATCH] Adds renamed file path to file view nodes Adds originalPath token --- package.json | 18 +++++++++--------- src/git/formatters/statusFormatter.ts | 14 ++++++++++++++ src/git/models/file.ts | 6 ++++++ src/system/string.ts | 15 +++++++++++++++ src/views/nodes/commitFileNode.ts | 9 ++++++--- src/views/nodes/resultsFileNode.ts | 18 ++++++++++++------ src/views/nodes/statusFileNode.ts | 6 +++--- 7 files changed, 65 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index 89c4aa4..6bb2f07 100644 --- a/package.json +++ b/package.json @@ -1266,13 +1266,13 @@ "gitlens.views.commitFileFormat": { "type": "string", "default": "${file}", - "markdownDescription": "Specifies the format of a committed file in the views\n- Available tokens\n - `${directory}` — directory name\n - `${file}` — file name\n - `${filePath}` — formatted file name and path\n - `${path}` — full file path", + "markdownDescription": "Specifies the format of a committed file in the views\n- Available tokens\n - `${directory}` — directory name\n - `${file}` — file name\n - `${filePath}` — formatted file name and path\n - `${originalPath}` — full file path of the original file if renamed\n - `${path}` — full file path", "scope": "window" }, "gitlens.views.commitFileDescriptionFormat": { "type": "string", - "default": "${directory}", - "markdownDescription": "Specifies the description format of a committed file in the views\n- Available tokens\n - `${directory}` — directory name\n - `${file}` — file name\n - `${filePath}` — formatted file name and path\n - `${path}` — full file path", + "default": "${directory}${ ← originalPath}", + "markdownDescription": "Specifies the description format of a committed file in the views\n- Available tokens\n - `${directory}` — directory name\n - `${file}` — file name\n - `${filePath}` — formatted file name and path\n - `${originalPath}` — full file path of the original file if renamed\n - `${path}` — full file path", "scope": "window" }, "gitlens.views.commitFormat": { @@ -1576,13 +1576,13 @@ "gitlens.views.stashFileFormat": { "type": "string", "default": "${file}", - "markdownDescription": "Specifies the format of a stashed file in the views\n- Available tokens\n - `${directory}` — directory name\n - `${file}` — file name\n - `${filePath}` — formatted file name and path\n - `${path}` — full file path", + "markdownDescription": "Specifies the format of a stashed file in the views\n- Available tokens\n - `${directory}` — directory name\n - `${file}` — file name\n - `${filePath}` — formatted file name and path\n - `${originalPath}` — full file path of the original file if renamed\n - `${path}` — full file path", "scope": "window" }, "gitlens.views.stashFileDescriptionFormat": { "type": "string", - "default": "${directory}", - "markdownDescription": "Specifies the description format of a stashed file in the views\n- Available tokens\n - `${directory}` — directory name\n - `${file}` — file name\n - `${filePath}` — formatted file name and path\n - `${path}` — full file path", + "default": "${directory}${ ← originalPath}", + "markdownDescription": "Specifies the description format of a stashed file in the views\n- Available tokens\n - `${directory}` — directory name\n - `${file}` — file name\n - `${filePath}` — formatted file name and path\n - `${originalPath}` — full file path of the original file if renamed\n - `${path}` — full file path", "scope": "window" }, "gitlens.views.stashFormat": { @@ -1600,13 +1600,13 @@ "gitlens.views.statusFileFormat": { "type": "string", "default": "${working }${file}", - "markdownDescription": "Specifies the format of the status of a working or committed file in the views\n- Available tokens\n - `${directory}` — directory name\n - `${file}` — file name\n - `${filePath}` — formatted file name and path\n - `${path}` — full file path\n - `${working}` — optional indicator if the file is uncommitted", + "markdownDescription": "Specifies the format of the status of a working or committed file in the views\n- Available tokens\n - `${directory}` — directory name\n - `${file}` — file name\n - `${filePath}` — formatted file name and path\n - `${originalPath}` — full file path of the original file if renamed\n - `${path}` — full file path\n - `${working}` — optional indicator if the file is uncommitted", "scope": "window" }, "gitlens.views.statusFileDescriptionFormat": { "type": "string", - "default": "${directory}", - "markdownDescription": "Specifies the description format of the status of a working or committed file in the views\n- Available tokens\n - `${directory}` — directory name\n - `${file}` — file name\n - `${filePath}` — formatted file name and path\n - `${path}` — full file path\n - `${working}` — optional indicator if the file is uncommitted", + "default": "${directory}${ ← originalPath}", + "markdownDescription": "Specifies the description format of the status of a working or committed file in the views\n- Available tokens\n - `${directory}` — directory name\n - `${file}` — file name\n - `${filePath}` — formatted file name and path\n - `${originalPath}` — full file path of the original file if renamed\n - `${path}` — full file path\n - `${working}` — optional indicator if the file is uncommitted", "scope": "window" }, "gitlens.advanced.abbreviatedShaLength": { diff --git a/src/git/formatters/statusFormatter.ts b/src/git/formatters/statusFormatter.ts index ddd3a3e..d34b1eb 100644 --- a/src/git/formatters/statusFormatter.ts +++ b/src/git/formatters/statusFormatter.ts @@ -12,6 +12,7 @@ export interface StatusFormatOptions extends FormatOptions { directory?: Strings.TokenOptions; file?: Strings.TokenOptions; filePath?: Strings.TokenOptions; + originalPath?: Strings.TokenOptions; path?: Strings.TokenOptions; status?: Strings.TokenOptions; working?: Strings.TokenOptions; @@ -34,6 +35,19 @@ export class StatusFileFormatter extends Formatter return this._padOrTruncate(filePath, this._options.tokenOptions.filePath); } + get originalPath() { + // if ( + // // this._item.status !== 'R' || + // this._item.originalFileName == null || + // this._item.originalFileName.length === 0 + // ) { + // return ''; + // } + + const originalPath = GitFile.getOriginalRelativePath(this._item, this._options.relativePath); + return this._padOrTruncate(originalPath, this._options.tokenOptions.originalPath); + } + get path() { const directory = GitFile.getRelativePath(this._item, this._options.relativePath); return this._padOrTruncate(directory, this._options.tokenOptions.path); diff --git a/src/git/models/file.ts b/src/git/models/file.ts index 258121c..8a58a92 100644 --- a/src/git/models/file.ts +++ b/src/git/models/file.ts @@ -38,6 +38,12 @@ export namespace GitFile { return GitUri.getFormattedPath(file.fileName, options); } + export function getOriginalRelativePath(file: GitFile, relativeTo?: string): string { + if (file.originalFileName == null || file.originalFileName.length === 0) return ''; + + return GitUri.getRelativePath(file.originalFileName, relativeTo); + } + export function getRelativePath(file: GitFile, relativeTo?: string): string { return GitUri.getRelativePath(file.fileName, relativeTo); } diff --git a/src/system/string.ts b/src/system/string.ts index f7dc093..17aeb86 100644 --- a/src/system/string.ts +++ b/src/system/string.ts @@ -15,6 +15,21 @@ export namespace Strings { Backslash = 92 } + export function getCommonBase(s1: string, s2: string, delimiter: string) { + let char; + let index = 0; + for (let i = 0; i < s1.length; i++) { + char = s1[i]; + if (char !== s2[i]) break; + + if (char === delimiter) { + index = i; + } + } + + return index > 0 ? s1.substring(0, index + 1) : undefined; + } + export function getDurationMilliseconds(start: [number, number]) { const [secs, nanosecs] = process.hrtime(start); return secs * 1000 + Math.floor(nanosecs / 1000000); diff --git a/src/views/nodes/commitFileNode.ts b/src/views/nodes/commitFileNode.ts index 62a8b71..4cf0fe5 100644 --- a/src/views/nodes/commitFileNode.ts +++ b/src/views/nodes/commitFileNode.ts @@ -158,7 +158,7 @@ export class CommitFileNode extends ViewRefFileNode { if (this._tooltip === undefined) { if (this._displayAs & CommitFileNodeDisplayAs.CommitLabel) { // eslint-disable-next-line no-template-curly-in-string - const status = StatusFileFormatter.fromTemplate('${status}', this.file); + const status = StatusFileFormatter.fromTemplate('${status}${ (originalPath)}', this.file); this._tooltip = CommitFormatter.fromTemplate( this.commit.isUncommitted ? `\${author} ${GlyphChars.Dash} \${id}\n${status}\n\${ago} (\${date})` @@ -170,8 +170,11 @@ export class CommitFileNode extends ViewRefFileNode { ); } else { - // eslint-disable-next-line no-template-curly-in-string - this._tooltip = StatusFileFormatter.fromTemplate('${file}\n${directory}/\n\n${status}', this.file); + this._tooltip = StatusFileFormatter.fromTemplate( + // eslint-disable-next-line no-template-curly-in-string + '${file}\n${directory}/\n\n${status}${ (originalPath)}', + this.file + ); } } return this._tooltip; diff --git a/src/views/nodes/resultsFileNode.ts b/src/views/nodes/resultsFileNode.ts index 7f80fd0..efe4403 100644 --- a/src/views/nodes/resultsFileNode.ts +++ b/src/views/nodes/resultsFileNode.ts @@ -35,8 +35,11 @@ export class ResultsFileNode extends ViewRefFileNode { const item = new TreeItem(this.label, TreeItemCollapsibleState.None); item.contextValue = ResourceType.ResultsFile; item.description = this.description; - // eslint-disable-next-line no-template-curly-in-string - item.tooltip = StatusFileFormatter.fromTemplate('${file}\n${directory}/\n\n${status}', this.file); + item.tooltip = StatusFileFormatter.fromTemplate( + // eslint-disable-next-line no-template-curly-in-string + '${file}\n${directory}/\n\n${status}${ (originalPath)}', + this.file + ); const statusIcon = GitFile.getStatusIcon(this.file.status); item.iconPath = { @@ -51,10 +54,13 @@ export class ResultsFileNode extends ViewRefFileNode { private _description: string | undefined; get description() { if (this._description === undefined) { - // eslint-disable-next-line no-template-curly-in-string - this._description = StatusFileFormatter.fromTemplate('${directory}', this.file, { - relativePath: this.relativePath - }); + this._description = StatusFileFormatter.fromTemplate( + this.view.config.commitFileDescriptionFormat, + this.file, + { + relativePath: this.relativePath + } + ); } return this._description; } diff --git a/src/views/nodes/statusFileNode.ts b/src/views/nodes/statusFileNode.ts index 17d50d2..f19c269 100644 --- a/src/views/nodes/statusFileNode.ts +++ b/src/views/nodes/statusFileNode.ts @@ -60,7 +60,7 @@ export class StatusFileNode extends ViewNode { item.contextValue += '+staged'; item.tooltip = StatusFileFormatter.fromTemplate( // eslint-disable-next-line no-template-curly-in-string - '${file}\n${directory}/\n\n${status} in Index (staged)', + '${file}\n${directory}/\n\n${status}${ (originalPath)} in Index (staged)', this.file ); } @@ -68,7 +68,7 @@ export class StatusFileNode extends ViewNode { item.contextValue += '+unstaged'; item.tooltip = StatusFileFormatter.fromTemplate( // eslint-disable-next-line no-template-curly-in-string - '${file}\n${directory}/\n\n${status} in Working Tree', + '${file}\n${directory}/\n\n${status}${ (originalPath)} in Working Tree', this.file ); } @@ -108,7 +108,7 @@ export class StatusFileNode extends ViewNode { } item.tooltip = StatusFileFormatter.fromTemplate( - `\${file}\n\${directory}/\n\n\${status} in ${this.getChangedIn()}`, + `\${file}\n\${directory}/\n\n\${status}\${ (originalPath)} in ${this.getChangedIn()}`, this.file ); }