Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/buildstream_plugins/sources/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,11 @@ def _guess_version(self):
commit_sha = None

string = self.mirror.ref

if string is None:
# An untracked source has no ref to guess from: the "sha"
# cannot be discovered, so honor the documented contract
# ("either None or strings") instead of crashing on None.
return (None, version_guess, commits)
main_split = string.rsplit("-g", 1)
if len(main_split) < 2:
# Didn't find the `-g`, assume its a raw git sha as input
Expand All @@ -1097,6 +1101,8 @@ def _guess_version(self):
return (commit_sha, version_guess, commits)

def collect_source_info(self):
if self.mirror.ref is None:
return []
Comment on lines +1104 to +1105

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the review delay. The _guess_version() improvement looks good to me. However, I'm not convinced we actually want/need the early return in collect_source_info().

If we want to prevent collecting info of unresolved sources, I think we should consider this in BuildStream core, not require plugins to handle that case. The _guess_version() improvement is sufficient to fix the crash, as far as I can tell.

Do you have a good argument for this early return or are you ok with dropping that part?

extra_data = None
commit_sha, version_guess, commits = self._guess_version()
if commits:
Expand Down
19 changes: 19 additions & 0 deletions tests/sources/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -1243,3 +1243,22 @@ def test_source_info(
commit_offset = None

assert commit_offset == expected_offset


@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available")
@pytest.mark.datafiles(os.path.join(DATA_DIR, "template"))
def test_source_info_untracked_source(cli, tmpdir, datafiles):
project = str(datafiles)

# Create the repo, but never track the element: the source
# is valid (has a track) yet has no ref.
repo = create_repo("git", str(tmpdir))
repo.create(os.path.join(project, "repofiles"))

# Write out our test target with track and NO ref
element = {"kind": "import", "sources": [repo.source_config(ref=None)]}
generate_element(project, "target.bst", element)

# `bst show` with %{source-info} must not crash on the untracked source
result = cli.run(project=project, args=["show", "--format", "%{name}:\n%{source-info}", "target.bst"])
result.assert_success()
Loading