diff --git a/cachi2/core/package_managers/bundler/parser.py b/cachi2/core/package_managers/bundler/parser.py index fcea98b35..77f596944 100644 --- a/cachi2/core/package_managers/bundler/parser.py +++ b/cachi2/core/package_managers/bundler/parser.py @@ -116,10 +116,12 @@ class GitDependency(_GemMetadata): Attributes: url: The URL of the git repository. + branch: The branch to checkout. ref: Commit hash. """ url: AcceptedUrl + branch: Optional[str] = None ref: AcceptedGitRef @cached_property @@ -153,7 +155,11 @@ def download_to(self, deps_dir: RootedPath) -> None: to_path=git_repo_path.path, env={"GIT_TERMINAL_PROMPT": "0"}, ) - repo.git.checkout(self.ref) + + if self.branch is not None: + repo.git.checkout(self.branch) + + repo.git.reset("--hard", self.ref) class PathDependency(_GemMetadata): diff --git a/cachi2/core/package_managers/bundler/scripts/lockfile_parser.rb b/cachi2/core/package_managers/bundler/scripts/lockfile_parser.rb index 15afc71b3..8fcfd98e9 100755 --- a/cachi2/core/package_managers/bundler/scripts/lockfile_parser.rb +++ b/cachi2/core/package_managers/bundler/scripts/lockfile_parser.rb @@ -11,21 +11,22 @@ lockfile_parser.specs.each do |spec| parsed_spec = { name: spec.name, - version: spec.version.to_s + version: spec.version } case spec.source when Bundler::Source::Rubygems parsed_spec[:type] = 'rubygems' - parsed_spec[:source] = spec.source.remotes.map(&:to_s).first + parsed_spec[:source] = spec.source.remotes.first parsed_spec[:platform] = spec.platform when Bundler::Source::Git parsed_spec[:type] = 'git' parsed_spec[:url] = spec.source.uri + parsed_spec[:branch] = spec.source.branch parsed_spec[:ref] = spec.source.revision when Bundler::Source::Path parsed_spec[:type] = 'path' - parsed_spec[:subpath] = spec.source.path.to_s + parsed_spec[:subpath] = spec.source.path end parsed_specs << parsed_spec diff --git a/tests/unit/package_managers/bundler/test_parser.py b/tests/unit/package_managers/bundler/test_parser.py index ae3e63dde..9dc518cd4 100644 --- a/tests/unit/package_managers/bundler/test_parser.py +++ b/tests/unit/package_managers/bundler/test_parser.py @@ -153,6 +153,7 @@ def test_parse_gemlock( { "type": "git", "url": "https://github.com/3scale/json-schema.git", + "branch": "devel", "ref": GIT_REF, **base_dep, }, @@ -177,6 +178,7 @@ def test_parse_gemlock( name="example", version="0.1.0", url="https://github.com/3scale/json-schema.git", + branch="devel", ref=GIT_REF, ), PathDependency(