Skip to content

Commit

Permalink
feat: --no-restage flag for skipping re-stage step in staged mode (#39)…
Browse files Browse the repository at this point in the history
… (#40)
  • Loading branch information
benwiley4000 authored and azz committed Sep 19, 2018
1 parent ea58162 commit 230d03f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -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.
Expand Down
18 changes: 17 additions & 1 deletion src/__tests__/scm-git.test.js
Expand Up @@ -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'], {
Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Expand Up @@ -9,6 +9,7 @@ export default (
config,
since,
staged,
restage = true,
branch,
onFoundSinceRevision,
onFoundChangedFiles,
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 230d03f

Please sign in to comment.