Skip to content

Commit 94f4fcc

Browse files
committed
Sync the final branch ref handling into the advisory-link PR
2 parents b189619 + 634b188 commit 94f4fcc

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
@@ -139,13 +139,21 @@ def test_qualified_default_branch_uses_the_short_branch_name(
139139
assert _flags(params) == (True, True)
140140

141141

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

147155
params = _scan_params(cli_runtime)
148-
assert params.branch == "main"
156+
assert params.branch == expected_branch
149157
assert params.make_default_branch is False
150158

151159

0 commit comments

Comments
 (0)