Skip to content

Commit 2485609

Browse files
committed
fix: reject binary files when executing a saved plan too
A dry-run plan saved before this check existed (or produced by a different version) can still carry a binary file; execute now runs validate_no_binary_files on the saved diff before validate_coverage so it stops before creating any branches.
1 parent 8470822 commit 2485609

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

pr_split/cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,7 @@ def execute(
10281028
parsed_diff = parse_diff(plan.raw_diff)
10291029

10301030
try:
1031+
validate_no_binary_files(parsed_diff)
10311032
validate_coverage(plan.groups, parsed_diff)
10321033
except PlanValidationError as exc:
10331034
console.print(f"[red]{exc}[/red]")

tests/test_cli_coverage.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,42 @@ def test_execute_missing_merge_base_sha(
523523
result = runner.invoke(app, ["execute"])
524524
assert result.exit_code != 0
525525

526+
@patch("pr_split.cli._create_branches_and_commits")
527+
@patch("pr_split.cli.check_gh_auth", return_value=True)
528+
@patch("pr_split.cli.is_worktree_clean", return_value=True)
529+
@patch("pr_split.cli.branch_exists", return_value=True)
530+
@patch("pr_split.cli.load_plan")
531+
@patch("pr_split.cli.plan_exists", return_value=True)
532+
def test_execute_rejects_saved_plan_with_binary_files(
533+
self,
534+
mock_pe: MagicMock,
535+
mock_load: MagicMock,
536+
mock_be: MagicMock,
537+
mock_clean: MagicMock,
538+
mock_auth: MagicMock,
539+
mock_create: MagicMock,
540+
) -> None:
541+
mock_plan_file = MagicMock()
542+
mock_plan_file.git_state.branches = []
543+
mock_plan_file.git_state.prs = []
544+
plan = mock_plan_file.plan
545+
plan.raw_diff = (
546+
"diff --git a/img.png b/img.png\n"
547+
"index 1111111..2222222 100644\n"
548+
"Binary files a/img.png and b/img.png differ\n"
549+
"diff --git a/a.py b/a.py\n--- a/a.py\n+++ b/a.py\n@@ -1 +1 @@\n-x\n+y\n"
550+
)
551+
plan.merge_base_sha = "abc123"
552+
plan.base_branch = "main"
553+
plan.stacked = False
554+
plan.groups = [_group("pr-1", "a", files=["a.py"])]
555+
mock_load.return_value = mock_plan_file
556+
result = runner.invoke(app, ["execute"])
557+
assert result.exit_code == 1
558+
assert "binary files" in result.output
559+
assert "img.png" in result.output
560+
mock_create.assert_not_called()
561+
526562

527563
# ---------------------------------------------------------------------------
528564
# status command

0 commit comments

Comments
 (0)