summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThe Bundler Bot <bot@bundler.io>2018-05-20 10:56:49 +0000
committerColby Swandale <me@colby.fyi>2018-10-05 16:15:43 +1000
commit51f336bf701b0deaa329e91028bd9e431b9cbb54 (patch)
tree42eb054adee21dc716d896374c6c6be74bb97e74
parente6de3b9c098538dac8a862fed01ccb4dc01a49b4 (diff)
downloadbundler-51f336bf701b0deaa329e91028bd9e431b9cbb54.tar.gz
Auto merge of #6517 - agrim123:agr-bundler-add-skip-install, r=colby-swandale
Add --skip-install flag to bundle add Usage ```bash bundle add rack --skip-install ``` This flag would not install the gem, only add it to the gemfile. Closes #6511 (cherry picked from commit c793c38a55559677573d28d4bfadd811e8508b48)
-rw-r--r--lib/bundler/cli.rb3
-rw-r--r--lib/bundler/cli/add.rb2
-rw-r--r--man/bundle-add.ronn9
-rw-r--r--spec/commands/add_spec.rb10
4 files changed, 20 insertions, 4 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index a0362f35d0..bd4f360546 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -331,7 +331,8 @@ module Bundler
method_option "version", :aliases => "-v", :type => :string
method_option "group", :aliases => "-g", :type => :string
method_option "source", :aliases => "-s", :type => :string
-
+ method_option "skip-install", :type => :boolean, :banner =>
+ "Adds gem to the Gemfile but does not install it"
def add(gem_name)
require "bundler/cli/add"
Add.new(options.dup, gem_name).run
diff --git a/lib/bundler/cli/add.rb b/lib/bundler/cli/add.rb
index 1fcbd22f28..e1a662161e 100644
--- a/lib/bundler/cli/add.rb
+++ b/lib/bundler/cli/add.rb
@@ -19,7 +19,7 @@ module Bundler
dependency = Bundler::Dependency.new(@gem_name, version, @options)
Injector.inject([dependency], :conservative_versioning => @options[:version].nil?) # Perform conservative versioning only when version is not specified
- Installer.install(Bundler.root, Bundler.definition)
+ Installer.install(Bundler.root, Bundler.definition) unless @options["skip-install"]
end
end
end
diff --git a/man/bundle-add.ronn b/man/bundle-add.ronn
index f0f9b54d8f..91eb1d7188 100644
--- a/man/bundle-add.ronn
+++ b/man/bundle-add.ronn
@@ -3,10 +3,10 @@ bundle-add(1) -- Add gem to the Gemfile and run bundle install
## SYNOPSIS
-`bundle add` <GEM_NAME> [--group=GROUP] [--version=VERSION] [--source=SOURCE]
+`bundle add` <GEM_NAME> [--group=GROUP] [--version=VERSION] [--source=SOURCE] [--skip-install]
## DESCRIPTION
-Adds the named gem to the Gemfile and run `bundle install`.
+Adds the named gem to the Gemfile and run `bundle install`. `bundle install` can be avoided by using the flag `--skip-install`.
Example:
@@ -16,6 +16,8 @@ bundle add rails --version "< 3.0, > 1.1"
bundle add rails --version "~> 5.0.0" --source "https://gems.example.com" --group "development"
+bundle add rails --skip-install
+
bundle add rails --group "development, test"
## OPTIONS
@@ -27,3 +29,6 @@ bundle add rails --group "development, test"
* `--source`, , `-s`:
Specify the source for the added gem.
+
+* `--skip-install`:
+ Adds the gem to the Gemfile but does not install it.
diff --git a/spec/commands/add_spec.rb b/spec/commands/add_spec.rb
index 799c8a1b93..fb3bd9928d 100644
--- a/spec/commands/add_spec.rb
+++ b/spec/commands/add_spec.rb
@@ -75,11 +75,21 @@ RSpec.describe "bundle add" do
describe "with --source" do
it "adds dependency with specified source" do
bundle "add 'foo' --source='file://#{gem_repo2}'"
+
expect(bundled_app("Gemfile").read).to match(%r{gem "foo", "~> 2.0", :source => "file:\/\/#{gem_repo2}"})
expect(the_bundle).to include_gems "foo 2.0"
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"
+
+ expect(bundled_app("Gemfile").read).to match(/gem "foo", "= 2.0"/)
+ expect(the_bundle).to_not include_gems "foo 2.0"
+ end
+ end
+
it "using combination of short form options works like long form" do
bundle "add 'foo' -s='file://#{gem_repo2}' -g='development' -v='~>1.0'"
expect(bundled_app("Gemfile").read).to include %(gem "foo", "~> 1.0", :group => :development, :source => "file://#{gem_repo2}")