From 31f4ab7e45c4a653e70c0b63dee9edc39277569b Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Tue, 11 Feb 2020 03:03:14 -0500 Subject: [PATCH] Adds staged changes to file/line history --- src/git/models/status.ts | 2 +- src/views/nodes/fileHistoryNode.ts | 107 ++++++++++++++++++++---------- src/views/nodes/lineHistoryNode.ts | 132 +++++++++++++++++++++++++++---------- 3 files changed, 172 insertions(+), 69 deletions(-) diff --git a/src/git/models/status.ts b/src/git/models/status.ts index 0b89116..d30442e 100644 --- a/src/git/models/status.ts +++ b/src/git/models/status.ts @@ -148,7 +148,7 @@ export class GitStatusFile implements GitFile { ) {} get status(): GitFileStatus { - return this.indexStatus || this.workingTreeStatus || '?'; + return this.indexStatus ?? this.workingTreeStatus ?? '?'; } get staged() { diff --git a/src/views/nodes/fileHistoryNode.ts b/src/views/nodes/fileHistoryNode.ts index a894f95..1b8d926 100644 --- a/src/views/nodes/fileHistoryNode.ts +++ b/src/views/nodes/fileHistoryNode.ts @@ -43,41 +43,82 @@ export class FileHistoryNode extends SubscribeableViewNode implements PageableVi if (this.uri.sha === undefined) { const status = await Container.git.getStatusForFile(this.uri.repoPath!, this.uri.fsPath); - if (status !== undefined && (status.indexStatus !== undefined || status.workingTreeStatus !== undefined)) { - let sha; - let previousSha; - if (status.workingTreeStatus !== undefined) { - sha = GitService.uncommittedSha; - if (status.indexStatus !== undefined) { - previousSha = GitService.uncommittedStagedSha; - } else if (status.workingTreeStatus !== '?') { - previousSha = 'HEAD'; - } + if (status?.workingTreeStatus !== undefined || status?.indexStatus !== undefined) { + const user = await Container.git.getCurrentUser(this.uri.repoPath!); + if (status.workingTreeStatus !== undefined && status.indexStatus !== undefined) { + let commit = new GitLogCommit( + GitCommitType.LogFile, + this.uri.repoPath!, + GitService.uncommittedSha, + 'You', + user !== undefined ? user.email : undefined, + new Date(), + new Date(), + '', + status.fileName, + [status], + status.status, + status.originalFileName, + GitService.uncommittedStagedSha, + status.originalFileName || status.fileName + ); + + children.push( + new CommitFileNode(this.view, this, status, commit, { + displayAsCommit: true, + inFileHistory: true + }) + ); + + commit = new GitLogCommit( + GitCommitType.LogFile, + this.uri.repoPath!, + GitService.uncommittedStagedSha, + 'You', + user !== undefined ? user.email : undefined, + new Date(), + new Date(), + '', + status.fileName, + [status], + status.status, + status.originalFileName, + 'HEAD', + status.originalFileName || status.fileName + ); + + children.push( + new CommitFileNode(this.view, this, status, commit, { + displayAsCommit: true, + inFileHistory: true + }) + ); } else { - sha = GitService.uncommittedStagedSha; - previousSha = 'HEAD'; + const commit = new GitLogCommit( + GitCommitType.LogFile, + this.uri.repoPath!, + status.workingTreeStatus !== undefined + ? GitService.uncommittedSha + : GitService.uncommittedStagedSha, + 'You', + user !== undefined ? user.email : undefined, + new Date(), + new Date(), + '', + status.fileName, + [status], + status.status, + status.originalFileName, + 'HEAD', + status.originalFileName || status.fileName + ); + children.push( + new CommitFileNode(this.view, this, status, commit, { + displayAsCommit: true, + inFileHistory: true + }) + ); } - - const user = await Container.git.getCurrentUser(this.uri.repoPath!); - const commit = new GitLogCommit( - GitCommitType.LogFile, - this.uri.repoPath!, - sha, - 'You', - user !== undefined ? user.email : undefined, - new Date(), - new Date(), - '', - status.fileName, - [status], - status.status, - status.originalFileName, - previousSha, - status.originalFileName || status.fileName - ); - children.push( - new CommitFileNode(this.view, this, status, commit, { displayAsCommit: true, inFileHistory: true }) - ); } } diff --git a/src/views/nodes/lineHistoryNode.ts b/src/views/nodes/lineHistoryNode.ts index 0a281c5..423a3da 100644 --- a/src/views/nodes/lineHistoryNode.ts +++ b/src/views/nodes/lineHistoryNode.ts @@ -59,32 +59,6 @@ export class LineHistoryNode extends SubscribeableViewNode implements PageableVi for (const commit of blame.commits.values()) { if (!commit.isUncommitted) continue; - const file: GitFile = { - fileName: commit.fileName, - indexStatus: '?', - originalFileName: commit.originalFileName, - repoPath: this.uri.repoPath!, - status: 'M', - workingTreeStatus: '?' - }; - - const uncommitted = new GitLogCommit( - GitCommitType.LogFile, - this.uri.repoPath!, - commit.sha, - 'You', - commit.email, - commit.authorDate, - commit.committerDate, - commit.message, - commit.fileName, - [file], - 'M', - commit.originalFileName, - commit.previousSha, - commit.originalFileName || commit.fileName - ); - const firstLine = blame.lines[0]; const lastLine = blame.lines[blame.lines.length - 1]; @@ -97,15 +71,103 @@ export class LineHistoryNode extends SubscribeableViewNode implements PageableVi selection.active.character ); - children.splice( - 0, - 0, - new CommitFileNode(this.view, this, file, uncommitted, { - displayAsCommit: true, - inFileHistory: true, - selection: selection - }) - ); + const status = await Container.git.getStatusForFile(this.uri.repoPath!, this.uri.fsPath); + + const file: GitFile = { + fileName: commit.fileName, + indexStatus: status?.indexStatus ?? '?', + originalFileName: commit.originalFileName, + repoPath: this.uri.repoPath!, + status: 'M', + workingTreeStatus: status?.workingTreeStatus ?? '?' + }; + + if (status?.workingTreeStatus !== undefined && status?.indexStatus !== undefined) { + let uncommitted = new GitLogCommit( + GitCommitType.LogFile, + this.uri.repoPath!, + GitService.uncommittedStagedSha, + 'You', + commit.email, + commit.authorDate, + commit.committerDate, + commit.message, + commit.fileName, + [file], + 'M', + commit.originalFileName, + commit.previousSha, + commit.originalFileName || commit.fileName + ); + + children.splice( + 0, + 0, + new CommitFileNode(this.view, this, file, uncommitted, { + displayAsCommit: true, + inFileHistory: true, + selection: selection + }) + ); + + uncommitted = new GitLogCommit( + GitCommitType.LogFile, + this.uri.repoPath!, + GitService.uncommittedSha, + 'You', + commit.email, + commit.authorDate, + commit.committerDate, + commit.message, + commit.fileName, + [file], + 'M', + commit.originalFileName, + GitService.uncommittedStagedSha, + commit.originalFileName || commit.fileName + ); + + children.splice( + 0, + 0, + new CommitFileNode(this.view, this, file, uncommitted, { + displayAsCommit: true, + inFileHistory: true, + selection: selection + }) + ); + } else { + const uncommitted = new GitLogCommit( + GitCommitType.LogFile, + this.uri.repoPath!, + status?.workingTreeStatus !== undefined + ? GitService.uncommittedSha + : status?.indexStatus !== undefined + ? GitService.uncommittedStagedSha + : commit.sha, + 'You', + commit.email, + commit.authorDate, + commit.committerDate, + commit.message, + commit.fileName, + [file], + 'M', + commit.originalFileName, + commit.previousSha, + commit.originalFileName || commit.fileName + ); + + children.splice( + 0, + 0, + new CommitFileNode(this.view, this, file, uncommitted, { + displayAsCommit: true, + inFileHistory: true, + selection: selection + }) + ); + } break; }