Skip to content

Commit

Permalink
fix: workaround for stashing deleted files for git < 2.23
Browse files Browse the repository at this point in the history
  • Loading branch information
iiroj committed Nov 14, 2019
1 parent 9c33515 commit 1a87333
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/gitWorkflow.js
Expand Up @@ -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!')
Expand Down

0 comments on commit 1a87333

Please sign in to comment.