Skip to content

Commit

Permalink
bundler: Add branch attribute to git dependencies
Browse files Browse the repository at this point in the history
If the branch does exist, checkout the branch in the repository.
Do not go to detached state afterwards. Use `git reset --hard` instead.

Signed-off-by: Michal Šoltis <[email protected]>
  • Loading branch information
slimreaper35 committed Dec 19, 2024
1 parent 2b47f22 commit a1aff7a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
8 changes: 7 additions & 1 deletion cachi2/core/package_managers/bundler/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/package_managers/bundler/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand All @@ -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(
Expand Down

0 comments on commit a1aff7a

Please sign in to comment.