From abbeed40708fe01ce72775a56d1025c8746a76a6 Mon Sep 17 00:00:00 2001 From: Luca Castoro Date: Tue, 3 Jul 2018 17:02:57 +0200 Subject: [PATCH 1/2] git bc-show-eligible BRANCH parameter is now optional, defaults to 'master'. Now git bc-show-eligible can be called from repo's subfolders. --- bin/git-bc-show-eligible | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/bin/git-bc-show-eligible b/bin/git-bc-show-eligible index 8f09cee..2252c58 100755 --- a/bin/git-bc-show-eligible +++ b/bin/git-bc-show-eligible @@ -1,10 +1,19 @@ #!/usr/bin/env python -import pygit2 -import re +import subprocess import argparse +import pygit2 import sys +import re +def find_toplevel(): + try: + return subprocess.check_output( + ['git', 'rev-parse', '--show-toplevel'], + stderr=subprocess.PIPE + ).rstrip() + except subprocess.CalledProcessError: + return None def find_unpicked(repo, from_commit, to_commit, since_commit, show_all): base_id = repo.merge_base(from_commit.id, to_commit.id) @@ -40,14 +49,21 @@ def find_unpicked(repo, from_commit, to_commit, since_commit, show_all): break parser = argparse.ArgumentParser(description='Show commits, eligible for cherry-picking') -parser.add_argument('branch', metavar='BRANCH', help='Name for the branch to check against') +parser.add_argument('branch', metavar='BRANCH', help='Name for the branch to check against', + default='master', nargs='?') parser.add_argument('target_branch', metavar='TARGET_BRANCH', help='Name for the target branch', default='HEAD', nargs='?') parser.add_argument('--since', metavar='COMMIT', help='Start checking since specified commit') parser.add_argument('--all', action='store_true', help='Show commits from all users') +top = find_toplevel() + +if not top: + print('The current folder is not a valid git repository') + sys.exit(1) + args = parser.parse_args() -repo = pygit2.Repository('.') +repo = pygit2.Repository(top) try: from_commit = repo.revparse_single(args.branch) From e5c3a6bb922363a3c16bbbf72fb75eff64808ec6 Mon Sep 17 00:00:00 2001 From: Luca Castoro <13522333+lucacastoro@users.noreply.github.com> Date: Tue, 3 Jul 2018 18:37:49 +0200 Subject: [PATCH 2/2] **BRANCH** defaults to `origin/master` instead of `origin` --- bin/git-bc-show-eligible | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/git-bc-show-eligible b/bin/git-bc-show-eligible index 2252c58..33d27c7 100755 --- a/bin/git-bc-show-eligible +++ b/bin/git-bc-show-eligible @@ -50,7 +50,7 @@ def find_unpicked(repo, from_commit, to_commit, since_commit, show_all): parser = argparse.ArgumentParser(description='Show commits, eligible for cherry-picking') parser.add_argument('branch', metavar='BRANCH', help='Name for the branch to check against', - default='master', nargs='?') + default='origin/master', nargs='?') parser.add_argument('target_branch', metavar='TARGET_BRANCH', help='Name for the target branch', default='HEAD', nargs='?') parser.add_argument('--since', metavar='COMMIT', help='Start checking since specified commit')