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
25 changes: 22 additions & 3 deletions src/stack_pr/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -884,9 +884,28 @@ def deduce_base(args: CommonArgs) -> CommonArgs:
"""
if args.base:
return args
deduced_base = get_command_output(
["git", "merge-base", args.head, f"{args.remote}/{args.target}"]
)

# Check if the remote branch exists
remote_branch = f"{args.remote}/{args.target}"
try:
run_shell_command(["git", "rev-parse", "--verify", remote_branch], quiet=True)
except SubprocessError:
error(
f"Remote branch '{remote_branch}' does not exist. Please ensure the branch is available."
)
sys.exit(1)

# Attempt to find the merge base
try:
deduced_base = get_command_output(
["git", "merge-base", args.head, remote_branch]
)
except SubprocessError:
error(
f"Failed to find a merge base between '{args.head}' and '{remote_branch}'."
)
sys.exit(1)

return CommonArgs(
deduced_base,
args.head,
Expand Down