diff --git a/.lintstagedrc.json b/.lintstagedrc.json index 565435dcc..e52d997e7 100644 --- a/.lintstagedrc.json +++ b/.lintstagedrc.json @@ -1,5 +1,5 @@ { - "*.{js,json,md}": ["prettier --write", "git add"], - "*.js": ["npm run lint:base --fix", "git add"], - ".*{rc, json}": ["jsonlint --in-place", "git add"] + "*.{js,json,md}": ["prettier --write"], + "*.js": ["npm run lint:base --fix"], + ".*{rc, json}": ["jsonlint --in-place"] } diff --git a/lib/gitWorkflow.js b/lib/gitWorkflow.js index b6ad63e93..5a1020059 100644 --- a/lib/gitWorkflow.js +++ b/lib/gitWorkflow.js @@ -117,16 +117,25 @@ class GitWorkflow { } /** - * Applies back unstaged changes that have been hidden in the stash. + * Applies back task modifications, and unstaged changes hidden in the stash. * In case of a merge-conflict retry with 3-way merge. * * @param {Object} [options] * @returns {Promise} */ - async restoreUnstagedChanges() { - debug('Restoring unstaged changes...') + async applyModifications() { + let modifiedFiles = await this.execGit(['ls-files', '--modified']) + if (modifiedFiles) { + modifiedFiles = modifiedFiles.split('\n') + debug('Detected files modified by tasks:') + debug(modifiedFiles) + debug('Adding files to index...') + await this.execGit(['add', modifiedFiles]) + debug('Done adding files to index!') + } if (this.unstagedDiff) { + debug('Restoring unstaged changes...') try { await this.execGit(gitApplyArgs, { input: `${this.unstagedDiff}\n` }) } catch (error) { @@ -143,8 +152,8 @@ class GitWorkflow { throw new Error('Unstaged changes could not be restored due to a merge conflict!') } } + debug('Done restoring unstaged changes!') } - debug('Done restoring unstaged changes!') if (this.untrackedFiles) { debug('Restoring untracked files...') diff --git a/lib/runAll.js b/lib/runAll.js index acfcfb90c..2704ed0e7 100644 --- a/lib/runAll.js +++ b/lib/runAll.js @@ -115,9 +115,9 @@ module.exports = async function runAll( task: () => new Listr(tasks, { ...listrOptions, concurrent: true, exitOnError: false }) }, { - title: 'Restoring unstaged changes...', + title: 'Applying modifications...', skip: ctx => ctx.hasErrors && 'Skipped because of errors from tasks', - task: () => git.restoreUnstagedChanges() + task: () => git.applyModifications() }, { title: 'Reverting to original state...', diff --git a/test/__mocks__/gitWorkflow.js b/test/__mocks__/gitWorkflow.js index 7b846dd7c..212655108 100644 --- a/test/__mocks__/gitWorkflow.js +++ b/test/__mocks__/gitWorkflow.js @@ -1,6 +1,6 @@ const stub = { stashBackup: jest.fn().mockImplementation(() => Promise.resolve()), - restoreUnstagedChanges: jest.fn().mockImplementation(() => Promise.resolve()), + applyModifications: jest.fn().mockImplementation(() => Promise.resolve()), restoreOriginalState: jest.fn().mockImplementation(() => Promise.resolve()), dropBackup: jest.fn().mockImplementation(() => Promise.resolve()) } diff --git a/test/__snapshots__/runAll.spec.js.snap b/test/__snapshots__/runAll.spec.js.snap index 65f538180..130ed3b91 100644 --- a/test/__snapshots__/runAll.spec.js.snap +++ b/test/__snapshots__/runAll.spec.js.snap @@ -10,8 +10,8 @@ LOG echo \\"sample\\" [started] LOG echo \\"sample\\" [completed] LOG Running tasks for *.js [completed] LOG Running tasks... [completed] -LOG Restoring unstaged changes... [started] -LOG Restoring unstaged changes... [completed] +LOG Applying modifications... [started] +LOG Applying modifications... [completed] LOG Cleaning up... [started] LOG Cleaning up... [completed]" `; @@ -33,8 +33,8 @@ LOG → LOG Running tasks for *.js [failed] LOG → LOG Running tasks... [failed] -LOG Restoring unstaged changes... [started] -LOG Restoring unstaged changes... [skipped] +LOG Applying modifications... [started] +LOG Applying modifications... [skipped] LOG → Skipped because of errors from tasks LOG Reverting to original state... [started] LOG Reverting to original state... [completed] @@ -64,8 +64,8 @@ LOG → LOG Running tasks for *.js [failed] LOG → LOG Running tasks... [failed] -LOG Restoring unstaged changes... [started] -LOG Restoring unstaged changes... [skipped] +LOG Applying modifications... [started] +LOG Applying modifications... [skipped] LOG → Skipped because of errors from tasks LOG Reverting to original state... [started] LOG Reverting to original state... [completed] @@ -103,8 +103,8 @@ LOG echo \\"sample\\" [started] LOG echo \\"sample\\" [completed] LOG Running tasks for *.js [completed] LOG Running tasks... [completed] -LOG Restoring unstaged changes... [started] -LOG Restoring unstaged changes... [completed] +LOG Applying modifications... [started] +LOG Applying modifications... [completed] LOG Cleaning up... [started] LOG Cleaning up... [completed]" `; diff --git a/test/runAll.unmocked.spec.js b/test/runAll.unmocked.spec.js index 0dec32507..8c693e6ad 100644 --- a/test/runAll.unmocked.spec.js +++ b/test/runAll.unmocked.spec.js @@ -26,7 +26,7 @@ const testJsFileUnfixable = `const obj = { 'foo': 'bar' ` -const fixJsConfig = { config: { '*.js': ['prettier --write', 'git add'] } } +const fixJsConfig = { config: { '*.js': 'prettier --write' } } const isAppveyor = !!process.env.APPVEYOR const osTmpDir = isAppveyor ? 'C:\\projects' : fs.realpathSync(os.tmpdir())