[前][次][番号順一覧][スレッド一覧]

ruby-changes:70151

From: Vyacheslav <ko1@a...>
Date: Sat, 11 Dec 2021 00:13:42 +0900 (JST)
Subject: [ruby-changes:70151] 1a62a50c4f (master): [rubygems/rubygems] Add `github` and `ref` options to `bundle add`

https://git.ruby-lang.org/ruby.git/commit/?id=1a62a50c4f

From 1a62a50c4f9c835dee5d6bc17ca45914daea1bbd Mon Sep 17 00:00:00 2001
From: Vyacheslav Alexeev <alexeev.corp@g...>
Date: Fri, 10 Dec 2021 15:40:58 +0800
Subject: [rubygems/rubygems] Add `github` and `ref` options to `bundle add`

https://github.com/rubygems/rubygems/commit/c3e54acab0
---
 lib/bundler/cli.rb                |  2 ++
 lib/bundler/dependency.rb         |  4 +++-
 lib/bundler/injector.rb           |  4 +++-
 lib/bundler/man/bundle-add.1      | 10 +++++++++-
 lib/bundler/man/bundle-add.1.ronn |  8 +++++++-
 spec/bundler/commands/add_spec.rb | 37 +++++++++++++++++++++++++++++++++++--
 6 files changed, 59 insertions(+), 6 deletions(-)

diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index 9046c0115c9..36d0472c624 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -369,7 +369,9 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/cli.rb#L369
     method_option "source", :aliases => "-s", :type => :string
     method_option "require", :aliases => "-r", :type => :string, :banner => "Adds require path to gem. Provide false, or a path as a string."
     method_option "git", :type => :string
+    method_option "github", :type => :string
     method_option "branch", :type => :string
+    method_option "ref", :type => :string
     method_option "skip-install", :type => :boolean, :banner =>
       "Adds gem to the Gemfile but does not install it"
     method_option "optimistic", :type => :boolean, :banner => "Adds optimistic declaration of version to gem"
diff --git a/lib/bundler/dependency.rb b/lib/bundler/dependency.rb
index 27206b1bac9..94e85053dd5 100644
--- a/lib/bundler/dependency.rb
+++ b/lib/bundler/dependency.rb
@@ -7,7 +7,7 @@ require_relative "rubygems_ext" https://github.com/ruby/ruby/blob/trunk/lib/bundler/dependency.rb#L7
 module Bundler
   class Dependency < Gem::Dependency
     attr_reader :autorequire
