Skip to content

Commit ff16c95

Browse files
committed
Add --format option
-s is now equal to --format=simple
1 parent 1fa5e2f commit ff16c95

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@ But the comparison isn't quite as strict, generally leading to a shorter list of
2424

2525
### Options
2626

27-
* `--simple` or `-s`: Don't print full markdown output, good for console printing without the additional fluff.
2827
* `--group` or `-g`: Group commits by prefix, this uses the part of the commit summary that is usually used in Node.js core to indicate subsystem for example. Groups are made up of numbers, letters, `,` and `-`, followed by a `:`.
2928
* `--exclude-label`: Exclude any commits from the list that come from a GitHub pull request with the given label. Multiple `--exclude-label` options may be provided, they will also be split by `,`. e.g. `--exclude-label=semver-major,meta`.
3029
* `--patch-only`: An alias for `--exclude-label=semver-major,semver-minor`.
30+
* `--format`: Dictates what formatting the output will have. Possible options are: `simple`, `sha`. The default is to print markdown-formatted output.
31+
- `simple`: Don't print full markdown output, good for console printing without the additional fluff.
32+
- `sha`: Print only the 10-character truncated commit shasums. Good for piping though additional tooling, such as `xargs git cherry-pick` for applying commits.
33+
* `--simple` or `-s`: An alias for `--format=simple`.
3134

3235
## License
3336

branch-diff.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,12 @@ function diffCollected (options, branchCommits, callback) {
100100
}
101101

102102

103-
function printCommits (list, simple) {
104-
list = list.map((commit) => commitToOutput(commit, simple, ghId))
103+
function printCommits (list, format) {
104+
if (format === 'sha') {
105+
list = list.map((commit) => `${commit.sha.substr(0, 10)}`)
106+
} else {
107+
list = list.map((commit) => commitToOutput(commit, format === 'simple', ghId))
108+
}
105109

106110
let out = list.join('\n') + '\n'
107111

@@ -129,12 +133,16 @@ if (require.main === module) {
129133
let argv = require('minimist')(process.argv.slice(2))
130134
, branch1 = argv._[0]
131135
, branch2 = argv._[1]
132-
, simple = argv.simple || argv.s
136+
, format = argv.format
133137
, group = argv.group || argv.g
134138
, endRef = argv['end-ref']
135139
, excludeLabels = []
136140
, options
137141

142+
143+
if (argv.simple || argv.s)
144+
format = 'simple'
145+
138146
if (argv['patch-only'])
139147
excludeLabels = [ 'semver-minor', 'semver-major' ]
140148
if (argv['exclude-label']) {
@@ -143,12 +151,12 @@ if (require.main === module) {
143151
excludeLabels = excludeLabels.concat(argv['exclude-label'])
144152
}
145153

146-
options = { simple, group, excludeLabels, endRef }
154+
options = { simple: format === 'simple', group, excludeLabels, endRef }
147155

148156
branchDiff(branch1, branch2, options, (err, list) => {
149157
if (err)
150158
throw err
151159

152-
printCommits(list, simple)
160+
printCommits(list, format)
153161
})
154162
}

0 commit comments

Comments
 (0)