Skip to content

Commit

Permalink
Adds renamed file path to file view nodes
Browse files Browse the repository at this point in the history
Adds originalPath token
  • Loading branch information
eamodio committed Apr 28, 2019
1 parent 5d1a2e6 commit bfd310f
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 21 deletions.
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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": {
Expand All @@ -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": {
Expand Down
14 changes: 14 additions & 0 deletions src/git/formatters/statusFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,6 +35,19 @@ export class StatusFileFormatter extends Formatter<GitFile, StatusFormatOptions>
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);
Expand Down
6 changes: 6 additions & 0 deletions src/git/models/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
15 changes: 15 additions & 0 deletions src/system/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 6 additions & 3 deletions src/views/nodes/commitFileNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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})`
Expand All @@ -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;
Expand Down
18 changes: 12 additions & 6 deletions src/views/nodes/resultsFileNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions src/views/nodes/statusFileNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ 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
);
}
else {
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
);
}
Expand Down Expand Up @@ -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
);
}
Expand Down

0 comments on commit bfd310f

Please sign in to comment.