Skip to content

Instantly share code, notes, and snippets.

@dryan
Created October 11, 2012 04:23
Show Gist options
  • Save dryan/3870152 to your computer and use it in GitHub Desktop.
Save dryan/3870152 to your computer and use it in GitHub Desktop.
Shell script for formatting the output of `git whatchanged` into a simple list of commit messages
#!/usr/local/bin/python
import optparse, sys, os
try:
import git
except ImportError:
print 'You need gitpython. `pip install gitpython`'
sys.exit(os.EX_UNAVAILABLE)
parser = optparse.OptionParser()
parser.add_option('--verbose', dest = 'verbose', help = 'show author, timestamp and subject', action = "store_true", default = False)
parser.add_option('--prefix', help = 'The characters to prefix before each commit report', default = '* ')
options, args = parser.parse_args()
if len(args):
tree1 = args.pop(0)
else:
print "You must specify a git object as the first argument"
sys.exit(os.EX_NOINPUT)
if len(args):
tree2 = args.pop(0)
else:
print "You must specify a git object as the second argument"
sys.exit(os.EX_NOINPUT)
format = '--format=%s'
if options.verbose:
format = '--format=%ae <%ai>: %s'
commits = []
g = git.Git(os.getcwd())
whatchanged = g.whatchanged('%s..%s' % (tree1, tree2), format).split("\n")
for line in whatchanged:
if line.find(':') == 0:
continue
if len(line):
commits.append(line)
for commit in commits:
print '%s%s' % (options.prefix, commit)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment