|
16 | 16 |
|
17 | 17 | def parser(subparsers, _): |
18 | 18 | """Adds the branch parser to the given subparsers object.""" |
19 | | - desc = 'list, create, edit or delete branches' |
| 19 | + desc = 'list, create, delete, or edit branches' |
20 | 20 | branch_parser = subparsers.add_parser( |
21 | 21 | 'branch', help=desc, description=desc.capitalize()) |
22 | | - branch_parser.add_argument( |
| 22 | + |
| 23 | + list_group = branch_parser.add_argument_group('list branches') |
| 24 | + list_group.add_argument( |
23 | 25 | '-r', '--remote', |
24 | 26 | help='list remote branches in addition to local branches', |
25 | 27 | action='store_true') |
| 28 | + list_group.add_argument( |
| 29 | + '-v', '--verbose', help='be verbose, will output the head of each branch', |
| 30 | + action='store_true') |
26 | 31 |
|
27 | | - branch_parser.add_argument( |
| 32 | + create_group = branch_parser.add_argument_group('create branches') |
| 33 | + create_group.add_argument( |
28 | 34 | '-c', '--create', nargs='+', help='create branch(es)', dest='create_b', |
29 | 35 | metavar='branch') |
30 | | - branch_parser.add_argument( |
| 36 | + create_group.add_argument( |
31 | 37 | '-dp', '--divergent-point', |
32 | 38 | help='the commit from where to \'branch out\' (only relevant if a new ' |
33 | | - 'branch is created; defaults to HEAD)', default='HEAD', |
34 | | - dest='dp') |
35 | | - branch_parser.add_argument( |
| 39 | + 'branch is created; defaults to HEAD)', dest='dp') |
| 40 | + |
| 41 | + delete_group = branch_parser.add_argument_group('delete branches') |
| 42 | + delete_group.add_argument( |
36 | 43 | '-d', '--delete', nargs='+', help='delete branch(es)', dest='delete_b', |
37 | 44 | metavar='branch') |
38 | 45 |
|
39 | | - branch_parser.add_argument( |
| 46 | + edit_group = branch_parser.add_argument_group('edit the current branch') |
| 47 | + edit_group.add_argument( |
40 | 48 | '-sh', '--set-head', help='set the head of the current branch', |
41 | 49 | dest='new_head', metavar='commit_id') |
42 | | - branch_parser.add_argument( |
| 50 | + edit_group.add_argument( |
43 | 51 | '-su', '--set-upstream', |
44 | 52 | help='set the upstream branch of the current branch', |
45 | 53 | dest='upstream_b', metavar='branch') |
46 | | - branch_parser.add_argument( |
| 54 | + edit_group.add_argument( |
47 | 55 | '-uu', '--unset-upstream', |
48 | 56 | help='unset the upstream branch of the current branch', |
49 | 57 | action='store_true') |
50 | 58 |
|
51 | | - branch_parser.add_argument( |
52 | | - '-v', '--verbose', help='be verbose, will output the head of each branch', |
53 | | - action='store_true') |
54 | 59 | branch_parser.set_defaults(func=main) |
55 | 60 |
|
56 | 61 |
|
57 | 62 | def main(args, repo): |
| 63 | + is_list = bool(args.verbose or args.remote) |
| 64 | + is_create = bool(args.create_b or args.dp) |
| 65 | + is_delete = bool(args.delete_b) |
| 66 | + is_edit = bool(args.new_head or args.upstream_b or args.unset_upstream) |
| 67 | + |
| 68 | + if is_list + is_create + is_delete + is_edit > 1: |
| 69 | + pprint.err('Invalid flag combination') |
| 70 | + pprint.err_exp( |
| 71 | + 'Can only do one of list, create, delete, or edit branches at a time') |
| 72 | + return False |
| 73 | + |
58 | 74 | ret = True |
59 | 75 | if args.create_b: |
60 | | - ret = _do_create(args.create_b, args.dp, repo) |
| 76 | + ret = _do_create(args.create_b, args.dp or 'HEAD', repo) |
61 | 77 | elif args.delete_b: |
62 | 78 | ret = _do_delete(args.delete_b, repo) |
63 | 79 | elif args.upstream_b: |
|
0 commit comments