Skip to content

Commit

Permalink
fix: correctly leave only staged files for running tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
iiroj committed Nov 14, 2019
1 parent e58ebbf commit cfde9ca
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions lib/gitWorkflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,18 @@ class GitWorkflow {
debug('Done backing up merge state!')
}

// Get stash of entire original state, including unstaged changes
// Get diff of staged modifications. This will be applied back to the index. after stashing all changes.
// The `git stash save --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)
const stagedDiff = await this.execGit(['diff', '--cached'])

// Save stash of entire original state, including unstaged and untracked changes.
// This should remove all changes from the index.
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

// Apply staged modifications back to the index
await this.execGit([...gitApplyArgs, '--index'], { input: `${stagedDiff}\n` })

this.unstagedDiff = await this.execGit([
'diff',
'--unified=0',
Expand Down

0 comments on commit cfde9ca

Please sign in to comment.