From 76cb08f6eecd68f3ae7e606216b4c5fdc1da94f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iiro=20J=C3=A4ppinen?= Date: Sun, 21 Jul 2019 15:30:15 +0300 Subject: [PATCH] fix: retry failing apply with 3-way merge --- src/gitWorkflow.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/gitWorkflow.js b/src/gitWorkflow.js index 75f34f443..08f3f29b7 100644 --- a/src/gitWorkflow.js +++ b/src/gitWorkflow.js @@ -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 @@ -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!')