Skip to content

Commit

Permalink
fix: retry failing apply with 3-way merge
Browse files Browse the repository at this point in the history
  • Loading branch information
iiroj committed Nov 14, 2019
1 parent d843d07 commit 76cb08f
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/gitWorkflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ async function stashBackup(options) {
debug('Done backing up original state!')
}

const gitApplyArgs = ['apply', '-v', '--whitespace=nowarn', '--recount', '--unidiff-zero']

/**
* Resets everything and applies back unstaged and staged changes,
* possibly with modifications by tasks
Expand All @@ -56,10 +58,15 @@ async function restoreUnstagedChanges(options) {
debug('Restoring unstaged changes...')

if (unstagedDiff) {
await execGit(['apply', '-v', '--whitespace=nowarn', '--recount', '--unidiff-zero'], {
...options,
input: `${unstagedDiff}\n`
})
try {
await execGit(gitApplyArgs, { ...options, input: `${unstagedDiff}\n` })
} catch (error) {
debug('Error when restoring changes:')
debug(error)
debug('Retrying with 3-way merge')
// Retry with `--3way` if normal apply fails
await execGit([...gitApplyArgs, '--3way'], { ...options, input: `${unstagedDiff}\n` })
}
}

debug('Done restoring unstaged changes!')
Expand Down

0 comments on commit 76cb08f

Please sign in to comment.