From b7027099b19c12f8d43df0213278d2dc42471503 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Sun, 9 Feb 2020 23:04:29 +0100 Subject: [PATCH] Update git init when generating plugins * Extract separate test, test with `--skip-git` * Move `version_control` beneath `gitignore` to match `AppBuilder` from 8989a505 * Add changelog entry --- railties/CHANGELOG.md | 6 ++++++ .../generators/rails/plugin/plugin_generator.rb | 12 ++++++------ railties/test/generators/plugin_generator_test.rb | 9 +++++++-- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index a1e94f3f7c..334ee33a3b 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,9 @@ +* Run `git init` when generating plugins. + + Opt out with `--skip-git`. + + *OKURA Masafumi* + * Add benchmark generator Introduce benchmark generator to benchmark Rails applications. diff --git a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb b/railties/lib/rails/generators/rails/plugin/plugin_generator.rb index 8211fc2352..399d13c819 100644 --- a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb +++ b/railties/lib/rails/generators/rails/plugin/plugin_generator.rb @@ -57,6 +57,12 @@ module Rails template "gitignore", ".gitignore" end + def version_control + if !options[:skip_git] && !options[:pretend] + run "git init", capture: options[:quiet], abort_on_failure: false + end + end + def lib template "lib/%namespaced_name%.rb" template "lib/tasks/%namespaced_name%_tasks.rake" @@ -161,12 +167,6 @@ task default: :test append_file gemfile_in_app_path, entry end end - - def version_control - if !options[:skip_git] && !options[:pretend] - run "git init", capture: options[:quiet], abort_on_failure: false - end - end end module Generators diff --git a/railties/test/generators/plugin_generator_test.rb b/railties/test/generators/plugin_generator_test.rb index 2962aab1a7..ea6ca1e24d 100644 --- a/railties/test/generators/plugin_generator_test.rb +++ b/railties/test/generators/plugin_generator_test.rb @@ -64,7 +64,7 @@ class PluginGeneratorTest < Rails::Generators::TestCase end def test_generating_without_options - output = run_generator + run_generator assert_file "README.md", /Bukkits/ assert_no_file "config/routes.rb" assert_no_file "app/assets/config/bukkits_manifest.js" @@ -79,7 +79,11 @@ class PluginGeneratorTest < Rails::Generators::TestCase assert_file "test/bukkits_test.rb", /assert_kind_of Module, Bukkits/ assert_file "bin/test" assert_no_file "bin/rails" - assert_match(/run git init/, output) + end + + def test_initializes_git_repo + run_generator + assert_directory ".git" end def test_generating_in_full_mode_with_almost_of_all_skip_options @@ -607,6 +611,7 @@ class PluginGeneratorTest < Rails::Generators::TestCase assert_match name, contents assert_match email, contents end + assert_no_directory ".git" end def test_skipping_useless_folders_generation_for_api_engines