From 28ed11febae0fb6a7046f7f702caec3bb807a842 Mon Sep 17 00:00:00 2001 From: Julian Frimmel Date: Sat, 18 Jan 2025 20:11:37 +0100 Subject: [PATCH] Don't error out on git libraries at fixed tags 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. --- fusesoc/provider/git.py | 3 ++- tests/test_usecases.py | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) 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")