diff --git a/fusesoc/provider/git.py b/fusesoc/provider/git.py index cbcf3a18..bb1af4b1 100644 --- a/fusesoc/provider/git.py +++ b/fusesoc/provider/git.py @@ -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() diff --git a/tests/test_usecases.py b/tests/test_usecases.py index 52694e3c..f254f809 100644 --- a/tests/test_usecases.py +++ b/tests/test_usecases.py @@ -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")