Skip to content

Commit 4a029d6

Browse files
authored
Merge pull request #4 from lucacastoro/master
Minor improvements to bc-show-eligible
2 parents 2833cc4 + e5c3a6b commit 4a029d6

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

bin/git-bc-show-eligible

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
#!/usr/bin/env python
22

3-
import pygit2
4-
import re
3+
import subprocess
54
import argparse
5+
import pygit2
66
import sys
7+
import re
78

9+
def find_toplevel():
10+
try:
11+
return subprocess.check_output(
12+
['git', 'rev-parse', '--show-toplevel'],
13+
stderr=subprocess.PIPE
14+
).rstrip()
15+
except subprocess.CalledProcessError:
16+
return None
817

918
def find_unpicked(repo, from_commit, to_commit, since_commit, show_all):
1019
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):
4049
break
4150

4251
parser = argparse.ArgumentParser(description='Show commits, eligible for cherry-picking')
43-
parser.add_argument('branch', metavar='BRANCH', help='Name for the branch to check against')
52+
parser.add_argument('branch', metavar='BRANCH', help='Name for the branch to check against',
53+
default='origin/master', nargs='?')
4454
parser.add_argument('target_branch', metavar='TARGET_BRANCH', help='Name for the target branch',
4555
default='HEAD', nargs='?')
4656
parser.add_argument('--since', metavar='COMMIT', help='Start checking since specified commit')
4757
parser.add_argument('--all', action='store_true', help='Show commits from all users')
4858

59+
top = find_toplevel()
60+
61+
if not top:
62+
print('The current folder is not a valid git repository')
63+
sys.exit(1)
64+
4965
args = parser.parse_args()
50-
repo = pygit2.Repository('.')
66+
repo = pygit2.Repository(top)
5167

5268
try:
5369
from_commit = repo.revparse_single(args.branch)

0 commit comments

Comments
 (0)