forked from FuegoFro/GitChildBranchHelpers
/
arc_diff_against_parent.py
43 lines (36 loc) · 1.6 KB
/
arc_diff_against_parent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import argparse
from argparse import ArgumentParser, Namespace
from git_helpers import arc, fail_if_not_rebased, get_current_branch
from subcommands.git_rebase_children import get_branch_tracker
from subcommands.base_command import BaseCommand
class ArcDiffAgainstParent(BaseCommand):
def get_name(self):
# type: () -> str
return 'arc-diff'
def get_short_description(self):
# type: () -> str
return '`arc diff` this branch against its parent branch'
def inflate_subcommand_parser(self, parser):
# type: (ArgumentParser) -> None
parser.add_argument(
'arc_diff_args',
nargs=argparse.REMAINDER,
help="arguments to pass through to `arc diff`. You may need to add '--' before "
"them if the the first arg to pass through starts with '-'.",
)
def run_command(self, args):
# type: (Namespace) -> None
extra_arc_diff_options = args.arc_diff_args
if extra_arc_diff_options:
# If the first extra arg starts with "-", "--" must also have been passed, and
# argparse doesn't remove it for us
if extra_arc_diff_options[0] == "--":
del extra_arc_diff_options[0]
extra_args = " " + " ".join(extra_arc_diff_options)
else:
extra_args = ""
current_branch = get_current_branch()
with get_branch_tracker() as tracker:
parent = tracker.parent_for_child(current_branch)
fail_if_not_rebased(current_branch, parent, tracker)
arc("diff {}{}".format(parent, extra_args))