diff --git a/CHANGELOG.md b/CHANGELOG.md index 7771029..0b1542c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ### Fixed +- Fixes [#2394](https://github.com/gitkraken/vscode-gitlens/issues/2394) - Work in progress file diff compares working tree with working tree, instead of working tree with head - Fixes [#2207](https://github.com/gitkraken/vscode-gitlens/issues/2207) - Error when trying to push individual commit - Fixes [#2301](https://github.com/gitkraken/vscode-gitlens/issues/2301) - Create Worktree button doesn't work in certain cases - Fixes [#2382](https://github.com/gitkraken/vscode-gitlens/issues/2382) - commits disappearing from commit details view when they shouldn't diff --git a/src/git/gitProviderService.ts b/src/git/gitProviderService.ts index ab8d10e..02d3d9b 100644 --- a/src/git/gitProviderService.ts +++ b/src/git/gitProviderService.ts @@ -2303,6 +2303,10 @@ export class GitProviderService implements Disposable { pathOrUri?: string | Uri, options?: { timeout?: number }, ) { + if (pathOrUri != null && GitRevision.isUncommittedParent(ref)) { + ref = 'HEAD'; + } + if ( !ref || ref === GitRevision.deletedOrMissing || diff --git a/src/git/models/commit.ts b/src/git/models/commit.ts index b1be31d..f7b5c67 100644 --- a/src/git/models/commit.ts +++ b/src/git/models/commit.ts @@ -173,9 +173,11 @@ export class GitCommit implements GitRevisionReference { private _resolvedPreviousSha: string | undefined; get unresolvedPreviousSha(): string { - return ( - this._resolvedPreviousSha ?? (this.file != null ? this.file.previousSha : this.parents[0]) ?? `${this.sha}^` - ); + const previousSha = + this._resolvedPreviousSha ?? + (this.file != null ? this.file.previousSha : this.parents[0]) ?? + `${this.sha}^`; + return GitRevision.isUncommittedParent(previousSha) ? 'HEAD' : previousSha; } private _etagFileSystem: number | undefined; diff --git a/src/git/models/reference.ts b/src/git/models/reference.ts index 50e995a..24a9260 100644 --- a/src/git/models/reference.ts +++ b/src/git/models/reference.ts @@ -47,6 +47,10 @@ export namespace GitRevision { return ref === uncommitted || ref === uncommittedStaged || (!exact && isMatch(uncommittedRegex, ref)); } + export function isUncommittedParent(ref: string | undefined) { + return ref === `${uncommitted}^` || ref === `${uncommittedStaged}^`; + } + export function isUncommittedStaged(ref: string | undefined, exact: boolean = false): boolean { return ref === uncommittedStaged || (!exact && isMatch(uncommittedStagedRegex, ref)); }