Skip to content

Commit a0a5ea8

Browse files
committed
Keep incomplete branch refs from falling back to the default branch
1 parent 3b25602 commit a0a5ea8

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

‎socketsecurity/core/git_interface.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ def scan_branch_name(self, branch: str) -> str:
515515
"""Resolve a qualified branch ref to the branch name used by scan requests."""
516516
for prefix in ("refs/heads/", "refs/remotes/origin/"):
517517
if branch.startswith(prefix):
518-
return branch.removeprefix(prefix)
518+
return branch.removeprefix(prefix) or branch
519519

520520
if not branch.startswith("origin/"):
521521
return branch

‎tests/core/test_default_branch_flags.py‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,21 @@ def test_qualified_default_branch_uses_the_short_branch_name(
138138
assert _flags(params) == (True, True)
139139

140140

141-
def test_qualified_scan_of_another_branch_does_not_mark_it_as_default(
142-
cli_runtime, github_dispatch_on_develop # noqa: F811
141+
@pytest.mark.parametrize(
142+
"branch, expected_branch",
143+
[
144+
("refs/heads/main", "main"),
145+
("refs/heads/", "refs/heads/"),
146+
("refs/remotes/origin/", "refs/remotes/origin/"),
147+
],
148+
)
149+
def test_qualified_ref_must_name_the_default_branch_to_promote(
150+
cli_runtime, github_dispatch_on_develop, branch, expected_branch # noqa: F811
143151
):
144-
assert github_dispatch_on_develop(["--branch", "refs/heads/main"]) == 0
152+
assert github_dispatch_on_develop(["--branch", branch]) == 0
145153

146154
params = _scan_params(cli_runtime)
147-
assert params.branch == "main"
155+
assert params.branch == expected_branch
148156
assert params.make_default_branch is False
149157

150158

0 commit comments

Comments
 (0)