Skip to content

Commit 420fdec

Browse files
timdouglasazz
authored andcommitted
feat: add --branch argument (#15)
* accept an optional branch parameter for merge-base * accept branch option and pass to getSinceRevision * document --branch * fix readme changes
1 parent c58d413 commit 420fdec

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ In `package.json`'s `"scripts"` section, add:
7272

7373
Pre-commit mode. Under this flag only staged files will be formatted, and they will be re-staged after formatting.
7474

75+
### `--branch`
76+
77+
When not in `staged` pre-commit mode, use this flag to compare changes with the specified branch. Defaults to `master` branch.
78+
7579
<!-- Undocumented = Unsupported :D
7680
7781
### `--config`
@@ -89,4 +93,3 @@ For example `pretty-quick --since HEAD` will format only staged files.
8993
## Configuration and Ignore Files
9094

9195
`pretty-quick` will respect your [`.prettierrc`](https://prettier.io/docs/en/configuration) and [`.prettierignore`](https://prettier.io/docs/en/ignore#ignoring-files) files, so there's no additional setup required. Configuration files will be found by searching up the file system. `.prettierignore` files are only found from the working directory that the command was executed from.
92-

src/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default (
99
config,
1010
since,
1111
staged,
12+
branch,
1213
onFoundSinceRevision,
1314
onFoundChangedFiles,
1415
onWriteFile,
@@ -20,7 +21,7 @@ export default (
2021
}
2122
const directory = scm.rootDirectory;
2223

23-
const revision = since || scm.getSinceRevision(directory, { staged });
24+
const revision = since || scm.getSinceRevision(directory, { staged, branch });
2425

2526
onFoundSinceRevision && onFoundSinceRevision(scm.name, revision);
2627

src/scms/git.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@ const runGit = (directory, args) =>
1818

1919
const getLines = execaResult => execaResult.stdout.split('\n');
2020

21-
export const getSinceRevision = (directory, { staged }) => {
21+
export const getSinceRevision = (directory, { staged, branch }) => {
2222
try {
2323
const revision = staged
2424
? 'HEAD'
25-
: runGit(directory, ['merge-base', 'HEAD', 'master']).stdout.trim();
25+
: runGit(directory, [
26+
'merge-base',
27+
'HEAD',
28+
branch || 'master',
29+
]).stdout.trim();
2630
return runGit(directory, ['rev-parse', '--short', revision]).stdout.trim();
2731
} catch (error) {
2832
if (

0 commit comments

Comments
 (0)