From ce297cabdb3dc0d951e56772c9d8de7a6beeaff6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milan=20Tichavsk=C3=BD?= Date: Mon, 12 Sep 2022 11:42:36 +0200 Subject: [PATCH] Fix RubyGems GIT dependencies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When Cachito worker downloads GIT dependency, the downloaded Git repository is checked out at a proper revision (according to the `Gemfile.lock`), but it's not checked out at a proper branch. Until now, Cachito was using `git checkout -b `, however, this didn't work for cases when the branch already existed (e.g. downloaded repositories usually contained `master` branch and if the `Gemfile.lock` specified `master` branch too, this command tried to create a branch that already existed). To fix this, `-B` option should be used in `git checkout`, because in case of an existing branch, it checks out the branch and resets it to the current commit and no error is raised. Signed-off-by: Milan Tichavský --- cachito/workers/pkg_managers/rubygems.py | 2 +- tests/test_workers/test_pkg_managers/test_rubygems.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cachito/workers/pkg_managers/rubygems.py b/cachito/workers/pkg_managers/rubygems.py index f531b9824..6d6120aa2 100644 --- a/cachito/workers/pkg_managers/rubygems.py +++ b/cachito/workers/pkg_managers/rubygems.py @@ -424,7 +424,7 @@ def checkout_branch(dep: dict): try: repo = Repo(dep["path"] / "app") git = repo.git - git.checkout("HEAD", b=dep["branch"]) + git.checkout("HEAD", B=dep["branch"]) except CheckoutError: raise GitError(f"Couldn't checkout branch {dep['branch']} at {dep['path'] / 'app'}") except Exception: diff --git a/tests/test_workers/test_pkg_managers/test_rubygems.py b/tests/test_workers/test_pkg_managers/test_rubygems.py index a49d4b9a8..76cf4e9f7 100644 --- a/tests/test_workers/test_pkg_managers/test_rubygems.py +++ b/tests/test_workers/test_pkg_managers/test_rubygems.py @@ -921,7 +921,7 @@ def test_checkout_branch(mock_repo): rubygems.checkout_branch({"path": Path("/yo"), "branch": "b"}) mock_repo.assert_called_with(Path("/yo/app")) - mock_repo.return_value.git.checkout.assert_called_once_with("HEAD", b="b") + mock_repo.return_value.git.checkout.assert_called_once_with("HEAD", B="b") @mock.patch("cachito.workers.pkg_managers.rubygems.Repo")