fix: use spawn instead of exec for 'git log' to avoid maxBuffer err

This commit is contained in:
Ben Gummer 2016-11-25 10:21:56 +11:00 committed by Stephan Bönnemann
parent d7f5d19073
commit 73138f8a8f
3 changed files with 33 additions and 21 deletions

View File

@ -36,6 +36,7 @@
"coveralls": "^2.11.4", "coveralls": "^2.11.4",
"cz-conventional-changelog": "^1.1.4", "cz-conventional-changelog": "^1.1.4",
"mkdirp": "^0.5.1", "mkdirp": "^0.5.1",
"mock-spawn": "^0.2.6",
"nixt": "^0.5.0", "nixt": "^0.5.0",
"nock": "^8.0.0", "nock": "^8.0.0",
"npm-registry-couchapp": "^2.6.11", "npm-registry-couchapp": "^2.6.11",

View File

@ -1,4 +1,4 @@
var exec = require('child_process').exec var childProcess = require('child_process')
var log = require('npmlog') var log = require('npmlog')
@ -13,7 +13,7 @@ module.exports = function (config, cb) {
if (!from) return extract() if (!from) return extract()
exec('git branch --no-color --contains ' + from, function (err, stdout) { childProcess.exec('git branch --no-color --contains ' + from, function (err, stdout) {
var inHistory = false var inHistory = false
var branches var branches
@ -47,28 +47,33 @@ module.exports = function (config, cb) {
}) })
function extract () { function extract () {
exec( var child = childProcess.spawn('git', ['log', '-E', '--format=%H==SPLIT==%B==END==', range])
'git log -E --format=%H==SPLIT==%B==END== ' + range, var stdout = ''
{ var err = ''
maxBuffer: 1024 * 1024 // 1MB instead of 220KB (issue #286)
},
function (err, stdout) {
if (err) return cb(err)
cb(null, String(stdout).split('==END==\n') child.stdout.on('data', function (data) {
stdout += data
})
child.stderr.on('data', function (data) {
err += data
})
child.on('close', function (code) {
if (err || code) return cb(err)
cb(null, String(stdout).split('==END==\n')
.filter(function (raw) { .filter(function (raw) {
return !!raw.trim() return !!raw.trim()
}) })
.map(function (raw) { .map(function (raw) {
var data = raw.split('==SPLIT==') var data = raw.split('==SPLIT==')
return { return {
hash: data[0], hash: data[0],
message: data[1] message: data[1]
} }
})) })
} )
) })
} }
} }

View File

@ -1,3 +1,15 @@
var mockSpawn = require('mock-spawn')()
mockSpawn.setStrategy(function (command, args, opts) {
return function (cb) {
this.stdout.write(
/\.\.HEAD/.test(args.join(' '))
? rawCommits[0]
: rawCommits.join()
)
cb(0)
}
})
const rawCommits = [ const rawCommits = [
'hash-one==SPLIT==commit-one==END==\n', 'hash-one==SPLIT==commit-one==END==\n',
'hash-two==SPLIT==commit-two==END==\n' 'hash-two==SPLIT==commit-two==END==\n'
@ -12,13 +24,7 @@ module.exports = {
if (/notinhistory/.test(command)) return cb(new Error()) if (/notinhistory/.test(command)) return cb(new Error())
return cb(null, 'whatever\nmaster\n') return cb(null, 'whatever\nmaster\n')
} }
cb(
null,
/\.\.HEAD/.test(command)
? rawCommits[0]
: rawCommits.join()
)
}, },
spawn: mockSpawn,
'@noCallThru': true '@noCallThru': true
} }