diff --git a/repo_resource/common.py b/repo_resource/common.py index 6148dde..9fe16f7 100644 --- a/repo_resource/common.py +++ b/repo_resource/common.py @@ -105,12 +105,24 @@ def getRevision(remote, remoteUrl, project, branch): if is_sha1(branch): return (remote + '/' + project, branch) g = git.cmd.Git() - url, revision = ( + url, revList = ( remote + '/' + project, - g.ls_remote(remoteUrl+'/'+project, branch).split()[0] + g.ls_remote(remoteUrl+'/'+project, branch).split() ) - print('{}: {}'.format(url, revision)) - return (url, revision) + + # convert revision list to revision dict: + # ['SHA1', 'refs/heads/XXXX', 'SHA1', 'refs/heads/YYYY'] + # -> {'refs/heads/XXXX': 'SHA1', 'refs/heads/YYYY': 'SHA1'} + revDict = dict([(b, a) + for a, b in zip(revList[::2], revList[1::2])]) + + if branch.startswith('refs/tags'): + rev = branch + else: + rev = 'refs/heads/' + branch + + print('{}: {}'.format(url, revDict[rev])) + return (url, revDict[rev]) except Exception as e: with redirect_stdout(sys.stderr): print('Cannot fetch project {}/{}'.format(remoteUrl, project)) diff --git a/repo_resource/test_check.py b/repo_resource/test_check.py index 7debee6..7bee074 100644 --- a/repo_resource/test_check.py +++ b/repo_resource/test_check.py @@ -92,6 +92,13 @@ def setUp(self): 'name': 'aosp_include_multiple_projects.xml' } } + self.branch_matching_source = { + 'source': { + 'url': 'https://github.com/makohoek/demo-manifests.git', + 'revision': 'main', + 'name': 'branch_matching.xml' + } + } def tearDown(self): p = common.CACHEDIR @@ -437,6 +444,16 @@ def test_include_multiple_projects_version(self): version = versions[0]['version'] self.assertEqual(version, expected_version) + def test_branch_matching(self): + data = self.branch_matching_source + instream = StringIO(json.dumps(data)) + versions = check.check(instream) + + expected_version = '' # noqa: E501 + + version = versions[0]['version'] + self.assertEqual(version, expected_version) + if __name__ == '__main__': unittest.main()