def test_submodule_fetch_project_override(cli, tmpdir, datafiles): project = os.path.join(datafiles.dirname, datafiles.basename) checkoutdir = os.path.join(str(tmpdir), "checkout") # Create the submodule first from the 'subrepofiles' subdir subrepo = create_repo('git', str(tmpdir), 'subrepo') subrepo.create(os.path.join(project, 'subrepofiles')) # Create the repo from 'repofiles' subdir repo = create_repo('git', str(tmpdir)) ref = repo.create(os.path.join(project, 'repofiles')) # Add a submodule pointing to the one we created ref = repo.add_submodule('subdir', 'file://' + subrepo.repo) # Write out our test target element = {'kind': 'import', 'sources': [repo.source_config(ref=ref)]} _yaml.dump(element, os.path.join(project, 'target.bst')) # Fetch, build, checkout result = cli.run(project=project, args=['fetch', 'target.bst']) result.assert_success() result = cli.run(project=project, args=['build', 'target.bst']) result.assert_success() result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir]) result.assert_success() # Assert we checked out both files at their expected location assert os.path.exists(os.path.join(checkoutdir, 'file.txt')) assert not os.path.exists( os.path.join(checkoutdir, 'subdir', 'ponyfile.txt'))
def test_submodule_track_ignore_inconsistent(cli, tmpdir, datafiles): project = os.path.join(datafiles.dirname, datafiles.basename) # Create the repo from 'repofiles' subdir repo = create_repo('git', str(tmpdir)) ref = repo.create(os.path.join(project, 'repofiles')) # Write out our test target element = {'kind': 'import', 'sources': [repo.source_config(ref=ref)]} _yaml.dump(element, os.path.join(project, 'target.bst')) # Now add a .gitmodules file with an inconsistent submodule, # we are calling this inconsistent because the file was created # but `git submodule add` was never called, so there is no reference # associated to the submodule. # repo.add_file( os.path.join(project, 'inconsistent-submodule', '.gitmodules')) # Fetch should work, we're not yet at the offending ref result = cli.run(project=project, args=['fetch', 'target.bst']) result.assert_success() # Track will encounter an inconsistent submodule without any ref result = cli.run(project=project, args=['track', 'target.bst']) result.assert_success() # Assert that we are just fine without it, and emit a warning to the user. assert "Ignoring inconsistent submodule" in result.stderr
def master_gone_repo(remote_repo: Repo): with TemporaryDirectory() as directory: with TemporaryDirectory() as remote_directory: remote_repo = create_repo(remote_directory) cloned_repo = create_cloned_repo(repo_directory=directory, remote_repo=remote_repo) # ensure the directory is gone shutil.rmtree(remote_directory, ) # remove remote by closing remote_directory yield cloned_repo
def test_fetch_bad_ref(cli, tmpdir, datafiles): project = os.path.join(datafiles.dirname, datafiles.basename) # Create the repo from 'repofiles' subdir repo = create_repo('git', str(tmpdir)) ref = repo.create(os.path.join(project, 'repofiles')) # Write out our test target with a bad ref element = {'kind': 'import', 'sources': [repo.source_config(ref='5')]} _yaml.dump(element, os.path.join(project, 'target.bst')) # Assert that fetch raises an error here result = cli.run(project=project, args=['fetch', 'target.bst']) result.assert_main_error(ErrorDomain.STREAM, None) result.assert_task_error(ErrorDomain.SOURCE, None)
def test_submodule_track_no_ref_or_track(cli, tmpdir, datafiles): project = os.path.join(datafiles.dirname, datafiles.basename) # Create the repo from 'repofiles' subdir repo = create_repo('git', str(tmpdir)) ref = repo.create(os.path.join(project, 'repofiles')) # Write out our test target gitsource = repo.source_config(ref=None) gitsource.pop('track') element = {'kind': 'import', 'sources': [gitsource]} _yaml.dump(element, os.path.join(project, 'target.bst')) # Track will encounter an inconsistent submodule without any ref result = cli.run(project=project, args=['show', 'target.bst']) result.assert_main_error(ErrorDomain.SOURCE, "missing-track-and-ref") result.assert_task_error(None, None)
def test_is_ahead_vs_is_ancestor_of(): print() n_commits = 1000 with TemporaryDirectory() as directory: repo = create_repo(directory) add_n_big_commits(repo, n_commits + 1) ancestor_commit = repo.commit(f"HEAD~{n_commits}") commit = repo.commit("HEAD") elapsed_time_is_ahead_of = measure_is_ahead_of( repo=repo, ancestor=ancestor_commit, commit=commit) print( f"Elapsed time for 'is_ahead_of' {elapsed_time_is_ahead_of * 1000} ms" ) elapsed_time_is_ancestor_of = measure_is_ancestor_of( ancestor=ancestor_commit, commit=commit) print( f"Elapsed time for 'is_ancestors_of' {elapsed_time_is_ancestor_of * 1000} ms" )
def repo(): with TemporaryDirectory() as directory: yield create_repo(directory)
def test_overwrite_rogue_tag_multiple_remotes(cli, tmpdir, datafiles): """When using multiple remotes in cache (i.e. when using aliases), we need to make sure we override tags. This is not allowed to fetch tags that were present from different origins """ project = str(datafiles) repofiles = os.path.join(str(tmpdir), 'repofiles') os.makedirs(repofiles, exist_ok=True) file0 = os.path.join(repofiles, 'file0') with open(file0, 'w') as f: f.write('test\n') repo = create_repo('git', str(tmpdir)) top_commit = repo.create(repofiles) repodir, reponame = os.path.split(repo.repo) project_config = _yaml.load(os.path.join(project, 'project.conf')) project_config['aliases'] = {'repo': 'http://example.com/'} project_config['mirrors'] = [{ 'name': 'middle-earth', 'aliases': { 'repo': ['file://{}/'.format(repodir)] } }] _yaml.dump(_yaml.node_sanitize(project_config), os.path.join(project, 'project.conf')) repo.add_annotated_tag('tag', 'tag') file1 = os.path.join(repofiles, 'file1') with open(file1, 'w') as f: f.write('test\n') ref = repo.add_file(file1) config = repo.source_config(ref=ref) del config['track'] config['url'] = 'repo:{}'.format(reponame) # Write out our test target element = { 'kind': 'import', 'sources': [config], } element_path = os.path.join(project, 'target.bst') _yaml.dump(element, element_path) result = cli.run(project=project, args=['build', 'target.bst']) result.assert_success() repo.checkout(top_commit) file2 = os.path.join(repofiles, 'file2') with open(file2, 'w') as f: f.write('test\n') new_ref = repo.add_file(file2) repo.delete_tag('tag') repo.add_annotated_tag('tag', 'tag') repo.checkout('master') otherpath = os.path.join(str(tmpdir), 'other_path') shutil.copytree(repo.repo, os.path.join(otherpath, 'repo')) new_repo = create_repo('git', otherpath) repodir, reponame = os.path.split(repo.repo) _yaml.dump(_yaml.node_sanitize(project_config), os.path.join(project, 'project.conf')) config = repo.source_config(ref=new_ref) del config['track'] config['url'] = 'repo:{}'.format(reponame) element = { 'kind': 'import', 'sources': [config], } _yaml.dump(element, element_path) result = cli.run(project=project, args=['build', 'target.bst']) result.assert_success()