Skip to content

Commit

Permalink
Fix RubyGems GIT dependencies
Browse files Browse the repository at this point in the history
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 <branch name>`, 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ý <[email protected]>
  • Loading branch information
mtichavsky authored and chmeliik committed Sep 14, 2022
1 parent 7f1c938 commit ce297ca
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cachito/workers/pkg_managers/rubygems.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_workers/test_pkg_managers/test_rubygems.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit ce297ca

Please sign in to comment.