[Notes] [Git][BuildStream/buildstream][bst-1.2] 2 commits: Force updating tags when fetching git repository



Title: GitLab

Valentin David pushed to branch bst-1.2 at BuildStream / buildstream

Commits:

3 changed files:

Changes:

  • buildstream/plugins/sources/git.py
    ... ... @@ -158,7 +158,7 @@ class GitMirror(SourceFetcher):
    158 158
             else:
    
    159 159
                 remote_name = "origin"
    
    160 160
     
    
    161
    -        self.source.call([self.source.host_git, 'fetch', remote_name, '--prune'],
    
    161
    +        self.source.call([self.source.host_git, 'fetch', remote_name, '--prune', '--force', '--tags'],
    
    162 162
                              fail="Failed to fetch from remote git repository: {}".format(url),
    
    163 163
                              fail_temporarily=True,
    
    164 164
                              cwd=self.mirror)
    

  • tests/sources/git.py
    ... ... @@ -22,6 +22,7 @@
    22 22
     
    
    23 23
     import os
    
    24 24
     import pytest
    
    25
    +import shutil
    
    25 26
     
    
    26 27
     from buildstream._exceptions import ErrorDomain
    
    27 28
     from buildstream import _yaml
    
    ... ... @@ -408,3 +409,100 @@ def test_submodule_track_no_ref_or_track(cli, tmpdir, datafiles):
    408 409
         result = cli.run(project=project, args=['show', 'target.bst'])
    
    409 410
         result.assert_main_error(ErrorDomain.SOURCE, "missing-track-and-ref")
    
    410 411
         result.assert_task_error(None, None)
    
    412
    +
    
    413
    +
    
    414
    +@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available")
    
    415
    +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'template'))
    
    416
    +def test_overwrite_rogue_tag_multiple_remotes(cli, tmpdir, datafiles):
    
    417
    +    """When using multiple remotes in cache (i.e. when using aliases), we
    
    418
    +    need to make sure we override tags. This is not allowed to fetch
    
    419
    +    tags that were present from different origins
    
    420
    +    """
    
    421
    +
    
    422
    +    project = str(datafiles)
    
    423
    +
    
    424
    +    repofiles = os.path.join(str(tmpdir), 'repofiles')
    
    425
    +    os.makedirs(repofiles, exist_ok=True)
    
    426
    +    file0 = os.path.join(repofiles, 'file0')
    
    427
    +    with open(file0, 'w') as f:
    
    428
    +        f.write('test\n')
    
    429
    +
    
    430
    +    repo = create_repo('git', str(tmpdir))
    
    431
    +
    
    432
    +    top_commit = repo.create(repofiles)
    
    433
    +
    
    434
    +    repodir, reponame = os.path.split(repo.repo)
    
    435
    +    project_config = _yaml.load(os.path.join(project, 'project.conf'))
    
    436
    +    project_config['aliases'] = {
    
    437
    +        'repo': 'http://example.com/'
    
    438
    +    }
    
    439
    +    project_config['mirrors'] = [
    
    440
    +        {
    
    441
    +            'name': 'middle-earth',
    
    442
    +            'aliases': {
    
    443
    +                'repo': ['file://{}/'.format(repodir)]
    
    444
    +            }
    
    445
    +        }
    
    446
    +    ]
    
    447
    +    _yaml.dump(_yaml.node_sanitize(project_config), os.path.join(project, 'project.conf'))
    
    448
    +
    
    449
    +    repo.add_annotated_tag('tag', 'tag')
    
    450
    +
    
    451
    +    file1 = os.path.join(repofiles, 'file1')
    
    452
    +    with open(file1, 'w') as f:
    
    453
    +        f.write('test\n')
    
    454
    +
    
    455
    +    ref = repo.add_file(file1)
    
    456
    +
    
    457
    +    config = repo.source_config(ref=ref)
    
    458
    +    del config['track']
    
    459
    +    config['url'] = 'repo:{}'.format(reponame)
    
    460
    +
    
    461
    +    # Write out our test target
    
    462
    +    element = {
    
    463
    +        'kind': 'import',
    
    464
    +        'sources': [
    
    465
    +            config
    
    466
    +        ],
    
    467
    +    }
    
    468
    +    element_path = os.path.join(project, 'target.bst')
    
    469
    +    _yaml.dump(element, element_path)
    
    470
    +
    
    471
    +    result = cli.run(project=project, args=['build', 'target.bst'])
    
    472
    +    result.assert_success()
    
    473
    +
    
    474
    +    repo.checkout(top_commit)
    
    475
    +
    
    476
    +    file2 = os.path.join(repofiles, 'file2')
    
    477
    +    with open(file2, 'w') as f:
    
    478
    +        f.write('test\n')
    
    479
    +
    
    480
    +    new_ref = repo.add_file(file2)
    
    481
    +
    
    482
    +    repo.delete_tag('tag')
    
    483
    +    repo.add_annotated_tag('tag', 'tag')
    
    484
    +    repo.checkout('master')
    
    485
    +
    
    486
    +    otherpath = os.path.join(str(tmpdir), 'other_path')
    
    487
    +    shutil.copytree(repo.repo,
    
    488
    +                    os.path.join(otherpath, 'repo'))
    
    489
    +    new_repo = create_repo('git', otherpath)
    
    490
    +
    
    491
    +    repodir, reponame = os.path.split(repo.repo)
    
    492
    +
    
    493
    +    _yaml.dump(_yaml.node_sanitize(project_config), os.path.join(project, 'project.conf'))
    
    494
    +
    
    495
    +    config = repo.source_config(ref=new_ref)
    
    496
    +    del config['track']
    
    497
    +    config['url'] = 'repo:{}'.format(reponame)
    
    498
    +
    
    499
    +    element = {
    
    500
    +        'kind': 'import',
    
    501
    +        'sources': [
    
    502
    +            config
    
    503
    +        ],
    
    504
    +    }
    
    505
    +    _yaml.dump(element, element_path)
    
    506
    +
    
    507
    +    result = cli.run(project=project, args=['build', 'target.bst'])
    
    508
    +    result.assert_success()

  • tests/testutils/repo/git.py
    ... ... @@ -82,9 +82,22 @@ class Git(Repo):
    82 82
     
    
    83 83
         def latest_commit(self):
    
    84 84
             output = subprocess.check_output([
    
    85
    -            'git', 'rev-parse', 'master'
    
    85
    +            'git', 'rev-parse', 'HEAD'
    
    86 86
             ], env=GIT_ENV, cwd=self.repo)
    
    87 87
             return output.decode('UTF-8').strip()
    
    88 88
     
    
    89 89
         def branch(self, branch_name):
    
    90 90
             subprocess.call(['git', 'checkout', '-b', branch_name], env=GIT_ENV, cwd=self.repo)
    
    91
    +
    
    92
    +    def delete_tag(self, tag_name):
    
    93
    +        subprocess.call(['git', 'tag', '-d', tag_name],
    
    94
    +                        env=GIT_ENV, cwd=self.repo)
    
    95
    +
    
    96
    +    def checkout(self, commit):
    
    97
    +        subprocess.call(['git', 'checkout', commit],
    
    98
    +                        env=GIT_ENV, cwd=self.repo)
    
    99
    +
    
    100
    +    def add_annotated_tag(self, tag, message):
    
    101
    +        subprocess.call(['git', 'tag', '-a', tag, '-m', message],
    
    102
    +                        env=GIT_ENV, cwd=self.repo)
    
    103
    +        return self.latest_commit()



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