Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: --no-restage flag for skipping re-stage step in staged mode (#39) #40

Merged
merged 4 commits into from Sep 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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