Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/stacky/stacky.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,14 @@ def get_real_stack_bottom() -> Optional[BranchName]: # type: ignore [return]
return candiates.pop()


def get_stack_parent_branch_name(branch: BranchName) -> str:
return "branch.{}.merge".format(branch)


def get_stack_parent_branch(branch: BranchName) -> Optional[BranchName]: # type: ignore [return]
if branch in STACK_BOTTOMS:
return None
p = run(CmdArgs(["git", "config", "branch.{}.merge".format(branch)]), check=False)
p = run(CmdArgs(["git", "config", get_stack_parent_branch_name(branch)]), check=False)
if p is not None:
p = remove_prefix(p, "refs/heads/")
if BranchName(p) == branch:
Expand Down Expand Up @@ -482,6 +486,12 @@ def load_stack_for_given_branch(
if check:
die("Branch is not in a stack: {}", branch)
return None, [b.branch for b in branches]
if branch == parent:
error("Branch {} seems to be its own parent, this is wrong", branch)
error(
f"To fix it update the config for {get_stack_parent_branch_name(branch)} by running git config {get_stack_parent_branch_name(branch)} ref/heads/<branch>"
)
die("Refusing to continue")
branch = parent

branches.append(BranchNCommit(branch, None))
Expand Down Expand Up @@ -1241,7 +1251,7 @@ def set_parent(branch: BranchName, target: Optional[BranchName], *, set_origin:
[
"git",
"config",
"branch.{}.merge".format(branch),
get_stack_parent_branch_name(branch),
"refs/heads/{}".format(target if target is not None else branch),
]
)
Expand Down