From 1a87333f9ee0704b3bb332bf5fbc11dbd25f7821 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iiro=20J=C3=A4ppinen?= Date: Wed, 2 Oct 2019 06:33:39 +0300 Subject: [PATCH] fix: workaround for stashing deleted files for git < 2.23 --- lib/gitWorkflow.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/gitWorkflow.js b/lib/gitWorkflow.js index 66e6c3072..b6ad63e93 100644 --- a/lib/gitWorkflow.js +++ b/lib/gitWorkflow.js @@ -92,18 +92,25 @@ class GitWorkflow { } // Get stash of entire original state, including unstaged changes - // Keep index so that tasks only work on those files - await this.execGit(['stash', 'save', '--quiet', '--include-untracked', '--keep-index', STASH]) + await this.execGit(['stash', 'save', '--quiet', '--include-untracked', STASH]) + // Apply index from previous stash back to enable running tasks against + // staged files only. `git stash --keep-index` cannot be used here because of + // a bug affecting deleted files. The bug has been fixed in git v2.23.0 + // See https://github.com/git/git/blob/master/Documentation/RelNotes/2.23.0.txt#L322 + await this.execGit(['stash', 'apply', '--index', await this.getBackupStash()]) + // Clear any unstaged changes since they are saved in the stash, + // and shouldn't be affected by tasks + await this.execGit(['clean', '-df']) + await this.execGit(['checkout', '.']) // Since only staged files are now present, get a diff of unstaged changes // by comparing current index against original stash, but in reverse - const original = await this.getBackupStash() this.unstagedDiff = await this.execGit([ 'diff', '--unified=0', '--no-color', '--no-ext-diff', '--patch', - original, + await this.getBackupStash(), '-R' // Show diff in reverse ]) debug('Done backing up original state!')