Skip to content
Snippets Groups Projects
Commit 0eac4008 authored by Valentin David's avatar Valentin David
Browse files

buildstream/_gitsourcebase.py: Reduce git history for git describe.

Found during #833.

`git rev-list --boundary tag..HEAD` unfortunately gives boundaries
that are deeper than should when there is a merge commit between `tag`
and `HEAD`. The common ancestory of the two parents of the merge is
a boundary instead of the parent of the branch that is not traversed.

`--ancestry-path` fixes this issue by restricting `git` traversing
those branches.
parent ecae4d73
No related branches found
No related tags found
1 merge request!1069buildstream/_gitsourcebase.py: Reduce git history for git describe.
...@@ -297,7 +297,8 @@ class GitMirror(SourceFetcher): ...@@ -297,7 +297,8 @@ class GitMirror(SourceFetcher):
for _, commit_ref, _ in self.tags: for _, commit_ref, _ in self.tags:
_, out = self.source.check_output([self.source.host_git, 'rev-list', _, out = self.source.check_output([self.source.host_git, 'rev-list',
'--boundary', '{}..{}'.format(commit_ref, self.ref)], '--ancestry-path', '--boundary',
'{}..{}'.format(commit_ref, self.ref)],
fail="Failed to get git history {}..{} in directory: {}" fail="Failed to get git history {}..{} in directory: {}"
.format(commit_ref, self.ref, fullpath), .format(commit_ref, self.ref, fullpath),
fail_temporarily=True, fail_temporarily=True,
......
...@@ -883,6 +883,84 @@ def test_git_describe(cli, tmpdir, datafiles, ref_storage, tag_type): ...@@ -883,6 +883,84 @@ def test_git_describe(cli, tmpdir, datafiles, ref_storage, tag_type):
assert p.returncode != 0 assert p.returncode != 0
@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available")
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'template'))
def test_git_describe_relevant_history(cli, tmpdir, datafiles):
project = str(datafiles)
project_config = _yaml.load(os.path.join(project, 'project.conf'))
project_config['ref-storage'] = 'project.refs'
_yaml.dump(_yaml.node_sanitize(project_config), os.path.join(project, 'project.conf'))
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))
repo.create(repofiles)
file1 = os.path.join(str(tmpdir), 'file1')
with open(file1, 'w') as f:
f.write('test\n')
repo.add_file(file1)
repo.branch('branch')
repo.checkout('master')
file2 = os.path.join(str(tmpdir), 'file2')
with open(file2, 'w') as f:
f.write('test\n')
repo.add_file(file2)
file3 = os.path.join(str(tmpdir), 'file3')
with open(file3, 'w') as f:
f.write('test\n')
branch_boundary = repo.add_file(file3)
repo.checkout('branch')
file4 = os.path.join(str(tmpdir), 'file4')
with open(file4, 'w') as f:
f.write('test\n')
tagged_ref = repo.add_file(file4)
repo.add_annotated_tag('tag1', 'tag1')
head = repo.merge('master')
config = repo.source_config()
config['track'] = head
config['track-tags'] = True
# 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=['source', 'track', 'target.bst', '--deps', 'all'])
result.assert_success()
checkout = os.path.join(str(tmpdir), 'checkout')
result = cli.run(project=project, args=['build', 'target.bst'])
result.assert_success()
result = cli.run(project=project, args=['checkout', 'target.bst', checkout])
result.assert_success()
describe = subprocess.check_output(['git', 'describe'],
cwd=checkout).decode('ascii')
assert describe.startswith('tag1-2-')
rev_list = subprocess.check_output(['git', 'rev-list', '--all'],
cwd=checkout).decode('ascii')
assert set(rev_list.splitlines()) == set([head, tagged_ref, branch_boundary])
@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available") @pytest.mark.skipif(HAVE_GIT is False, reason="git is not available")
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'template')) @pytest.mark.datafiles(os.path.join(DATA_DIR, 'template'))
def test_default_do_not_track_tags(cli, tmpdir, datafiles): def test_default_do_not_track_tags(cli, tmpdir, datafiles):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment