From c3ff45fffe04e8b43c3513b9f9afdc49c64a48ab Mon Sep 17 00:00:00 2001 From: The Bundler Bot Date: Sun, 20 May 2018 10:56:49 +0000 Subject: [PATCH] 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) --- lib/bundler/cli.rb | 3 ++- lib/bundler/cli/add.rb | 2 +- man/bundle-add.ronn | 9 +++++++-- spec/commands/add_spec.rb | 10 ++++++++++ 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index 9d4799247b8..835a94fa928 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -331,7 +331,8 @@ def binstubs(*gems) 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 1fcbd22f28f..e1a662161eb 100644 --- a/lib/bundler/cli/add.rb +++ b/lib/bundler/cli/add.rb @@ -19,7 +19,7 @@ def run 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 f0f9b54d8fc..91eb1d71881 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` [--group=GROUP] [--version=VERSION] [--source=SOURCE] +`bundle add` [--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 d1f2050aa0d..7299938caa0 100644 --- a/spec/commands/add_spec.rb +++ b/spec/commands/add_spec.rb @@ -75,11 +75,21 @@ 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}")