diff --git a/README.md b/README.md index 66332e9..3e7db72 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,10 @@ Pre-commit mode. Under this flag only staged files will be formatted, and they w Partially staged files will not be re-staged after formatting and pretty-quick will exit with a non-zero exit code. The intent is to abort the git commit and allow the user to amend their selective staging to include formatting fixes. +### `--no-restage` (only git) + +Use with the `--staged` flag to skip re-staging files after formatting. + ### `--branch` When not in `staged` pre-commit mode, use this flag to compare changes with the specified branch. Defaults to `master` (git) / `default` (hg) branch. diff --git a/src/__tests__/scm-git.test.js b/src/__tests__/scm-git.test.js index d0c6f6e..99e4dae 100644 --- a/src/__tests__/scm-git.test.js +++ b/src/__tests__/scm-git.test.js @@ -174,7 +174,23 @@ describe('with git', () => { expect(execa.sync).toHaveBeenCalledWith('git', ['add', './raz.js'], { cwd: '/', }); - expect(execa.sync).not.toHaveBeenCalledWith('git', ['add', './foo.md'], { + expect(execa.sync).not.toHaveBeenCalledWith('git', ['add', './foo.js'], { + cwd: '/', + }); + expect(execa.sync).not.toHaveBeenCalledWith('git', ['add', './bar.md'], { + cwd: '/', + }); + }); + + test('with --staged AND --no-restage does not re-stage any files', () => { + mockGitFs(); + + prettyQuick('root', { since: 'banana', staged: true, restage: false }); + + expect(execa.sync).not.toHaveBeenCalledWith('git', ['add', './raz.js'], { + cwd: '/', + }); + expect(execa.sync).not.toHaveBeenCalledWith('git', ['add', './foo.js'], { cwd: '/', }); expect(execa.sync).not.toHaveBeenCalledWith('git', ['add', './bar.md'], { diff --git a/src/index.js b/src/index.js index 5076ca0..628fd22 100644 --- a/src/index.js +++ b/src/index.js @@ -9,6 +9,7 @@ export default ( config, since, staged, + restage = true, branch, onFoundSinceRevision, onFoundChangedFiles, @@ -46,7 +47,7 @@ export default ( config, onWriteFile: file => { onWriteFile && onWriteFile(file); - if (staged) { + if (staged && restage) { if (wasFullyStaged(file)) { scm.stageFile(directory, file); } else {