Skip to content

Instantly share code, notes, and snippets.

@Dyrcona
Created June 18, 2022 17:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dyrcona/61c9f400512436a5639161c33004ac59 to your computer and use it in GitHub Desktop.
Save Dyrcona/61c9f400512436a5639161c33004ac59 to your computer and use it in GitHub Desktop.
Use this like git cherry except it outputs the log messages of commits in head that are not in upstream. It could be useful for summarinzing changes or writing release notes.
#!/usr/bin/env python3
# -*- Mode: python; coding: utf-8 -*-
# ---------------------------------------------------------------
# Copyright © 2015, 2022 Jason J.A. Stephenson <jason@sigio.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# ---------------------------------------------------------------
import subprocess, sys
def gather_args():
args = { "upstream": None, "head": None, "limit": None }
if len(sys.argv) > 1:
args["upstream"] = sys.argv[1]
if len(sys.argv) > 2:
args["head"] = sys.argv[2]
if len(sys.argv) > 3:
args["limit"] = sys.argv[3]
return args
def gather_commits(upstream=None, head=None, limit=None):
args = ["git", "cherry"]
if upstream:
args.append(upstream)
if head:
args.append(head)
if limit:
args.append(limit)
with subprocess.Popen(args, stdout=subprocess.PIPE) as git:
commits = git.stdout.read().decode('utf8').splitlines()
return commits
def get_log(commit):
with subprocess.Popen(["git", "log", "-n 1", "--pretty=fuller", commit], stdout=subprocess.PIPE) as git:
log = git.stdout.read().decode('utf8')
return log
def main():
cherryArgs = gather_args()
for cherry in gather_commits(**cherryArgs):
if cherry.startswith('+ '):
print(get_log(cherry[2:42]))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment