Parse diff response to give more meaningful data
R0.6.0 will include diff functionality, the response for which is raw output from Git. Ideally this would be parsed to give a more meaningful object than just plain text.
Hello,
Any way to retrieve the data from the diff? I can't see the files that are changed, nor the lines. My code is:
var simpleGit = require('simple-git')();
console.log(simpleGit.diff(['--stat'], function() {}));
Here is the log:
Git {
_baseDir: 'projectPath',
_runCache: [],
ChildProcess:
{ ChildProcess: { [Function: ChildProcess] super_: [Object] },
fork: [Function],
_forkChild: [Function],
exec: [Function],
execFile: [Function],
spawn: [Function],
spawnSync: [Function: spawnSync],
execFileSync: [Function],
execSync: [Function: execSync] },
Buffer:
{ [Function: Buffer]
poolSize: 8192,
from: [Function],
alloc: [Function],
allocUnsafe: [Function],
isBuffer: [Function: isBuffer],
compare: [Function: compare],
isEncoding: [Function],
concat: [Function],
byteLength: [Function: byteLength] },
_childProcess:
ChildProcess {
domain: null,
_events: { error: [Function], close: [Function: bound ] },
_eventsCount: 2,
_maxListeners: undefined,
_closesNeeded: 3,
_closesGot: 0,
connected: false,
signalCode: null,
exitCode: null,
killed: false,
spawnfile: 'git',
_handle: Process { owner: [Circular], onexit: [Function], pid: 16914 },
spawnargs: [ 'git', 'diff', '--stat' ],
pid: 16914,
stdin:
Socket {
_connecting: false,
_hadError: false,
_handle: [Object],
_parent: null,
_host: null,
_readableState: [Object],
readable: false,
domain: null,
_events: [Object],
_eventsCount: 3,
_maxListeners: undefined,
_writableState: [Object],
writable: true,
allowHalfOpen: false,
destroyed: false,
bytesRead: 0,
_bytesDispatched: 0,
_sockname: null,
_writev: null,
_pendingData: null,
_pendingEncoding: '',
server: null,
_server: null },
stdout:
Socket {
_connecting: false,
_hadError: false,
_handle: [Object],
_parent: null,
_host: null,
_readableState: [Object],
readable: true,
domain: null,
_events: [Object],
_eventsCount: 5,
_maxListeners: undefined,
_writableState: [Object],
writable: false,
allowHalfOpen: false,
destroyed: false,
bytesRead: 0,
_bytesDispatched: 0,
_sockname: null,
_writev: null,
_pendingData: null,
_pendingEncoding: '',
server: null,
_server: null },
stderr:
Socket {
_connecting: false,
_hadError: false,
_handle: [Object],
_parent: null,
_host: null,
_readableState: [Object],
readable: true,
domain: null,
_events: [Object],
_eventsCount: 5,
_maxListeners: undefined,
_writableState: [Object],
writable: false,
allowHalfOpen: false,
destroyed: false,
bytesRead: 0,
_bytesDispatched: 0,
_sockname: null,
_writev: null,
_pendingData: null,
_pendingEncoding: '',
server: null,
_server: null },
stdio: [ [Object], [Object], [Object] ] } }
@LeMiniMoine I've just added a diffSummary that parses a git diff --stat, if you need more feel free to modify the parser and submit a pull request.
Awesome!! Working like a charm. It would be even better to be able to retrieve the line changes for each files. I'm currently doing a Hackaton in London and your library is really useful.
If you don't have time today I'll try to add it but it's already better with the summary. Thanks a lot!
Hope it goes well - I'll not be able to add more today, but you can copy the format of the parser and run that outside of the library if you have a git command handy that does the line by line diff rather than just the summary.