Skip to content

Commit 1562803

Browse files
jeremyevanscolby-swandale
authored andcommitted
[ruby/rubygems] Add support for bundle install --no-lock
This allows for the same behavior as including `lockfile false` in the Gemfile. This allows you to get the behavior without modifying the Gemfile, which is useful if you do not control the Gemfile. This is similar to the --no-lock option already supported by `gem install -g Gemfile`. ruby/rubygems@6c94623881 Co-authored-by: Colby Swandale <[email protected]>
1 parent 82d8d24 commit 1562803

File tree

5 files changed

+29
-1
lines changed

5 files changed

+29
-1
lines changed

lib/bundler/cli.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ def remove(*gems)
234234
method_option "local", type: :boolean, banner: "Do not attempt to fetch gems remotely and use the gem cache instead"
235235
method_option "prefer-local", type: :boolean, banner: "Only attempt to fetch gems remotely if not present locally, even if newer versions are available remotely"
236236
method_option "no-cache", type: :boolean, banner: "Don't update the existing gem cache."
237+
method_option "no-lock", type: :boolean, banner: "Don't create a lockfile."
237238
method_option "force", type: :boolean, aliases: "--redownload", banner: "Force reinstalling every gem, even if already installed"
238239
method_option "no-prune", type: :boolean, banner: "Don't remove stale gems from the cache (removed)."
239240
method_option "path", type: :string, banner: "Specify a different path than the system default, namely, $BUNDLE_PATH or $GEM_HOME (removed)."

lib/bundler/cli/install.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def run
4444
# (rather than some optimizations we perform at app runtime).
4545
definition = Bundler.definition(strict: true)
4646
definition.validate_runtime!
47+
definition.lockfile = false if options["no-lock"]
4748

4849
installer = Installer.install(Bundler.root, definition, options)
4950

lib/bundler/man/bundle-install.1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
.SH "NAME"
55
\fBbundle\-install\fR \- Install the dependencies specified in your Gemfile
66
.SH "SYNOPSIS"
7-
\fBbundle install\fR [\-\-force] [\-\-full\-index] [\-\-gemfile=GEMFILE] [\-\-jobs=NUMBER] [\-\-local] [\-\-no\-cache] [\-\-prefer\-local] [\-\-quiet] [\-\-retry=NUMBER] [\-\-standalone[=GROUP[ GROUP\|\.\|\.\|\.]]] [\-\-trust\-policy=TRUST\-POLICY] [\-\-target\-rbconfig=TARGET\-RBCONFIG]
7+
\fBbundle install\fR [\-\-force] [\-\-full\-index] [\-\-gemfile=GEMFILE] [\-\-jobs=NUMBER] [\-\-local] [\-\-no\-cache] [\-\-no\-lock] [\-\-prefer\-local] [\-\-quiet] [\-\-retry=NUMBER] [\-\-standalone[=GROUP[ GROUP\|\.\|\.\|\.]]] [\-\-trust\-policy=TRUST\-POLICY] [\-\-target\-rbconfig=TARGET\-RBCONFIG]
88
.SH "DESCRIPTION"
99
Install the gems specified in your Gemfile(5)\. If this is the first time you run bundle install (and a \fBGemfile\.lock\fR does not exist), Bundler will fetch all remote sources, resolve dependencies and install all needed gems\.
1010
.P
@@ -34,6 +34,11 @@ Force using locally installed gems, or gems already present in Rubygems' cache o
3434
\fB\-\-no\-cache\fR
3535
Do not update the cache in \fBvendor/cache\fR with the newly bundled gems\. This does not remove any gems in the cache but keeps the newly bundled gems from being cached during the install\.
3636
.TP
37+
\fB\-\-no\-lock\fR
38+
Do not create a lockfile\. Useful if you want to install dependencies but not lock versions of gems\. Recommended for library development, and other situations where the code is expected to work with a range of dependency versions\.
39+
.IP
40+
This has the same effect as using \fBlockfile false\fR in the Gemfile\. See gemfile(5) for more information\.
41+
.TP
3742
\fB\-\-quiet\fR
3843
Do not print progress information to the standard output\.
3944
.TP

lib/bundler/man/bundle-install.1.ronn

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ bundle-install(1) -- Install the dependencies specified in your Gemfile
99
[--jobs=NUMBER]
1010
[--local]
1111
[--no-cache]
12+
[--no-lock]
1213
[--prefer-local]
1314
[--quiet]
1415
[--retry=NUMBER]
@@ -71,6 +72,15 @@ update process below under [CONSERVATIVE UPDATING][].
7172
does not remove any gems in the cache but keeps the newly bundled gems from
7273
being cached during the install.
7374

75+
* `--no-lock`:
76+
Do not create a lockfile. Useful if you want to install dependencies but not
77+
lock versions of gems. Recommended for library development, and other
78+
situations where the code is expected to work with a range of dependency
79+
versions.
80+
81+
This has the same effect as using `lockfile false` in the Gemfile.
82+
See gemfile(5) for more information.
83+
7484
* `--quiet`:
7585
Do not print progress information to the standard output.
7686

spec/bundler/commands/install_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,17 @@
8989
expect(bundled_app("OmgFile.lock")).to exist
9090
end
9191

92+
it "doesn't create a lockfile if --no-lock option is given" do
93+
gemfile bundled_app("OmgFile"), <<-G
94+
source "https://gem.repo1"
95+
gem "myrack", "1.0"
96+
G
97+
98+
bundle "install --gemfile OmgFile --no-lock"
99+
100+
expect(bundled_app("OmgFile.lock")).not_to exist
101+
end
102+
92103
it "doesn't delete the lockfile if one already exists" do
93104
install_gemfile <<-G
94105
source "https://gem.repo1"

0 commit comments

Comments
 (0)