Skip to content

Instantly share code, notes, and snippets.

@Dyrcona
Created June 18, 2022 17:54
Show Gist options
  • Select an option

  • Save Dyrcona/61c9f400512436a5639161c33004ac59 to your computer and use it in GitHub Desktop.

Select an option

Save Dyrcona/61c9f400512436a5639161c33004ac59 to your computer and use it in GitHub Desktop.

Revisions

  1. Dyrcona created this gist Jun 18, 2022.
    54 changes: 54 additions & 0 deletions git-cherry-log
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    #!/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()