Skip to content

Commit

Permalink
[Fixes jordansissel#1557] Allow git repo as gem source
Browse files Browse the repository at this point in the history
  • Loading branch information
liger1978 authored and jordansissel committed Mar 26, 2019
1 parent 6628f17 commit 1c1ff7d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
3 changes: 3 additions & 0 deletions fpm.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ Gem::Specification.new do |spec|
# For sourcing from pleaserun
spec.add_dependency("pleaserun", "~> 0.0.29") # license: Apache 2

# For sourcing from git repos
spec.add_dependency("git", ">= 1.3.0", "< 2.0") # license: MIT

spec.add_dependency("stud")

spec.add_development_dependency("rspec", "~> 3.0.0") # license: MIT (according to wikipedia)
Expand Down
42 changes: 32 additions & 10 deletions lib/fpm/package/gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require "fileutils"
require "fpm/util"
require "yaml"
require "git"

# A rubygems package.
#
Expand Down Expand Up @@ -53,6 +54,15 @@ class FPM::Package::Gem < FPM::Package
"The directory where fpm installs the gem temporarily before conversion. " \
"Normally a random subdirectory of workdir."

option "--git-repo", "GIT_REPO",
"Use this git repo address as the source of the gem instead of " \
"rubygems.org.", :default => nil

option "--git-branch", "GIT_BRANCH",
"When using a git repo as the source of the gem instead of " \
"rubygems.org, use this git branch.",
:default => nil

# Override parent method
def staging_path(path=nil)
@gem_staging_path ||= attributes[:gem_stagingdir] || Stud::Temporary.directory("package-#{type}-staging")
Expand Down Expand Up @@ -91,21 +101,33 @@ def download(gem_name, gem_version=nil)

logger.info("Trying to download", :gem => gem_name, :version => gem_version)

gem_fetch = [ "#{attributes[:gem_gem]}", "fetch", gem_name]

gem_fetch += ["--prerelease"] if attributes[:gem_prerelease?]
gem_fetch += ["--version", gem_version] if gem_version

download_dir = build_path(gem_name)
FileUtils.mkdir(download_dir) unless File.directory?(download_dir)

::Dir.chdir(download_dir) do |dir|
logger.debug("Downloading in directory #{dir}")
safesystem(*gem_fetch)
if attributes[:gem_git_repo]
logger.debug("Git cloning in directory #{download_dir}")
g = Git.clone(attributes[:gem_git_repo],gem_name,:path => download_dir)
if attributes[:gem_git_branch]
g.branch(attributes[:gem_git_branch]).checkout
g.pull('origin',attributes[:gem_git_branch])
end
gem_build = [ "#{attributes[:gem_gem]}", "build", "#{g.dir.to_s}/#{gem_name}.gemspec"]
::Dir.chdir(g.dir.to_s) do |dir|
logger.debug("Building in directory #{dir}")
safesystem(*gem_build)
end
gem_files = ::Dir.glob(File.join(g.dir.to_s, "*.gem"))
else
gem_fetch = [ "#{attributes[:gem_gem]}", "fetch", gem_name]
gem_fetch += ["--prerelease"] if attributes[:gem_prerelease?]
gem_fetch += ["--version", gem_version] if gem_version
::Dir.chdir(download_dir) do |dir|
logger.debug("Downloading in directory #{dir}")
safesystem(*gem_fetch)
end
gem_files = ::Dir.glob(File.join(download_dir, "*.gem"))
end

gem_files = ::Dir.glob(File.join(download_dir, "*.gem"))

if gem_files.length != 1
raise "Unexpected number of gem files in #{download_dir}, #{gem_files.length} should be 1"
end
Expand Down

0 comments on commit 1c1ff7d

Please sign in to comment.