fix: use spawn instead of exec for 'git log' to avoid maxBuffer err
This commit is contained in:
		
							parent
							
								
									d7f5d19073
								
							
						
					
					
						commit
						73138f8a8f
					
				| @ -36,6 +36,7 @@ | ||||
|     "coveralls": "^2.11.4", | ||||
|     "cz-conventional-changelog": "^1.1.4", | ||||
|     "mkdirp": "^0.5.1", | ||||
|     "mock-spawn": "^0.2.6", | ||||
|     "nixt": "^0.5.0", | ||||
|     "nock": "^8.0.0", | ||||
|     "npm-registry-couchapp": "^2.6.11", | ||||
|  | ||||
| @ -1,4 +1,4 @@ | ||||
| var exec = require('child_process').exec | ||||
| var childProcess = require('child_process') | ||||
| 
 | ||||
| var log = require('npmlog') | ||||
| 
 | ||||
| @ -13,7 +13,7 @@ module.exports = function (config, cb) { | ||||
| 
 | ||||
|   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 branches | ||||
| 
 | ||||
| @ -47,28 +47,33 @@ module.exports = function (config, cb) { | ||||
|   }) | ||||
| 
 | ||||
|   function extract () { | ||||
|     exec( | ||||
|       'git log -E --format=%H==SPLIT==%B==END== ' + range, | ||||
|       { | ||||
|         maxBuffer: 1024 * 1024 // 1MB instead of 220KB (issue #286)
 | ||||
|       }, | ||||
|       function (err, stdout) { | ||||
|         if (err) return cb(err) | ||||
|     var child = childProcess.spawn('git', ['log', '-E', '--format=%H==SPLIT==%B==END==', range]) | ||||
|     var stdout = '' | ||||
|     var 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) { | ||||
|           return !!raw.trim() | ||||
|         }) | ||||
| 
 | ||||
|         .map(function (raw) { | ||||
|           var data = raw.split('==SPLIT==') | ||||
|           return { | ||||
|             hash: data[0], | ||||
|             message: data[1] | ||||
|           } | ||||
|         })) | ||||
|       } | ||||
|     ) | ||||
|         }) | ||||
|       ) | ||||
|     }) | ||||
|   } | ||||
| } | ||||
|  | ||||
| @ -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 = [ | ||||
|   'hash-one==SPLIT==commit-one==END==\n', | ||||
|   'hash-two==SPLIT==commit-two==END==\n' | ||||
| @ -12,13 +24,7 @@ module.exports = { | ||||
|       if (/notinhistory/.test(command)) return cb(new Error()) | ||||
|       return cb(null, 'whatever\nmaster\n') | ||||
|     } | ||||
| 
 | ||||
|     cb( | ||||
|       null, | ||||
|       /\.\.HEAD/.test(command) | ||||
|         ? rawCommits[0] | ||||
|         : rawCommits.join() | ||||
|     ) | ||||
|   }, | ||||
|   spawn: mockSpawn, | ||||
|   '@noCallThru': true | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user