Created
August 13, 2010 09:47
-
-
Save felixge/522627 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, this is helpful!