From 9071b55026538949125bb4eb40261b4af2666740 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Tue, 28 Mar 2017 00:35:06 -0400 Subject: [PATCH] Adds renamed file info into quick pick description --- src/git/models/logCommit.ts | 10 ++++++++-- src/git/parsers/logParser.ts | 6 +++--- src/quickPicks/commitDetails.ts | 2 +- src/quickPicks/gitQuickPicks.ts | 24 ++++++++++++++---------- src/quickPicks/repoStatus.ts | 6 +++++- 5 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/git/models/logCommit.ts b/src/git/models/logCommit.ts index f2074b5..45e7658 100644 --- a/src/git/models/logCommit.ts +++ b/src/git/models/logCommit.ts @@ -6,10 +6,16 @@ import * as path from 'path'; export type GitLogType = 'file' | 'repo'; +export interface IGitLogFileStatusEntry { + status: GitStatusFileStatus; + fileName: string; + originalFileName?: string; +} + export class GitLogCommit extends GitCommit { fileNames: string; - fileStatuses: { status: GitStatusFileStatus, fileName: string, originalFileName?: string }[]; + fileStatuses: IGitLogFileStatusEntry[]; nextSha?: string; nextFileName?: string; parentShas: string[]; @@ -24,7 +30,7 @@ export class GitLogCommit extends GitCommit { date: Date, message: string, status?: GitStatusFileStatus, - fileStatuses?: { status: GitStatusFileStatus, fileName: string, originalFileName?: string }[], + fileStatuses?: IGitLogFileStatusEntry[], lines?: IGitCommitLine[], originalFileName?: string, previousSha?: string, diff --git a/src/git/parsers/logParser.ts b/src/git/parsers/logParser.ts index 5aa32c3..e0c9db1 100644 --- a/src/git/parsers/logParser.ts +++ b/src/git/parsers/logParser.ts @@ -1,6 +1,6 @@ 'use strict'; import { Range } from 'vscode'; -import { Git, GitStatusFileStatus, GitLogCommit, GitLogType, IGitAuthor, IGitLog } from './../git'; +import { Git, GitStatusFileStatus, GitLogCommit, GitLogType, IGitAuthor, IGitLog, IGitLogFileStatusEntry } from './../git'; // import { Logger } from '../../logger'; import * as moment from 'moment'; import * as path from 'path'; @@ -18,7 +18,7 @@ interface ILogEntry { fileName?: string; originalFileName?: string; - fileStatuses?: { status: GitStatusFileStatus, fileName: string, originalFileName: string }[]; + fileStatuses?: IGitLogFileStatusEntry[]; status?: GitStatusFileStatus; @@ -134,7 +134,7 @@ export class GitLogParser { status: line[0] as GitStatusFileStatus, fileName: line.substring(1), originalFileName: undefined as string - }; + } as IGitLogFileStatusEntry; this._parseFileName(status); entry.fileStatuses.push(status); diff --git a/src/quickPicks/commitDetails.ts b/src/quickPicks/commitDetails.ts index bdf66a2..3d569a0 100644 --- a/src/quickPicks/commitDetails.ts +++ b/src/quickPicks/commitDetails.ts @@ -36,7 +36,7 @@ export class OpenCommitWorkingTreeFilesCommandQuickPickItem extends OpenFilesCom export class CommitDetailsQuickPick { static async show(git: GitService, commit: GitLogCommit, uri: Uri, goBackCommand?: CommandQuickPickItem, currentCommand?: CommandQuickPickItem, repoLog?: IGitLog): Promise { - const items: (CommitWithFileStatusQuickPickItem | CommandQuickPickItem)[] = commit.fileStatuses.map(fs => new CommitWithFileStatusQuickPickItem(commit, fs.fileName, fs.status)); + const items: (CommitWithFileStatusQuickPickItem | CommandQuickPickItem)[] = commit.fileStatuses.map(fs => new CommitWithFileStatusQuickPickItem(commit, fs)); let index = 0; diff --git a/src/quickPicks/gitQuickPicks.ts b/src/quickPicks/gitQuickPicks.ts index 55edf86..4ea8456 100644 --- a/src/quickPicks/gitQuickPicks.ts +++ b/src/quickPicks/gitQuickPicks.ts @@ -1,6 +1,6 @@ 'use strict'; import { QuickPickItem, Uri } from 'vscode'; -import { getGitStatusIcon, Git, GitCommit, GitStatusFileStatus, GitService, GitUri } from '../gitService'; +import { getGitStatusIcon, Git, GitCommit, GitStatusFileStatus, GitService, GitUri, IGitLogFileStatusEntry } from '../gitService'; import { OpenFileCommandQuickPickItem } from './quickPicks'; import * as moment from 'moment'; import * as path from 'path'; @@ -26,23 +26,27 @@ export class CommitWithFileStatusQuickPickItem extends OpenFileCommandQuickPickI shortSha: string; status: GitStatusFileStatus; - constructor(commit: GitCommit, fileName: string, status: GitStatusFileStatus) { - const icon = getGitStatusIcon(status); + constructor(commit: GitCommit, status: IGitLogFileStatusEntry) { + const icon = getGitStatusIcon(status.status); - let directory = Git.normalizePath(path.dirname(fileName)); + let directory = Git.normalizePath(path.dirname(status.fileName)); if (!directory || directory === '.') { directory = undefined; } - super(GitService.toGitContentUri(commit.sha, fileName, commit.repoPath, commit.originalFileName), { - label: `\u00a0\u00a0\u00a0\u00a0${icon}\u00a0\u00a0 ${path.basename(fileName)}`, - description: directory + let description = (status.status === 'R' && status.originalFileName) + ? `${directory || ''} \u00a0\u2190\u00a0 ${status.originalFileName}` + : directory; + + super(GitService.toGitContentUri(commit.sha, status.fileName, commit.repoPath, commit.originalFileName), { + label: `\u00a0\u00a0\u00a0\u00a0${icon}\u00a0\u00a0 ${path.basename(status.fileName)}`, + description: description }); - this.fileName = fileName; - this.gitUri = new GitUri(Uri.file(path.resolve(commit.repoPath, fileName))); + this.fileName = status.fileName; + this.gitUri = new GitUri(Uri.file(path.resolve(commit.repoPath, status.fileName))); this.sha = commit.sha; this.shortSha = commit.shortSha; - this.status = status; + this.status = status.status; } } \ No newline at end of file diff --git a/src/quickPicks/repoStatus.ts b/src/quickPicks/repoStatus.ts index d7747c2..a34a05a 100644 --- a/src/quickPicks/repoStatus.ts +++ b/src/quickPicks/repoStatus.ts @@ -17,9 +17,13 @@ export class OpenStatusFileCommandQuickPickItem extends OpenFileCommandQuickPick directory = undefined; } + let description = (status.status === 'R' && status.originalFileName) + ? `${directory || ''} \u00a0\u2190\u00a0 ${status.originalFileName}` + : directory; + super(uri, item || { label: `${status.staged ? '$(check)' : '\u00a0\u00a0\u00a0'}\u00a0\u00a0${icon}\u00a0\u00a0\u00a0${path.basename(status.fileName)}`, - description: directory + description: description }); } }