[Notes] [Git][BuildStream/buildstream][537-mirror-fallback-does-not-work-for-git] 2 commits: tests: Add a test of the git source with submodules



Title: GitLab

Jonathan Maw pushed to branch 537-mirror-fallback-does-not-work-for-git at BuildStream / buildstream

Commits:

4 changed files:

Changes:

  • buildstream/plugins/sources/git.py
    ... ... @@ -102,6 +102,7 @@ class GitMirror(SourceFetcher):
    102 102
     
    
    103 103
             self._path = path
    
    104 104
             self._ref = ref
    
    105
    +        self._alias_override = None
    
    105 106
     
    
    106 107
         # Ensures that the mirror exists
    
    107 108
         def ensure(self, alias_override=None):
    
    ... ... @@ -163,6 +164,7 @@ class GitMirror(SourceFetcher):
    163 164
                              cwd=self.mirror)
    
    164 165
     
    
    165 166
         def fetch(self, alias_override=None):
    
    167
    +        self._alias_override = alias_override
    
    166 168
             self.ensure(alias_override)
    
    167 169
             if not self.has_ref():
    
    168 170
                 self._fetch(alias_override)
    
    ... ... @@ -294,12 +296,13 @@ class GitMirror(SourceFetcher):
    294 296
                 return None
    
    295 297
     
    
    296 298
         def get_submodule_path(self, url):
    
    299
    +        real_url = self.source.translate_url(url)
    
    297 300
             for parser, section in self._read_gitmodules():
    
    298 301
                 parsed_url = parser.get(section, 'url')
    
    299
    -            if parsed_url == url:
    
    302
    +            if parsed_url == real_url:
    
    300 303
                     return parser.get(section, 'path')
    
    301 304
     
    
    302
    -        raise SourceError("{}: No submodule found with url '{}'".format(self.source, url))
    
    305
    +        raise SourceError("{}: No submodule found with url '{}'".format(self.source, real_url))
    
    303 306
     
    
    304 307
         @property
    
    305 308
         def path(self):
    

  • tests/frontend/mirror.py
    ... ... @@ -616,3 +616,82 @@ def test_mirror_junction_from_includes(cli, tmpdir, datafiles, kind):
    616 616
         os.rename('{}.bak'.format(upstream_repo.repo), upstream_repo.repo)
    
    617 617
         result = cli.run(project=project_dir, args=['fetch', element_name])
    
    618 618
         result.assert_success()
    
    619
    +
    
    620
    +@pytest.mark.datafiles(DATA_DIR)
    
    621
    +def test_mirror_git_submodule_fetch(cli, tmpdir, datafiles):
    
    622
    +    # Test that it behaves as expected with submodules, both defined in config
    
    623
    +    # and discovered when fetching.
    
    624
    +    foo_file = os.path.join(str(datafiles), 'files', 'foo')
    
    625
    +    bar_file = os.path.join(str(datafiles), 'files', 'bar')
    
    626
    +    bin_files_path = os.path.join(str(datafiles), 'files', 'bin-files', 'usr')
    
    627
    +    dev_files_path = os.path.join(str(datafiles), 'files', 'dev-files', 'usr')
    
    628
    +    mirror_dir = os.path.join(str(datafiles), 'mirror')
    
    629
    +
    
    630
    +    defined_subrepo = create_repo('git', str(tmpdir), 'defined_subrepo')
    
    631
    +    defined_mirror_ref = defined_subrepo.create(bin_files_path)
    
    632
    +    defined_mirror = defined_subrepo.copy(mirror_dir)
    
    633
    +    defined_subref = defined_subrepo.add_file(foo_file)
    
    634
    +
    
    635
    +    found_subrepo = create_repo('git', str(tmpdir), 'found_subrepo')
    
    636
    +    found_subref = found_subrepo.create(dev_files_path)
    
    637
    +
    
    638
    +    main_repo = create_repo('git', str(tmpdir))
    
    639
    +    main_mirror_ref = main_repo.create(bin_files_path)
    
    640
    +    main_repo.add_submodule('defined', 'file://' + defined_subrepo.repo)
    
    641
    +    main_repo.add_submodule('found', 'file://' + found_subrepo.repo)
    
    642
    +    main_mirror = main_repo.copy(mirror_dir)
    
    643
    +    main_ref = main_repo.add_file(bar_file)
    
    644
    +    
    
    645
    +    project_dir = os.path.join(str(tmpdir), 'project')
    
    646
    +    os.makedirs(project_dir)
    
    647
    +    element_dir = os.path.join(project_dir, 'elements')
    
    648
    +    os.makedirs(element_dir)
    
    649
    +    element = {
    
    650
    +        'kind': 'import',
    
    651
    +        'sources': [
    
    652
    +            main_repo.source_config(ref=main_mirror_ref)
    
    653
    +        ]
    
    654
    +    }
    
    655
    +    element_name = 'test.bst'
    
    656
    +    element_path = os.path.join(element_dir, element_name)
    
    657
    +
    
    658
    +    # Alias the main repo
    
    659
    +    full_repo = element['sources'][0]['url']
    
    660
    +    _, repo_name = os.path.split(full_repo)
    
    661
    +    alias = 'foo'
    
    662
    +    aliased_repo = alias + ':' + repo_name
    
    663
    +    element['sources'][0]['url'] = aliased_repo
    
    664
    +
    
    665
    +    # Hide the found subrepo
    
    666
    +    del element['sources'][0]['submodules']['found']
    
    667
    +
    
    668
    +    # Alias the defined subrepo
    
    669
    +    subrepo = element['sources'][0]['submodules']['defined']['url']
    
    670
    +    _, repo_name = os.path.split(subrepo)
    
    671
    +    aliased_repo = alias + ':' + repo_name
    
    672
    +    element['sources'][0]['submodules']['defined']['url'] = aliased_repo
    
    673
    +
    
    674
    +    _yaml.dump(element, element_path)
    
    675
    +
    
    676
    +    full_mirror = main_mirror.source_config()['url']
    
    677
    +    mirror_map, _ = os.path.split(full_mirror)
    
    678
    +    project = {
    
    679
    +        'name': 'test',
    
    680
    +        'element-path': 'elements',
    
    681
    +        'aliases': {
    
    682
    +            alias: 'http://www.example.com/'
    
    683
    +        },
    
    684
    +        'mirrors': [
    
    685
    +            {
    
    686
    +                'name': 'middle-earth',
    
    687
    +                'aliases': {
    
    688
    +                    alias: [mirror_map + "/"],
    
    689
    +                },
    
    690
    +            },
    
    691
    +        ]
    
    692
    +    }
    
    693
    +    project_file = os.path.join(project_dir, 'project.conf')
    
    694
    +    _yaml.dump(project, project_file)
    
    695
    +
    
    696
    +    result = cli.run(project=project_dir, args=['fetch', element_name])
    
    697
    +    result.assert_success()

  • tests/frontend/project/files/bar

  • tests/frontend/project/files/foo



  • [Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]