diff --git a/src/git/actions/commit.ts b/src/git/actions/commit.ts index b53abc9..0771146 100644 --- a/src/git/actions/commit.ts +++ b/src/git/actions/commit.ts @@ -202,8 +202,10 @@ export async function openChanges( commitOrRefs: GitCommit | { repoPath: string; ref1: string; ref2: string }, options?: TextDocumentShowOptions, ) { + const isArgCommit = isCommit(commitOrRefs); + if (typeof file === 'string') { - if (!isCommit(commitOrRefs)) throw new Error('Invalid arguments'); + if (!isArgCommit) throw new Error('Invalid arguments'); const f = await commitOrRefs.findFile(file); if (f == null) throw new Error('Invalid arguments'); @@ -213,17 +215,17 @@ export async function openChanges( options = { preserveFocus: true, preview: false, ...options }; - if (file.status === 'A') { - if (!isCommit(commitOrRefs)) return; - + if (file.status === 'A' && isArgCommit) { const commit = await commitOrRefs.getCommitForFile(file); void executeCommand(Commands.DiffWithPrevious, { commit: commit, showOptions: options, }); + + return; } - const refs = isCommit(commitOrRefs) + const refs = isArgCommit ? { repoPath: commitOrRefs.repoPath, // Don't need to worry about verifying the previous sha, as the DiffWith command will