Skip to content

Instantly share code, notes, and snippets.

@felixge
Created August 13, 2010 09:47
Show Gist options
  • Save felixge/522627 to your computer and use it in GitHub Desktop.
Save felixge/522627 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
var COMMIT_FILE = '/Users/felix/pp/commits.csv';
var exec = require('child_process').exec,
fs = require('fs');
exec('git log -1 HEAD --shortstat --pretty=format:"%ai%n%h%n%s"', function (err, stdout, stder) {
if (err) {
throw err;
}
var commitRow = stdout.match(/([^\n]+)\n([^\n]+)\n([^\n]+)\n.+?([\d]+) insertions.+?([\d]+) deletions/).slice(1);
// remove time zone information, makes it easier for certain tools to parse the column as a date
commitRow[0] = commitRow[0].replace(/ \+[\d]+$/, '');
// escape subject for CSV
commitRow[1] = commitRow[1].replace('"', '""');
// add the project directory
commitRow.push(process.cwd());
// write the commit log entry to disc
var commitFile = fs.createWriteStream(COMMIT_FILE, {flags: 'a'});
commitFile.write(commitRow.join(',')+'\n');
commitFile.end();
console.log('Recorded git loc entry in: '+COMMIT_FILE);
});
@m1m1k
Copy link

m1m1k commented Aug 14, 2015

Thanks, this is helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment