#!/usr/bin/python
# vim: filetype=python :

import os, sys
from subprocess import Popen, PIPE

def call(a):
    p = Popen(a, shell=True, stdout=PIPE)
    return p.stdout.read().strip()

if len(sys.argv) > 2:
    print 'usage: git fixup [<rev>]'
    exit(1)
elif len(sys.argv) == 2:
    rev = sys.argv[1]
else:
    rev = 'HEAD'

cmd = "git log -1 --format=%s " + rev
log = call(cmd)
if log:
    print 'fixup against "%s"' % log
    print call('git commit -m "fixup! %s"' % log)


