diff --git a/oelint_adv/rule_base/rule_var_src_uri.py b/oelint_adv/rule_base/rule_var_src_uri.py index ec2de68..25cad4c 100644 --- a/oelint_adv/rule_base/rule_var_src_uri.py +++ b/oelint_adv/rule_base/rule_var_src_uri.py @@ -151,8 +151,13 @@ def __init__(self) -> None: } self._required_unless_options = { - 'git': {'branch': ['nobranch']}, - 'gitsm': {'branch': ['nobranch']}, + 'git': {'branch': ['nobranch', 'usehead']}, + 'gitsm': {'branch': ['nobranch', 'usehead']}, + } + + self._required_if_options = { + 'git': {'usehead': ['branch', 'nobranch']}, + 'gitsm': {'usehead': ['branch', 'nobranch']}, } def __analyse(self, stash: Stash, item: Variable, _input: str, _index: int) -> List[Tuple[str, int, str]]: @@ -188,6 +193,12 @@ def __analyse(self, stash: Stash, item: Variable, _input: str, _index: int) -> L 'Fetcher \'{fetcher}\' requires option \'{option}\' or any of \'{other}\' to be set'.format( fetcher=_url['scheme'], option=key, other=','.join(val_)), blockoffset=item.InFileLine) + for key, val_ in self._required_if_options.get(_url['scheme'], {}).items(): + if key in _url['options'] and not any(x in _url['options'] for x in val_): + res += self.finding(item.Origin, item.InFileLine + _index, + 'Fetcher \'{fetcher}\' option \'{option}\' requires any of \'{other}\' to be set'.format( + fetcher=_url['scheme'], option=key, other=','.join(val_)), + blockoffset=item.InFileLine) return res def check(self, _file: str, stash: Stash) -> List[Tuple[str, int, str]]: diff --git a/tests/test_class_oelint_vars_srcurireqopt.py b/tests/test_class_oelint_vars_srcurireqopt.py index 89e24e2..3e9f767 100644 --- a/tests/test_class_oelint_vars_srcurireqopt.py +++ b/tests/test_class_oelint_vars_srcurireqopt.py @@ -24,6 +24,14 @@ class TestClassOelintVarsSRCURIReqOpt(TestBaseClass): { 'oelint_adv_test.bb': 'SRC_URI += "gitsm://foo.org/gaz.git;name=foo;protocol=ssh"', + }, + { + 'oelint_adv_test.bb': + 'SRC_URI += "git://foo.org/gaz.git;protocol=ssh;usehead=1"', + }, + { + 'oelint_adv_test.bb': + 'SRC_URI += "gitsm://foo.org/gaz.git;protocol=ssh;usehead=1"', }, ], ) @@ -67,6 +75,22 @@ def test_really_bad(self, input_, id_, occurrence): 'oelint_adv_test.bb': 'SRC_URI += "gitsm://foo.org/gaz.git;name=foo;protocol=ssh;nobranch=1"', }, + { + 'oelint_adv_test.bb': + 'SRC_URI += "git://foo.org/gaz.git;name=foo;protocol=ssh;nobranch=1;usehead=1"', + }, + { + 'oelint_adv_test.bb': + 'SRC_URI += "gitsm://foo.org/gaz.git;name=foo;protocol=ssh;nobranch=1;usehead=1"', + }, + { + 'oelint_adv_test.bb': + 'SRC_URI += "git://foo.org/gaz.git;name=foo;protocol=ssh;branch=main;usehead=1"', + }, + { + 'oelint_adv_test.bb': + 'SRC_URI += "gitsm://foo.org/gaz.git;name=foo;protocol=ssh;branch=main;usehead=1"', + }, { 'oelint-adv_test.bb': '''