|
1 | 1 | #!/usr/bin/env python
|
2 | 2 |
|
3 |
| -import pygit2 |
4 |
| -import re |
| 3 | +import subprocess |
5 | 4 | import argparse
|
| 5 | +import pygit2 |
6 | 6 | import sys
|
| 7 | +import re |
7 | 8 |
|
| 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 |
8 | 17 |
|
9 | 18 | def find_unpicked(repo, from_commit, to_commit, since_commit, show_all):
|
10 | 19 | 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):
|
40 | 49 | break
|
41 | 50 |
|
42 | 51 | 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='?') |
44 | 54 | parser.add_argument('target_branch', metavar='TARGET_BRANCH', help='Name for the target branch',
|
45 | 55 | default='HEAD', nargs='?')
|
46 | 56 | parser.add_argument('--since', metavar='COMMIT', help='Start checking since specified commit')
|
47 | 57 | parser.add_argument('--all', action='store_true', help='Show commits from all users')
|
48 | 58 |
|
| 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 | + |
49 | 65 | args = parser.parse_args()
|
50 |
| -repo = pygit2.Repository('.') |
| 66 | +repo = pygit2.Repository(top) |
51 | 67 |
|
52 | 68 | try:
|
53 | 69 | from_commit = repo.revparse_single(args.branch)
|
|
0 commit comments