-    attr_reader :groups, :platforms, :gemfile, :git, :branch
+    attr_reader :groups, :platforms, :gemfile, :git, :github, :branch, :ref
 
     PLATFORM_MAP = {
       :ruby     => Gem::Platform::RUBY,
@@ -82,7 +82,9 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/dependency.rb#L82
       @groups         = Array(options["group"] || :default).map(&:to_sym)
       @source         = options["source"]
       @git            = options["git"]
+      @github         = options["github"]
       @branch         = options["branch"]
+      @ref            = options["ref"]
       @platforms      = Array(options["platforms"])
       @env            = options["env"]
       @should_include = options.fetch("should_include", true)
diff --git a/lib/bundler/injector.rb b/lib/bundler/injector.rb
index 5e5dfca02ee..42f837a919c 100644
--- a/lib/bundler/injector.rb
+++ b/lib/bundler/injector.rb
@@ -112,10 +112,12 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/injector.rb#L112
 
         source = ", :source => \"#{d.source}\"" unless d.source.nil?
         git = ", :git => \"#{d.git}\"" unless d.git.nil?
+        github = ", :github => \"#{d.github}\"" unless d.github.nil?
         branch = ", :branch => \"#{d.branch}\"" unless d.branch.nil?
+        ref = ", :ref => \"#{d.ref}\"" unless d.ref.nil?
         require_path = ", :require => #{convert_autorequire(d.autorequire)}" unless d.autorequire.nil?
 
-        %(gem #{name}#{requirement}#{group}#{source}#{git}#{branch}#{require_path})
+        %(gem #{name}#{requirement}#{group}#{source}#{git}#{github}#{branch}#{ref}#{require_path})
       end.join("\n")
     end
 
diff --git a/lib/bundler/man/bundle-add.1 b/lib/bundler/man/bundle-add.1
index a94467e25f3..6c462ba839b 100644
--- a/lib/bundler/man/bundle-add.1
+++ b/lib/bundler/man/bundle-add.1
@@ -7,7 +7,7 @@ https://github.com/ruby/ruby/blob/trunk/lib/bundler/man/bundle-add.1#L7
 \fBbundle\-add\fR \- Add gem to the Gemfile and run bundle install
 .
 .SH "SYNOPSIS"
-\fBbundle add\fR \fIGEM_NAME\fR [\-\-group=GROUP] [\-\-version=VERSION] [\-\-source=SOURCE] [\-\-git=GIT] [\-\-branch=BRANCH] [\-\-skip\-install] [\-\-strict] [\-\-optimistic]
+\fBbundle add\fR \fIGEM_NAME\fR [\-\-group=GROUP] [\-\-version=VERSION] [\-\-source=SOURCE] [\-\-git=GIT] [\-\-github=GITHUB] [\-\-branch=BRANCH] [\-\-ref=REF] [\-\-skip\-install] [\-\-strict] [\-\-optimistic]
 .
 .SH "DESCRIPTION"
 Adds the named gem to the Gemfile and run \fBbundle install\fR\. \fBbundle install\fR can be avoided by using the flag \fB\-\-skip\-install\fR\.
@@ -49,10 +49,18 @@ Specify the source for the added gem\. https://github.com/ruby/ruby/blob/trunk/lib/bundler/man/bundle-add.1#L49
 Specify the git source for the added gem\.
 .
 .TP
+\fB\-\-github\fR
+Specify the github source for the added gem\.
+.
+.TP
 \fB\-\-branch\fR
 Specify the git branch for the added gem\.
 .
 .TP
+\fB\-\-ref\fR
+Specify the git ref for the added gem\.
+.
+.TP
 \fB\-\-skip\-install\fR
 Adds the gem to the Gemfile but does not install it\.
 .
diff --git a/lib/bundler/man/bundle-add.1.ronn b/lib/bundler/man/bundle-add.1.ronn
index 26cbe556471..6547297c862 100644
--- a/lib/bundler/man/bundle-add.1.ronn
+++ b/lib/bundler/man/bundle-add.1.ronn
@@ -3,7 +3,7 @@ bundle-add(1) -- Add gem to the Gemfile and run bundle install https://github.com/ruby/ruby/blob/trunk/lib/bundler/man/bundle-add.1.ronn#L3
 
 ## SYNOPSIS
 
-`bundle add` <GEM_NAME> [--group=GROUP] [--version=VERSION] [--source=SOURCE] [--git=GIT] [--branch=BRANCH] [--skip-install] [--strict] [--optimistic]
+`bundle add` <GEM_NAME> [--group=GROUP] [--version=VERSION] [--source=SOURCE] [--git=GIT] [--github=GITHUB] [--branch=BRANCH] [--ref=REF] [--skip-install] [--strict] [--optimistic]
 
 ## DESCRIPTION
 Adds the named gem to the Gemfile and run `bundle install`. `bundle install` can be avoided by using the flag `--skip-install`.
@@ -33,9 +33,15 @@ bundle add rails --group "development, test" https://github.com/ruby/ruby/blob/trunk/lib/bundler/man/bundle-add.1.ronn#L33
 * `--git`:
   Specify the git source for the added gem.
 
+* `--github`:
+  Specify the github source for the added gem.
+
 * `--branch`:
   Specify the git branch for the added gem.
 
+* `--ref`:
+  Specify the git ref for the added gem.
+
 * `--skip-install`:
   Adds the gem to the Gemfile but does not install it.
 
diff --git a/spec/bundler/commands/add_spec.rb b/spec/bundler/commands/add_spec.rb
index 093ec53fea0..96ea238063e 100644
--- a/spec/bundler/commands/add_spec.rb
+++ b/spec/bundler/commands/add_spec.rb
@@ -104,7 +104,7 @@ RSpec.describe "bundle add" do https://github.com/ruby/ruby/blob/trunk/spec/bundler/commands/add_spec.rb#L104
   end
 
   describe "with --git" do
-    it "adds dependency with specified github source" do
+    it "adds dependency with specified git source" do
       bundle "add foo --git=#{lib_path("foo-2.0")}"
 
       expect(bundled_app_gemfile.read).to match(/gem "foo", "~> 2.0", :git => "#{lib_path("foo-2.0")}"/)
@@ -117,7 +117,7 @@ RSpec.describe "bundle add" do https://github.com/ruby/ruby/blob/trunk/spec/bundler/commands/add_spec.rb#L117
       update_git "foo", "2.0", :branch => "test"
     end
 
-    it "adds dependency with specified github source and branch" do
+    it "adds dependency with specified git source and branch" do
       bundle "add foo --git=#{lib_path("foo-2.0")} --branch=test"
 
       expect(bundled_app_gemfile.read).to match(/gem "foo", "~> 2.0", :git => "#{lib_path("foo-2.0")}", :branch => "test"/)
@@ -125,6 +125,39 @@ RSpec.describe "bundle add" do https://github.com/ruby/ruby/blob/trunk/spec/bundler/commands/add_spec.rb#L125
     end
   end
 
+  describe "with --git and --ref" do
+    it "adds dependency with specified git source and branch" do
+      bundle "add foo --git=#{lib_path("foo-2.0")} --ref=#{revision_for(lib_path("foo-2.0"))}"
+
+      expect(bundled_app_gemfile.read).to match(/gem "foo", "~> 2\.0", :git => "#{lib_path("foo-2.0")}", :ref => "#{revision_for(lib_path("foo-2.0"))}"/)
+      expect(the_bundle).to include_gems "foo 2.0"
+    end
+  end
+
+  describe "with --github" do
+    it "adds dependency with specified github source" do
+      bundle "add rake --github=ruby/rake"
+
+      expect(bundled_app_gemfile.read).to match(%r{gem "rake", "~> 13\.0", :github => "ruby\/rake"})
+    end
+  end
+
+  describe "with --github and --branch" do
+    it "adds dependency with specified github source and branch" do
+      bundle "add rake --github=ruby/rake --branch=master"
+
+      expect(bundled_app_gemfile.read).to match(%r{gem "rake", "~> 13\.0", :github => "ruby\/rake", :branch => "master"})
+    end
+  end
+
+  describe "with --github and --ref" do
+    it "adds dependency with specified github source and ref" do
+      bundle "add rake --github=ruby/rake --ref=5c60da8"
+
+      expect(bundled_app_gemfile.read).to match(%r{gem "rake", "~> 13\.0", :github => "ruby\/rake", :ref => "5c60da8"})
+    end
+  end
+
   describe "with --skip-install" do
     it "adds gem to Gemfile but is not installed" do
       bundle "add foo --skip-install --version=2.0"
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]