diff --git a/lib/gitWorkflow.js b/lib/gitWorkflow.js index f7dea4f64..ecc6502bc 100644 --- a/lib/gitWorkflow.js +++ b/lib/gitWorkflow.js @@ -68,14 +68,16 @@ class GitWorkflow { debug('Done backing up merge state!') } - // Save stash of entire original state, including unstaged and untracked changes. - // This should remove all changes from the index. - // The `--keep-index` option cannot be used since it resurrects deleted files on - // git versions before v2.23.0 (https://github.com/git/git/blob/master/Documentation/RelNotes/2.23.0.txt#L322) + // Get stash of entire original state, including unstaged changes await this.execGit(['stash', 'save', '--quiet', '--include-untracked', STASH]) - // Apply only the staged changes back to index + // 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()]) - // Checkout everything just in case there are unstaged files left behind. + // 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