diff --git a/swh/loader/git/tests/test_utils.py b/swh/loader/git/tests/test_utils.py --- a/swh/loader/git/tests/test_utils.py +++ b/swh/loader/git/tests/test_utils.py @@ -3,6 +3,8 @@ # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information +from random import shuffle + import pytest from swh.loader.git import utils @@ -28,3 +30,24 @@ timestamp = 2 ** exp with pytest.raises(ValueError, match=".*is out of range.*"): utils.check_date_time(timestamp) + + +def test_ignore_branch_name(): + branches = [ + b"HEAD", + b"refs/heads/master", + b"refs/{}", + b"refs/pull/10/head", # PR branch filtered + b"refs/pull/100/head", # PR branch filtered + b"refs/something/merge", # merge request branch filtered + b"refs/^{}", # other branch filtered + ] + + # order is not interesting + shuffle(branches) + + actual_branches = [b for b in branches if not utils.ignore_branch_name(b)] + + assert sorted(actual_branches) == sorted( + [b"HEAD", b"refs/heads/master", b"refs/{}"] + ) diff --git a/swh/loader/git/utils.py b/swh/loader/git/utils.py --- a/swh/loader/git/utils.py +++ b/swh/loader/git/utils.py @@ -83,14 +83,11 @@ def ignore_branch_name(branch_name: bytes) -> bool: """Should the git loader ignore the branch named `branch_name`?""" - if branch_name.endswith(b"^{}"): - # Peeled refs make the git protocol explode - return True - elif branch_name.startswith(b"refs/pull/") and branch_name.endswith(b"/merge"): - # We filter-out auto-merged GitHub pull requests - return True - - return False + return ( + branch_name.endswith(b"^{}") + or branch_name.startswith(b"refs/pull/") + or branch_name.endswith(b"/merge") + ) def filter_refs(refs: Dict[bytes, bytes]) -> Dict[bytes, HexBytes]: