From 8465f708ff0d8a0ffaf76f37afded69498761d11 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Mon, 25 Sep 2023 14:30:17 -0400 Subject: [PATCH] Fixes #2928 create new file on apply --- CHANGELOG.md | 1 + src/git/actions/commit.ts | 29 ++++++++++++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf199cb..358fdf3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ### Fixed +- Fixes [#2928](https://github.com/gitkraken/vscode-gitlens/issues/2928) - Apply Changes should create new files when needed - Fixes [#2896](https://github.com/gitkraken/vscode-gitlens/issues/2896) - Repositories view stuck in loading state - Fixes issue with "View as [List|Tree]" toggle not working in the _Commit Details_ view diff --git a/src/git/actions/commit.ts b/src/git/actions/commit.ts index d77a4e9..3393bf5 100644 --- a/src/git/actions/commit.ts +++ b/src/git/actions/commit.ts @@ -25,16 +25,31 @@ import type { GitRevisionReference } from '../models/reference'; import { getReferenceFromRevision, isUncommitted, isUncommittedStaged } from '../models/reference'; export async function applyChanges(file: string | GitFile, ref1: GitRevisionReference, ref2?: GitRevisionReference) { - // Open the working file to ensure undo will work - await openFile(file, ref1, { preserveFocus: true, preview: false }); - + let create = false; let ref = ref1.ref; - // If the file is `?` (untracked), then this must be a stash, so get the ^3 commit to access the untracked file - if (typeof file !== 'string' && file.status === '?') { - ref = `${ref}^3`; + if (typeof file !== 'string') { + // If the file is `?` (untracked), then this must be a stash, so get the ^3 commit to access the untracked file + if (file.status === '?') { + ref = `${ref}^3`; + create = true; + } else if (file.status === 'A') { + create = true; + } } - await Container.instance.git.applyChangesToWorkingFile(GitUri.fromFile(file, ref1.repoPath, ref), ref, ref2?.ref); + if (create) { + const uri = GitUri.fromFile(file, ref1.repoPath); + await Container.instance.git.applyChangesToWorkingFile(uri, ref, ref2?.ref); + await openFile(uri, { preserveFocus: true, preview: false }); + } else { + // Open the working file to ensure undo will work + await openFile(file, ref1, { preserveFocus: true, preview: false }); + await Container.instance.git.applyChangesToWorkingFile( + GitUri.fromFile(file, ref1.repoPath, ref), + ref, + ref2?.ref, + ); + } } export async function copyIdToClipboard(ref: { repoPath: string; ref: string } | GitCommit) {