1 | var la = require('lazy-ass')
|
2 | var is = require('check-more-types')
|
3 | var exec = require('./exec')
|
4 | var debug = require('debug')('ggit')
|
5 |
|
6 | var parsers = require('./parse-git-log')
|
7 | la(is.fn(parsers.parseOneLineLog), 'missing single line parser', parsers)
|
8 | la(is.fn(parsers.parseCommitLog), 'missing full log parser', parsers)
|
9 |
|
10 |
|
11 | function getLog (opts) {
|
12 | opts = opts || {}
|
13 |
|
14 | var cmd = opts.full ? 'git log --pretty=full' : 'git log --pretty=oneline'
|
15 | var logParser = opts.full ? parsers.parseCommitLog : parsers.parseOneLineLog
|
16 |
|
17 | if (opts.n > 0) {
|
18 | cmd += ' -n ' + opts.n
|
19 | }
|
20 | if (opts.remote && opts.branch) {
|
21 | cmd += ' ' + opts.remote + '/' + opts.branch + '..' + opts.branch
|
22 | } else if (opts.from) {
|
23 | cmd += ' ' + opts.from + '..'
|
24 | }
|
25 | if (opts.firstParent) {
|
26 | cmd += ' --first-parent ' + opts.firstParent
|
27 | }
|
28 | debug('using log cmd "%s"', cmd)
|
29 |
|
30 | return exec(cmd).then(logParser)
|
31 | }
|
32 |
|
33 | module.exports = getLog
|
34 |
|
35 | if (!module.parent) {
|
36 | getLog({ n: 5 }).then(console.log, console.error)
|
37 | }
|