diff options
author | David RodrÃguez <deivid.rodriguez@riseup.net> | 2019-07-24 12:24:55 +0200 |
---|---|---|
committer | David RodrÃguez <deivid.rodriguez@riseup.net> | 2019-07-31 17:25:40 +0200 |
commit | 154c687310396bc6a1ca06b853dc9f3eca8c6a81 (patch) | |
tree | 94677d57fa6619016ef5c22610b93f8f5d076964 | |
parent | 33199fd0a32fe074393fc85f27a37b1f0a1eb85e (diff) | |
download | bundler-git_option_to_bundle_gem.tar.gz |
Add `--[no-]git` option to `bundle gem`git_option_to_bundle_gem
I think using `--no-git` can be useful when creating gems inside
monorepos.
-rw-r--r-- | lib/bundler/cli.rb | 1 | ||||
-rw-r--r-- | lib/bundler/cli/gem.rb | 2 | ||||
-rw-r--r-- | spec/commands/newgem_spec.rb | 36 |
3 files changed, 38 insertions, 1 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index 2f35b83c36..8b055dc902 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -538,6 +538,7 @@ module Bundler :lazy_default => [ENV["BUNDLER_EDITOR"], ENV["VISUAL"], ENV["EDITOR"]].find {|e| !e.nil? && !e.empty? }, :desc => "Open generated gemspec in the specified editor (defaults to $EDITOR or $BUNDLER_EDITOR)" method_option :ext, :type => :boolean, :default => false, :desc => "Generate the boilerplate for C extension code" + method_option :git, :type => :boolean, :default => true, :desc => "Initialize a git repo inside your library." method_option :mit, :type => :boolean, :desc => "Generate an MIT license file. Set a default with `bundle config set gem.mit true`." method_option :test, :type => :string, :lazy_default => "rspec", :aliases => "-t", :banner => "rspec", :desc => "Generate a test directory for your library, either rspec or minitest. Set a default with `bundle config set gem.test rspec`." diff --git a/lib/bundler/cli/gem.rb b/lib/bundler/cli/gem.rb index 3db1ec7843..5ae9ca4af8 100644 --- a/lib/bundler/cli/gem.rb +++ b/lib/bundler/cli/gem.rb @@ -148,7 +148,7 @@ module Bundler end end - if Bundler.git_present? + if Bundler.git_present? && options[:git] Bundler.ui.info "Initializing git repo in #{target}" Dir.chdir(target) do `git init` diff --git a/spec/commands/newgem_spec.rb b/spec/commands/newgem_spec.rb index 94f4d82e98..0b01797810 100644 --- a/spec/commands/newgem_spec.rb +++ b/spec/commands/newgem_spec.rb @@ -60,6 +60,42 @@ RSpec.describe "bundle gem" do end end + describe "git repo initialization" do + let(:gem_name) { "test-gem" } + + shared_examples_for "a gem with an initial git repo" do + before do + execute_bundle_gem(gem_name, flags) + end + it "generates a gem skeleton with a .git folder" do + gem_skeleton_assertions(gem_name) + expect(bundled_app("test-gem/.git")).to exist + end + end + + context "when using the default" do + it_behaves_like "a gem with an initial git repo" do + let(:flags) { "" } + end + end + + context "when explicitly passing --git" do + it_behaves_like "a gem with an initial git repo" do + let(:flags) { "--git" } + end + end + + context "when passing --no-git" do + before do + execute_bundle_gem(gem_name, "--no-git") + end + it "generates a gem skeleton without a .git folder" do + gem_skeleton_assertions(gem_name) + expect(bundled_app("test-gem/.git")).not_to exist + end + end + end + shared_examples_for "--mit flag" do before do execute_bundle_gem(gem_name, "--mit") |