Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Auto merge of #6517 - agrim123:agr-bundler-add-skip-install, r=colby-…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
bundlerbot committed May 20, 2018
2 parents 0c5d3b8 + dddfcf2 commit c793c38
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/bundler/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,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
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/cli/add.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 7 additions & 2 deletions man/bundle-add.ronn
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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
Expand All @@ -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.
10 changes: 10 additions & 0 deletions spec/commands/add_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down

0 comments on commit c793c38

Please sign in to comment.