-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy patharc_land_onto_parent.py
51 lines (41 loc) · 1.97 KB
/
arc_land_onto_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
44
45
46
47
48
49
50
51
import argparse
from argparse import ArgumentParser, Namespace
from git_helpers import arc, fail_if_not_rebased, get_branch_tracker, get_current_branch
from subcommands.base_command import BaseCommand
class ArcLandOntoParent(BaseCommand):
def get_name(self) -> str:
return "arc-land"
def get_short_description(self) -> str:
return "`arc land` this branch onto its parent branch"
def inflate_subcommand_parser(self, parser: ArgumentParser) -> None:
parser.add_argument(
"arc_land_args",
nargs=argparse.REMAINDER,
help=(
"arguments to pass through to `arc land`. You may need to add '--' before "
"them if the the first arg to pass through starts with '-'."
),
)
def run_command(self, args: Namespace) -> None:
extra_arc_land_options = args.arc_land_args
if extra_arc_land_options:
# If the first extra arg starts with "-", "--" must also have been passed, and
# argparse doesn't remove it for us
if extra_arc_land_options[0] == "--":
del extra_arc_land_options[0]
extra_args = " " + " ".join(extra_arc_land_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)
if parent != "master":
should_land = input("Are you sure you want to land onto non-master branch '{}'? [y/N] ".format(parent))
should_land = should_land.lower()
if should_land not in ("y", "yes"):
print("Aborting land")
exit()
arc("land --onto {}{}".format(parent, extra_args))
# Successfully landed, replace ourselves with our parent
tracker.collapse_and_remove_parent(current_branch)