UNPKG

1.02 kBJavaScriptView Raw
1var la = require('lazy-ass')
2var is = require('check-more-types')
3var exec = require('./exec')
4var debug = require('debug')('ggit')
5
6var parsers = require('./parse-git-log')
7la(is.fn(parsers.parseOneLineLog), 'missing single line parser', parsers)
8la(is.fn(parsers.parseCommitLog), 'missing full log parser', parsers)
9
10// returns a promise
11function 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
33module.exports = getLog
34
35if (!module.parent) {
36 getLog({ n: 5 }).then(console.log, console.error)
37}