Skip to content

Instantly share code, notes, and snippets.

@jclulow
Created February 13, 2012 09:11
Show Gist options
  • Save jclulow/1815289 to your computer and use it in GitHub Desktop.
Save jclulow/1815289 to your computer and use it in GitHub Desktop.
git outgoing
#!/usr/bin/env node
var execFile = require('child_process').execFile;
var log = console.log;
var exit = process.exit;
execFile('git', ['whatchanged', 'origin/master..'], function(err, stdout, stderr) {
if (err) {
log('ERROR: ' + stderr);
exit(1);
}
var lines = stdout.split('\n');
var types = {
M: 'modified',
A: 'added',
D: 'deleted'
};
var lists = {};
var state = 0;
for (var i = 0; i < lines.length; i++) {
var line = lines[i];
switch (state) {
case 0: // pre-description */
if (!line.trim()) {
state = 1;
log('\ndescription:');
} else {
log(line);
}
break;
case 1: // description
if (!line.trim()) {
state = 2;
log();
} else {
log('\t' + line.trim());
}
break;
case 2:
if (line) {
var m = line.match(/^:[0-9]+ +[0-9]+ +[a-z0-9]+\.\.\. +[a-z0-9]+\.\.\. +([A-Z])[\t ]+(.*)$/);
if (m) {
var type = types[m[1]];
var file = m[2];
if (!type) {
log('ERROR: unknown type character \'' + m[1] +'\'');
exit(2);
}
lists[type] = lists[type] || [];
lists[type].push(file);
} else {
log('ERROR: unknown line format: ' + line);
exit(3);
}
}
break;
}
}
if (state !== 2) {
log('ERROR: did not find all expected sections');
exit(4);
}
for (key in types) {
var heading = types[key];
var list = lists[heading];
if (!list) continue;
log(heading + ':');
for (var k = 0; k < list.length; k++) {
log(' ' + list[k]);
}
log();
}
});
$ git outgoing
commit 6997d1f03b6ee3427a242970a53b6814b6252605
Author: Joshua M. Clulow <josh@sysmgr.org>
Date: Tue Nov 29 10:20:35 2011 +1100
description:
1815 sed -i "" no longer works
modified:
usr/src/cmd/sed/main.c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment