diff --git a/src/git/models/status.ts b/src/git/models/status.ts index 79a23d7..c5ca748 100644 --- a/src/git/models/status.ts +++ b/src/git/models/status.ts @@ -1,10 +1,12 @@ 'use strict'; import { Uri } from 'vscode'; -import { GlyphChars } from '../../constants'; -import { memoize, Strings } from '../../system'; -import { GitUri } from '../gitUri'; import { GitBranch, GitTrackingState } from './branch'; +import { GlyphChars } from '../../constants'; +import { Container } from '../../container'; import { GitFile, GitFileStatus } from './file'; +import { GitUri } from '../gitUri'; +import { GitCommitType, GitLogCommit, GitRevision } from './models'; +import { memoize, Strings } from '../../system'; export interface ComputedWorkingTreeGitStatus { staged: number; @@ -224,12 +226,16 @@ export class GitStatusFile implements GitFile { public readonly originalFileName?: string, ) {} + get edited() { + return this.workingTreeStatus != null; + } + get status(): GitFileStatus { return this.indexStatus ?? this.workingTreeStatus ?? '?'; } get staged() { - return this.indexStatus !== undefined; + return this.indexStatus != null; } @memoize() @@ -253,6 +259,71 @@ export class GitStatusFile implements GitFile { return GitFile.getStatusText(this.status); } + async toPsuedoCommits(): Promise { + if (this.workingTreeStatus == null && this.indexStatus == null) return []; + + const commits = []; + + const user = await Container.git.getCurrentUser(this.repoPath); + if (this.workingTreeStatus != null && this.indexStatus != null) { + commits.push( + new GitLogCommit( + GitCommitType.LogFile, + this.repoPath, + GitRevision.uncommitted, + 'You', + user?.email ?? undefined, + new Date(), + new Date(), + '', + this.fileName, + [this], + this.status, + this.originalFileName, + GitRevision.uncommittedStaged, + this.originalFileName ?? this.fileName, + ), + new GitLogCommit( + GitCommitType.LogFile, + this.repoPath, + GitRevision.uncommittedStaged, + 'You', + user != null ? user.email : undefined, + new Date(), + new Date(), + '', + this.fileName, + [this], + this.status, + this.originalFileName, + 'HEAD', + this.originalFileName ?? this.fileName, + ), + ); + } else { + commits.push( + new GitLogCommit( + GitCommitType.LogFile, + this.repoPath, + this.workingTreeStatus != null ? GitRevision.uncommitted : GitRevision.uncommittedStaged, + 'You', + user?.email ?? undefined, + new Date(), + new Date(), + '', + this.fileName, + [this], + this.status, + this.originalFileName, + 'HEAD', + this.originalFileName ?? this.fileName, + ), + ); + } + + return commits; + } + with(changes: { indexStatus?: GitFileStatus | null; workTreeStatus?: GitFileStatus | null; diff --git a/src/views/nodes/fileHistoryNode.ts b/src/views/nodes/fileHistoryNode.ts index 167a312..e293413 100644 --- a/src/views/nodes/fileHistoryNode.ts +++ b/src/views/nodes/fileHistoryNode.ts @@ -2,9 +2,7 @@ import { Disposable, ThemeIcon, TreeItem, TreeItemCollapsibleState } from 'vscode'; import { Container } from '../../container'; import { - GitCommitType, GitLog, - GitLogCommit, GitRevision, RepositoryChange, RepositoryChangeEvent, @@ -41,89 +39,25 @@ export class FileHistoryNode extends SubscribeableViewNode implements PageableVi async getChildren(): Promise { const children: ViewNode[] = []; - if (this.uri.sha === undefined) { + if (this.uri.sha == null) { const status = await Container.git.getStatusForFile(this.uri.repoPath!, this.uri.fsPath); - 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!, - GitRevision.uncommitted, - 'You', - user !== undefined ? user.email : undefined, - new Date(), - new Date(), - '', - status.fileName, - [status], - status.status, - status.originalFileName, - GitRevision.uncommittedStaged, - 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!, - GitRevision.uncommittedStaged, - '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 { - const commit = new GitLogCommit( - GitCommitType.LogFile, - this.uri.repoPath!, - status.workingTreeStatus !== undefined - ? GitRevision.uncommitted - : GitRevision.uncommittedStaged, - '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 commits = await status?.toPsuedoCommits(); + if (commits?.length) { + children.push( + ...commits.map( + commit => + new CommitFileNode(this.view, this, status!, commit, { + displayAsCommit: true, + inFileHistory: true, + }), + ), + ); } } const log = await this.getLog(); - if (log !== undefined) { + if (log != null) { children.push( ...insertDateMarkers( Iterables.map( diff --git a/src/views/nodes/lineHistoryNode.ts b/src/views/nodes/lineHistoryNode.ts index 840f200..9acc4d3 100644 --- a/src/views/nodes/lineHistoryNode.ts +++ b/src/views/nodes/lineHistoryNode.ts @@ -52,7 +52,7 @@ export class LineHistoryNode extends SubscribeableViewNode implements PageableVi let selection = this.selection; - if (this.uri.sha === undefined) { + if (this.uri.sha == null) { // Check for any uncommitted changes in the range const blame = this._editorContents ? await Container.git.getBlameForRangeContents(this.uri, selection, this._editorContents)