From 0d11d32f02df1d62139a9f63b279593c9bed7fdb Mon Sep 17 00:00:00 2001 From: Aditya Khowal <108611217+AdityaKhowalGithub@users.noreply.github.com> Date: Mon, 28 Apr 2025 01:06:14 +0000 Subject: [PATCH 1/2] update deduce_base to include error handingling --- src/stack_pr/cli.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/stack_pr/cli.py b/src/stack_pr/cli.py index d068998..5c917a6 100755 --- a/src/stack_pr/cli.py +++ b/src/stack_pr/cli.py @@ -884,9 +884,24 @@ 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, From 29fbe69468e6b9b98fd22c66af11af54fb912e1a Mon Sep 17 00:00:00 2001 From: Aditya Khowal <108611217+AdityaKhowalGithub@users.noreply.github.com> Date: Fri, 16 May 2025 03:37:06 +0000 Subject: [PATCH 2/2] formatted with ruff --- src/stack_pr/cli.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/stack_pr/cli.py b/src/stack_pr/cli.py index 5c917a6..b5bbfd0 100755 --- a/src/stack_pr/cli.py +++ b/src/stack_pr/cli.py @@ -890,7 +890,9 @@ def deduce_base(args: CommonArgs) -> CommonArgs: 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.") + error( + f"Remote branch '{remote_branch}' does not exist. Please ensure the branch is available." + ) sys.exit(1) # Attempt to find the merge base @@ -899,7 +901,9 @@ def deduce_base(args: CommonArgs) -> CommonArgs: ["git", "merge-base", args.head, remote_branch] ) except SubprocessError: - error(f"Failed to find a merge base between '{args.head}' and '{remote_branch}'.") + error( + f"Failed to find a merge base between '{args.head}' and '{remote_branch}'." + ) sys.exit(1) return CommonArgs(