Skip to content

Commit

Permalink
Don't error out on git libraries at fixed tags
Browse files Browse the repository at this point in the history
See #721 for context. This simply uses `git fetch` instead of `git pull`
if a specific version is requested. This is a kind of hacky solution,
since this won't work if somebody removes the `sync-version` from the
`fusesoc.conf`-file (in that case, the code will use `git pull` again,
which will fail as before). Since this usecase is not that common, this
commit should be enough for now.
  • Loading branch information
jfrimmel committed Jan 18, 2025
1 parent 9c5f89d commit 28ed11f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion fusesoc/provider/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def init_library(library):

@staticmethod
def update_library(library):
git_args = ["-C", library.location, "pull"]
download_option = "pull" if not library.sync_version else "fetch"
git_args = ["-C", library.location, download_option]
try:
Git._checkout_library_version(library)
Launcher("git", git_args).run()
Expand Down
24 changes: 24 additions & 0 deletions tests/test_usecases.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,30 @@ def test_git_library_with_default_branch_is_added_and_updated(caplog):
assert "Updating..." in caplog.text


def test_update_git_library_with_fixed_version(caplog, capsys):
"""
Previously, one could not successfully use `fusesoc library update` on
libraries with specific sync versions. This test checks, that no error is
reported in that case.
"""
url = "https://github.com/fusesoc/fusesoc-generators"
_fusesoc("library", "add", url, "--sync-version", "v0.1.4")
assert "Checked out fusesoc-generators at version v0.1.4" in caplog.text

_fusesoc("library", "list")
output = capsys.readouterr().out
assert "fusesoc-generators" in output
assert "v0.1.4" in output

_fusesoc("library", "update")
assert "Failed to update library" not in caplog.text

_fusesoc("library", "list")
output = capsys.readouterr().out
assert "fusesoc-generators" in output
assert "v0.1.4" in output


def test_usage_error_leads_to_nonzero_exit_code():
with pytest.raises(SystemExit):
_fusesoc("--option_does_not_exist")
Expand Down

0 comments on commit 28ed11f

Please sign in to comment.