From 02f7b3ef2d455fff46cb6d5a0877a5193bc769c9 Mon Sep 17 00:00:00 2001 From: Julianna Date: Wed, 13 Dec 2023 01:05:04 -0600 Subject: [PATCH 01/10] fix: local overcommit file merges with existing .overcommit.yml file (#815) --- lib/overcommit/configuration_loader.rb | 6 +- spec/overcommit/configuration_loader_spec.rb | 62 ++++++++++++++------ 2 files changed, 45 insertions(+), 23 deletions(-) diff --git a/lib/overcommit/configuration_loader.rb b/lib/overcommit/configuration_loader.rb index e4063d7e..8fd68a01 100644 --- a/lib/overcommit/configuration_loader.rb +++ b/lib/overcommit/configuration_loader.rb @@ -70,11 +70,9 @@ def load_repo_config # Loads a configuration, ensuring it extends the default configuration. def load_file(file, local_file = nil) overcommit_config = self.class.load_from_file(file, default: false, logger: @log) - if local_file - local_config = self.class.load_from_file(local_file, default: false, logger: @log) - end + l_config = self.class.load_from_file(local_file, default: false, logger: @log) if local_file config = self.class.default_configuration.merge(overcommit_config) - config = self.class.default_configuration.merge(local_config) if local_config + config = config.merge(l_config) if l_config if @options.fetch(:verify) { config.verify_signatures? } verify_signatures(config) diff --git a/spec/overcommit/configuration_loader_spec.rb b/spec/overcommit/configuration_loader_spec.rb index 2ddbe4e6..90497201 100644 --- a/spec/overcommit/configuration_loader_spec.rb +++ b/spec/overcommit/configuration_loader_spec.rb @@ -58,11 +58,32 @@ end end - context 'when repo contains a local configuration file' do + context 'when repo only contains a repo level configuration file' do let(:config_contents) { <<-CFG } - plugin_directory: 'some-directory' + PreCommit: + Rubocop: + enabled: true CFG + around do |example| + repo do + File.open('.overcommit.yml', 'w') { |f| f.write(config_contents) } + example.run + end + end + + it 'includes default settings' do + subject + subject.for_hook('CapitalizedSubject', 'CommitMsg').should include('enabled' => true) + end + + it 'includes .overwrite.yml configs' do + subject + subject.for_hook('Rubocop', 'PreCommit').should include('enabled' => true) + end + end + + context 'when repo also contains a local configuration file' do let(:local_config_contents) { <<-CFG } plugin_directory: 'some-different-directory' CFG @@ -75,28 +96,31 @@ end end - it 'loads the file' do - Overcommit::ConfigurationLoader.any_instance. - should_receive(:load_file). - with(File.expand_path('.overcommit.yml'), File.expand_path('.local-overcommit.yml')) + let(:config_contents) { <<-CFG } + PreCommit: + ScssLint: + enabled: true + CFG + + let(:local_config_contents) { <<-CFG } + PreCommit: + Rubocop: + enabled: true + CFG + + it 'includes default settings' do subject + subject.for_hook('CapitalizedSubject', 'CommitMsg').should include('enabled' => true) end - it 'merges each loaded file with the default configuration' do - subject.plugin_directory.should == File.expand_path('some-different-directory') + it 'includes .overwrite.yml configs' do + subject + subject.for_hook('ScssLint', 'PreCommit').should include('enabled' => true) end - context 'and the configuration file contains a hook with no `enabled` option' do - let(:config_contents) { <<-CFG } - PreCommit: - ScssLint: - command: ['bundle', 'exec', 'scss-lint'] - CFG - - it 'displays a warning' do - subject - output.string.should =~ /PreCommit::ScssLint.*not.*enabled/i - end + it 'includes .local-overwrite.yml configs' do + subject + subject.for_hook('Rubocop', 'PreCommit').should include('enabled' => true) end end end From 38febfc1d798a5220d97c58307a8621e8d427258 Mon Sep 17 00:00:00 2001 From: Shane da Silva Date: Tue, 12 Dec 2023 23:09:05 -0800 Subject: [PATCH 02/10] Cut version 0.61.0 (#817) --- CHANGELOG.md | 5 +++++ lib/overcommit/version.rb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca3a52eb..cc14f3f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Overcommit Changelog +## 0.61.0 + +* Allow `ReplaceBranch` to use `skip_if` +* Fix local Overcommit file merges with existing `.overcommit.yml` + ## 0.60.0 * Allow overriding `Gemfile.lock` location for `BundleCheck` pre-commit hook diff --git a/lib/overcommit/version.rb b/lib/overcommit/version.rb index 0c03dd7f..0646ce48 100644 --- a/lib/overcommit/version.rb +++ b/lib/overcommit/version.rb @@ -2,5 +2,5 @@ # Defines the gem version. module Overcommit - VERSION = '0.60.0' + VERSION = '0.61.0' end From 4f11048e99134ea0e4128d7ad6694f3b230d88f1 Mon Sep 17 00:00:00 2001 From: Denis Zaratan Pasin Date: Wed, 13 Dec 2023 08:11:36 +0100 Subject: [PATCH 03/10] Adding Ruby 3.2 to test matrix (#816) --- .github/workflows/tests.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 848db60c..416afe34 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -18,6 +18,7 @@ jobs: - '2.7' - '3.0' - '3.1' + - '3.2' os: - ubuntu - windows @@ -27,6 +28,8 @@ jobs: exclude: - ruby-version: '3.1' os: windows + - ruby-version: '3.2' + os: windows steps: - uses: actions/checkout@v2 From faf76fc7aa01c2b3264020ed301b569a9ed53360 Mon Sep 17 00:00:00 2001 From: Andy Waite <13400+andyw8@users.noreply.github.com> Date: Sun, 14 Jan 2024 21:06:39 -0500 Subject: [PATCH 04/10] Update RuboCop (#818) The current version of Ruby is from April 2020. Since there are quite a lot of new issues identified, I've committed them to the `.rubocop_todo.yml` so that they can be addressed incrementally or disabled. Co-authored-by: Andy Waite --- .rubocop.yml | 2 + .rubocop_todo.yml | 137 ++++++++++++++++++ Gemfile | 4 +- .../hook/pre_commit/phpcs_fixer_spec.rb | 12 +- 4 files changed, 147 insertions(+), 8 deletions(-) create mode 100644 .rubocop_todo.yml diff --git a/.rubocop.yml b/.rubocop.yml index 35002594..8c779097 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,5 @@ +inherit_from: .rubocop_todo.yml + AllCops: TargetRubyVersion: 2.4 diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 00000000..53df9159 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,137 @@ +# This configuration was generated by +# `rubocop --auto-gen-config --auto-gen-only-exclude --no-exclude-limit` +# on 2024-01-10 14:09:00 UTC using RuboCop version 1.59.0. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowAliasSyntax, AllowedMethods. +# AllowedMethods: alias_method, public, protected, private +Layout/EmptyLinesAroundAttributeAccessor: + Exclude: + - 'lib/overcommit/hook_context/post_merge.rb' + +# Offense count: 6 +# Configuration parameters: AllowedMethods. +# AllowedMethods: enums +Lint/ConstantDefinitionInBlock: + Exclude: + - 'spec/overcommit/message_processor_spec.rb' + +# Offense count: 4 +Lint/MixedRegexpCaptureTypes: + Exclude: + - 'lib/overcommit/hook/pre_commit/dart_analyzer.rb' + - 'lib/overcommit/hook/pre_commit/java_checkstyle.rb' + - 'lib/overcommit/hook/pre_commit/kt_lint.rb' + - 'lib/overcommit/hook/pre_commit/scalastyle.rb' + +# Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). +Lint/RedundantCopDisableDirective: + Exclude: + - 'lib/overcommit/hook_runner.rb' + - 'lib/overcommit/printer.rb' + +# Offense count: 1 +# Configuration parameters: CountComments, Max, CountAsOne. +Metrics/ClassLength: + Exclude: + - 'lib/overcommit/utils.rb' + +# Offense count: 2 +# Configuration parameters: AllowedMethods, AllowedPatterns, Max. +Metrics/CyclomaticComplexity: + Exclude: + - 'lib/overcommit/configuration.rb' + - 'lib/overcommit/hook_runner.rb' + +# Offense count: 3 +# Configuration parameters: AllowedMethods, AllowedPatterns, Max. +Metrics/PerceivedComplexity: + Exclude: + - 'lib/overcommit/configuration.rb' + - 'lib/overcommit/configuration_validator.rb' + - 'lib/overcommit/hook_runner.rb' + +# Offense count: 23 +# This cop supports unsafe autocorrection (--autocorrect-all). +Style/GlobalStdStream: + Exclude: + - 'bin/overcommit' + - 'lib/overcommit/hook/post_commit/git_guilt.rb' + - 'template-dir/hooks/commit-msg' + - 'template-dir/hooks/overcommit-hook' + - 'template-dir/hooks/post-checkout' + - 'template-dir/hooks/post-commit' + - 'template-dir/hooks/post-merge' + - 'template-dir/hooks/post-rewrite' + - 'template-dir/hooks/pre-commit' + - 'template-dir/hooks/pre-push' + - 'template-dir/hooks/pre-rebase' + - 'template-dir/hooks/prepare-commit-msg' + +# Offense count: 2 +# This cop supports unsafe autocorrection (--autocorrect-all). +Style/HashTransformValues: + Exclude: + - 'lib/overcommit/configuration.rb' + - 'lib/overcommit/configuration_validator.rb' + +# Offense count: 1 +# Configuration parameters: AllowedMethods. +# AllowedMethods: respond_to_missing? +Style/OptionalBooleanParameter: + Exclude: + - 'lib/overcommit/logger.rb' + +# Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). +Style/RedundantBegin: + Exclude: + - 'lib/overcommit/hook/prepare_commit_msg/replace_branch.rb' + - 'lib/overcommit/utils.rb' + +# Offense count: 10 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: SafeForConstants. +Style/RedundantFetchBlock: + Exclude: + - 'lib/overcommit/configuration.rb' + - 'lib/overcommit/configuration_validator.rb' + - 'lib/overcommit/hook/base.rb' + - 'lib/overcommit/hook/pre_commit/chamber_verification.rb' + - 'lib/overcommit/logger.rb' + - 'spec/support/shell_helpers.rb' + +# Offense count: 8 +# This cop supports safe autocorrection (--autocorrect). +Style/RedundantRegexpEscape: + Exclude: + - 'lib/overcommit/configuration.rb' + - 'lib/overcommit/hook/pre_commit/php_cs.rb' + - 'lib/overcommit/hook/pre_commit/php_lint.rb' + - 'lib/overcommit/hook/pre_commit/php_stan.rb' + +# Offense count: 15 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: Mode. +Style/StringConcatenation: + Exclude: + - 'lib/overcommit/hook/pre_commit/bundle_check.rb' + - 'lib/overcommit/hook_runner.rb' + - 'lib/overcommit/message_processor.rb' + - 'spec/integration/gemfile_option_spec.rb' + - 'spec/overcommit/hook/commit_msg/text_width_spec.rb' + - 'spec/overcommit/hook/prepare_commit_msg/base_spec.rb' + - 'spec/overcommit/message_processor_spec.rb' + - 'spec/spec_helper.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +Style/ZeroLengthPredicate: + Exclude: + - 'lib/overcommit/hook/pre_commit/ruby_syntax.rb' diff --git a/Gemfile b/Gemfile index ff22be0c..53b13c7f 100644 --- a/Gemfile +++ b/Gemfile @@ -11,7 +11,7 @@ gem 'rspec', '~> 3.0' gem 'simplecov', '~> 0.21.0' gem 'simplecov-lcov', '~> 0.8.0' -# Pin RuboCop for Travis builds. -gem 'rubocop', '0.82.0' +# Pin RuboCop for CI builds +gem 'rubocop', '1.59.0' gem 'ffi' if Gem.win_platform? diff --git a/spec/overcommit/hook/pre_commit/phpcs_fixer_spec.rb b/spec/overcommit/hook/pre_commit/phpcs_fixer_spec.rb index 33b0d7c1..a4b1e187 100644 --- a/spec/overcommit/hook/pre_commit/phpcs_fixer_spec.rb +++ b/spec/overcommit/hook/pre_commit/phpcs_fixer_spec.rb @@ -13,7 +13,7 @@ context 'when phpcs fixer exits successfully with fixed file' do before do - # rubocop:disable Metrics/LineLength + # rubocop:disable Layout/LineLength sample_output = [ 'Loaded config default.', 'Using cache file ".php_cs.cache".', @@ -24,7 +24,7 @@ 'Fixed all files in 0.001 seconds, 10.000 MB memory used', '', ].join("\n") - # rubocop:enable Metrics/LineLength + # rubocop:enable Layout/LineLength result = double('result') result.stub(:status).and_return(0) @@ -38,7 +38,7 @@ context 'when phpcs fixer exits successfully with no file to fix' do before do - # rubocop:disable Metrics/LineLength + # rubocop:disable Layout/LineLength sample_output = [ 'Loaded config default.', 'Using cache file ".php_cs.cache".', @@ -46,7 +46,7 @@ 'Legend: ?-unknown, I-invalid file syntax, file ignored, S-Skipped, .-no changes, F-fixed, E-error', '', ].join("\n") - # rubocop:enable Metrics/LineLength + # rubocop:enable Layout/LineLength result = double('result') result.stub(:status).and_return(0) @@ -60,7 +60,7 @@ context 'when phpcs exits unsuccessfully' do before do - # rubocop:disable Metrics/LineLength + # rubocop:disable Layout/LineLength sample_output = [ 'Loaded config default.', 'Using cache file ".php_cs.cache".', @@ -72,7 +72,7 @@ ' 1) /home/damien/Code/Rezdy/php/foo/broken.php', '', ].join("\n") - # rubocop:enable Metrics/LineLength + # rubocop:enable Layout/LineLength result = double('result') result.stub(:status).and_return(1) From bc1fec660e5c7c0cd83e2c8b3de8f02b55c0b367 Mon Sep 17 00:00:00 2001 From: Shane da Silva Date: Sun, 14 Jan 2024 18:17:08 -0800 Subject: [PATCH 05/10] Update branch for CI from `master` to `main` (#819) This was missed when we switched to using `main`. --- .github/workflows/lint.yml | 6 +++--- .github/workflows/tests.yml | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index b1879f09..8b23cbab 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,9 +1,9 @@ name: Lint on: push: - branches: [master] + branches: [main] pull_request: - branches: [master] + branches: [main] jobs: overcommit: @@ -16,7 +16,7 @@ jobs: - name: Set up Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: 2.7 + ruby-version: 3.3 bundler-cache: true - name: Prepare environment diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 416afe34..26c20dd1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,9 +1,9 @@ name: Tests on: push: - branches: [master] + branches: [main] pull_request: - branches: [master] + branches: [main] jobs: rspec: From 2dd1eb9e3fbaaf3693b9a32414fb8cf7706c9db9 Mon Sep 17 00:00:00 2001 From: Patrik Ragnarsson Date: Wed, 17 Jan 2024 00:02:11 +0100 Subject: [PATCH 06/10] Allow childprocess 5 (#820) I think it only brings improvements: https://github.com/enkessler/childprocess/releases/tag/v5.0.0 --- overcommit.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/overcommit.gemspec b/overcommit.gemspec index ef9f24fc..8bc70845 100644 --- a/overcommit.gemspec +++ b/overcommit.gemspec @@ -27,7 +27,7 @@ Gem::Specification.new do |s| s.required_ruby_version = '>= 2.4' - s.add_dependency 'childprocess', '>= 0.6.3', '< 5' + s.add_dependency 'childprocess', '>= 0.6.3', '< 6' s.add_dependency 'iniparse', '~> 1.4' s.add_dependency 'rexml', '~> 3.2' end From f190f24b748ba04ed5199c9ac8ca12557237800c Mon Sep 17 00:00:00 2001 From: Shane da Silva Date: Tue, 16 Jan 2024 15:05:50 -0800 Subject: [PATCH 07/10] Cut version 0.62.0 (#821) --- CHANGELOG.md | 4 ++++ lib/overcommit/version.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc14f3f1..5953a7c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Overcommit Changelog +## 0.62.0 + +* Allow version 5 of `childprocess` gem dependency + ## 0.61.0 * Allow `ReplaceBranch` to use `skip_if` diff --git a/lib/overcommit/version.rb b/lib/overcommit/version.rb index 0646ce48..f6805668 100644 --- a/lib/overcommit/version.rb +++ b/lib/overcommit/version.rb @@ -2,5 +2,5 @@ # Defines the gem version. module Overcommit - VERSION = '0.61.0' + VERSION = '0.62.0' end From 607ce057b760b697dc63623e7b7dc06a79316eab Mon Sep 17 00:00:00 2001 From: benmelz Date: Sat, 24 Feb 2024 18:50:30 -0500 Subject: [PATCH 08/10] Get suite running smoothly again (#824) Am planning on proposing/implementing a new feature, but first I noticed that there are a number of failing specs on main, so I figured I would start with that. As written, this includes four main adjustments, two of which might actually be bugfixes: - one spec was hanging indefinitely for me locally on a `Thread.join` call - explicitly capturing the child threads and joining them directly fixed it (might be machine dependent?) - when an encoding is specified, the rails schema up to date hook was passing arguments incorrectly (kwarg containing `encoding` was being interpreted as the `length` positional arg) (possible bug) - many specs were attempting to create file submodules without the `protocol.file.allow=always` config option causing failure - alias detection for amendment appeared to be broken, due to regexp incompatibilities between ruby/git (git wasn't properly parsing `\s` in the value matcher for `git config --regexp [key] [value]` command), so moved that matching into ruby (possible bug, also maybe machine/git build opt dependent) - dropped ruby 2.6 from the test matrix - it appears that it's far enough EOL that github has trouble even setting it up. I can attempt to add it back/get it working, but I figured it might be time to ditch it *I don't have a windows machine, so I'm not gonna be much help with those CI builds (should note fails appear unrelated to anything I've done here). --- .github/workflows/tests.yml | 1 - .../pre_commit/rails_schema_up_to_date.rb | 4 +-- .../helpers/file_modifications.rb | 31 ++++++++++++------- spec/overcommit/git_repo_spec.rb | 22 +++++++------ .../hook/prepare_commit_msg/base_spec.rb | 4 +-- .../hook_context/commit_msg_spec.rb | 10 +++--- .../hook_context/post_checkout_spec.rb | 2 +- .../hook_context/post_commit_spec.rb | 2 +- .../hook_context/post_merge_spec.rb | 2 +- .../hook_context/post_rewrite_spec.rb | 3 +- .../hook_context/pre_commit_spec.rb | 10 +++--- spec/overcommit/hook_context/run_all_spec.rb | 3 +- spec/overcommit/installer_spec.rb | 2 +- 13 files changed, 54 insertions(+), 42 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 26c20dd1..71a83ba6 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -14,7 +14,6 @@ jobs: fail-fast: false matrix: ruby-version: - - '2.6' - '2.7' - '3.0' - '3.1' diff --git a/lib/overcommit/hook/pre_commit/rails_schema_up_to_date.rb b/lib/overcommit/hook/pre_commit/rails_schema_up_to_date.rb index dafd31a1..1f2de970 100644 --- a/lib/overcommit/hook/pre_commit/rails_schema_up_to_date.rb +++ b/lib/overcommit/hook/pre_commit/rails_schema_up_to_date.rb @@ -35,7 +35,7 @@ def run # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplex private def encoding - return unless @config.key?('encoding') + return {} unless @config.key?('encoding') { encoding: @config['encoding'] }.compact end @@ -53,7 +53,7 @@ def schema_files end def schema - @schema ||= schema_files.map { |file| File.read(file, encoding) }.join + @schema ||= schema_files.map { |file| File.read(file, **encoding) }.join @schema.tr('_', '') end diff --git a/lib/overcommit/hook_context/helpers/file_modifications.rb b/lib/overcommit/hook_context/helpers/file_modifications.rb index 00aaccc8..8d221ddc 100644 --- a/lib/overcommit/hook_context/helpers/file_modifications.rb +++ b/lib/overcommit/hook_context/helpers/file_modifications.rb @@ -12,7 +12,7 @@ def amendment? cmd = Overcommit::Utils.parent_command return unless cmd - amend_pattern = 'commit(\s.*)?\s--amend(\s|$)' + amend_pattern = /commit(\s.*)?\s--amend/ # Since the ps command can return invalid byte sequences for commands # containing unicode characters, we replace the offending characters, @@ -24,18 +24,11 @@ def amendment? encode('UTF-8') end - return @amendment if - # True if the command is a commit with the --amend flag - @amendment = !(/\s#{amend_pattern}/ =~ cmd).nil? + # True if the command is a commit with the --amend flag + return @amendment if @amendment = cmd.match?(amend_pattern) # Check for git aliases that call `commit --amend` - `git config --get-regexp "^alias\\." "#{amend_pattern}"`. - scan(/alias\.([-\w]+)/). # Extract the alias - each do |match| - return @amendment if - # True if the command uses a git alias for `commit --amend` - @amendment = !(/git(\.exe)?\s+#{match[0]}/ =~ cmd).nil? - end + return @amendment if @amendment = command_is_amend_alias?(cmd, amend_pattern) @amendment end @@ -74,6 +67,22 @@ def modified_lines_in_file(file) end @modified_lines[file] end + + private + + def command_is_amend_alias?(cmd, amend_pattern) + `git config --get-regexp "^alias"`.split("\n").each do |alias_def| + alias_map = alias_def.match /alias\.(?[-\w]+)\s+(?.+)/ + next unless alias_map + + alias_from_match = alias_map[:from].match? amend_pattern + alias_to_match = cmd.match? /git(\.exe)?\s+#{alias_map[:to]}/ + + # True if the command uses a git alias for `commit --amend` + return true if @amendment = alias_from_match && alias_to_match + end + false + end end end end diff --git a/spec/overcommit/git_repo_spec.rb b/spec/overcommit/git_repo_spec.rb index 128737c3..08f3b585 100644 --- a/spec/overcommit/git_repo_spec.rb +++ b/spec/overcommit/git_repo_spec.rb @@ -24,12 +24,13 @@ end submodule = repo do - `git submodule add #{nested_submodule} nested-sub 2>&1 > #{File::NULL}` + git_config = '-c protocol.file.allow=always' + `git #{git_config} submodule add #{nested_submodule} nested-sub 2>&1 > #{File::NULL}` `git commit -m "Add nested submodule"` end repo do - `git submodule add #{submodule} sub 2>&1 > #{File::NULL}` + `git -c protocol.file.allow=always submodule add #{submodule} sub 2>&1 > #{File::NULL}` example.run end end @@ -150,7 +151,7 @@ end before do - `git submodule add #{submodule} sub 2>&1 > #{File::NULL}` + `git -c protocol.file.allow=always submodule add #{submodule} sub 2>&1 > #{File::NULL}` end it { should_not include File.expand_path('sub') } @@ -178,7 +179,8 @@ `git commit --allow-empty -m "Submodule commit"` end - `git submodule add #{submodule} #{submodule_dir} 2>&1 > #{File::NULL}` + git_config = '-c protocol.file.allow=always' + `git #{git_config} submodule add #{submodule} #{submodule_dir} 2>&1 > #{File::NULL}` `git commit -m "Add submodule"` end @@ -282,7 +284,7 @@ touch 'tracked' `git add tracked` `git commit -m "Initial commit"` - `git submodule add #{submodule} sub 2>&1 > #{File::NULL}` + `git -c protocol.file.allow=always submodule add #{submodule} sub 2>&1 > #{File::NULL}` touch 'staged' `git add staged` example.run @@ -327,7 +329,7 @@ end repo do - `git submodule add #{submodule} sub-repo 2>&1 > #{File::NULL}` + `git -c protocol.file.allow=always submodule add #{submodule} sub-repo 2>&1 > #{File::NULL}` `git commit -m "Initial commit"` example.run end @@ -343,7 +345,8 @@ `git commit --allow-empty -m "Another submodule"` end - `git submodule add #{another_submodule} another-sub-repo 2>&1 > #{File::NULL}` + git_config = '-c protocol.file.allow=always' + `git #{git_config} submodule add #{another_submodule} another-sub-repo 2>&1 > #{File::NULL}` end it { should be_empty } @@ -365,11 +368,12 @@ context 'when there are multiple submodule removals staged' do before do - another_submodule = repo do + another_submod = repo do `git commit --allow-empty -m "Another submodule"` end - `git submodule add #{another_submodule} yet-another-sub-repo 2>&1 > #{File::NULL}` + git_conf = '-c protocol.file.allow=always' + `git #{git_conf} submodule add #{another_submod} yet-another-sub-repo 2>&1 > #{File::NULL}` `git commit -m "Add yet another submodule"` `git rm sub-repo` `git rm yet-another-sub-repo` diff --git a/spec/overcommit/hook/prepare_commit_msg/base_spec.rb b/spec/overcommit/hook/prepare_commit_msg/base_spec.rb index 616d6b8e..ef635a48 100644 --- a/spec/overcommit/hook/prepare_commit_msg/base_spec.rb +++ b/spec/overcommit/hook/prepare_commit_msg/base_spec.rb @@ -38,9 +38,7 @@ contents + "bravo\n" end end - Thread.new { hook_1.run } - Thread.new { hook_2.run } - Thread.list.each { |t| t.join unless t == Thread.current } + [Thread.new { hook_1.run }, Thread.new { hook_2.run }].each(&:join) expect(File.read(tempfile)).to match(/alpha\n#{initial_content}bravo\n/m) end end diff --git a/spec/overcommit/hook_context/commit_msg_spec.rb b/spec/overcommit/hook_context/commit_msg_spec.rb index 2aa68516..058f1508 100644 --- a/spec/overcommit/hook_context/commit_msg_spec.rb +++ b/spec/overcommit/hook_context/commit_msg_spec.rb @@ -298,7 +298,7 @@ end repo do - `git submodule add #{submodule} sub > #{File::NULL} 2>&1` + `git -c protocol.file.allow=always submodule add #{submodule} sub > #{File::NULL} 2>&1` `git commit -m "Add submodule"` echo('Hello World', 'sub/submodule-file') `git submodule foreach "git add submodule-file" < #{File::NULL}` @@ -474,7 +474,7 @@ end repo do - `git submodule add #{submodule} sub > #{File::NULL} 2>&1` + `git -c protocol.file.allow=always submodule add #{submodule} sub > #{File::NULL} 2>&1` `git commit -m "Add submodule"` echo('Hello World', 'sub/submodule-file') `git submodule foreach "git add submodule-file" < #{File::NULL}` @@ -500,7 +500,7 @@ end repo do - `git submodule add #{submodule} sub > #{File::NULL} 2>&1` + `git -c protocol.file.allow=always submodule add #{submodule} sub > #{File::NULL} 2>&1` `git commit -m "Add submodule"` echo('Hello World', 'sub/submodule-file') `git submodule foreach "git add submodule-file" < #{File::NULL}` @@ -532,7 +532,7 @@ end repo do - `git submodule add #{submodule} sub > #{File::NULL} 2>&1` + `git -c protocol.file.allow=always submodule add #{submodule} sub > #{File::NULL} 2>&1` `git commit -m "Add submodule"` `git rm sub` example.run @@ -561,7 +561,7 @@ end repo do - `git submodule add #{submodule} test-sub 2>&1 > #{File::NULL}` + `git -c protocol.file.allow=always submodule add #{submodule} test-sub 2>&1 > #{File::NULL}` expect(subject).to_not include File.expand_path('test-sub') end end diff --git a/spec/overcommit/hook_context/post_checkout_spec.rb b/spec/overcommit/hook_context/post_checkout_spec.rb index 50657c37..df1dccd2 100644 --- a/spec/overcommit/hook_context/post_checkout_spec.rb +++ b/spec/overcommit/hook_context/post_checkout_spec.rb @@ -67,7 +67,7 @@ repo do `git commit --allow-empty -m "Initial commit"` - `git submodule add #{submodule} test-sub 2>&1 > #{File::NULL}` + `git -c protocol.file.allow=always submodule add #{submodule} test-sub 2>&1 > #{File::NULL}` `git commit -m "Add submodule"` expect(subject).to_not include File.expand_path('test-sub') end diff --git a/spec/overcommit/hook_context/post_commit_spec.rb b/spec/overcommit/hook_context/post_commit_spec.rb index 81758256..5322a1f2 100644 --- a/spec/overcommit/hook_context/post_commit_spec.rb +++ b/spec/overcommit/hook_context/post_commit_spec.rb @@ -20,7 +20,7 @@ end repo do - `git submodule add #{submodule} test-sub 2>&1 > #{File::NULL}` + `git -c protocol.file.allow=always submodule add #{submodule} test-sub 2>&1 > #{File::NULL}` `git commit -m "Initial commit"` expect(subject).to_not include File.expand_path('test-sub') end diff --git a/spec/overcommit/hook_context/post_merge_spec.rb b/spec/overcommit/hook_context/post_merge_spec.rb index aa89fa82..0621b695 100644 --- a/spec/overcommit/hook_context/post_merge_spec.rb +++ b/spec/overcommit/hook_context/post_merge_spec.rb @@ -94,7 +94,7 @@ repo do `git commit --allow-empty -m "Initial commit"` `git checkout -b child > #{File::NULL} 2>&1` - `git submodule add #{submodule} test-sub 2>&1 > #{File::NULL}` + `git -c protocol.file.allow=always submodule add #{submodule} test-sub 2>&1 > #{File::NULL}` `git commit -m "Add submodule"` `git checkout master > #{File::NULL} 2>&1` `git merge --no-ff --no-edit child` diff --git a/spec/overcommit/hook_context/post_rewrite_spec.rb b/spec/overcommit/hook_context/post_rewrite_spec.rb index d2f18f6e..0d510c4a 100644 --- a/spec/overcommit/hook_context/post_rewrite_spec.rb +++ b/spec/overcommit/hook_context/post_rewrite_spec.rb @@ -101,8 +101,9 @@ end repo do + git_config = '-c protocol.file.allow=always' `git commit --allow-empty -m "Initial commit"` - `git submodule add #{submodule} test-sub 2>&1 > #{File::NULL}` + `git #{git_config} submodule add #{submodule} test-sub 2>&1 > #{File::NULL}` `git commit --amend -m "Add submodule"` expect(subject).to_not include File.expand_path('test-sub') end diff --git a/spec/overcommit/hook_context/pre_commit_spec.rb b/spec/overcommit/hook_context/pre_commit_spec.rb index dae42e66..719982a1 100644 --- a/spec/overcommit/hook_context/pre_commit_spec.rb +++ b/spec/overcommit/hook_context/pre_commit_spec.rb @@ -207,7 +207,7 @@ end repo do - `git submodule add #{submodule} sub > #{File::NULL} 2>&1` + `git -c protocol.file.allow=always submodule add #{submodule} sub > #{File::NULL} 2>&1` `git commit -m "Add submodule"` echo('Hello World', 'sub/submodule-file') `git submodule foreach "git add submodule-file" < #{File::NULL}` @@ -383,7 +383,7 @@ end repo do - `git submodule add #{submodule} sub > #{File::NULL} 2>&1` + `git -c protocol.file.allow=always submodule add #{submodule} sub > #{File::NULL} 2>&1` `git commit -m "Add submodule"` echo('Hello World', 'sub/submodule-file') `git submodule foreach "git add submodule-file" < #{File::NULL}` @@ -409,7 +409,7 @@ end repo do - `git submodule add #{submodule} sub > #{File::NULL} 2>&1` + `git -c protocol.file.allow=always submodule add #{submodule} sub > #{File::NULL} 2>&1` `git commit -m "Add submodule"` echo('Hello World', 'sub/submodule-file') `git submodule foreach "git add submodule-file" < #{File::NULL}` @@ -441,7 +441,7 @@ end repo do - `git submodule add #{submodule} sub > #{File::NULL} 2>&1` + `git -c protocol.file.allow=always submodule add #{submodule} sub > #{File::NULL} 2>&1` `git commit -m "Add submodule"` `git rm sub` example.run @@ -470,7 +470,7 @@ end repo do - `git submodule add #{submodule} test-sub 2>&1 > #{File::NULL}` + `git -c protocol.file.allow=always submodule add #{submodule} test-sub 2>&1 > #{File::NULL}` expect(subject).to_not include File.expand_path('test-sub') end end diff --git a/spec/overcommit/hook_context/run_all_spec.rb b/spec/overcommit/hook_context/run_all_spec.rb index 516fb70b..c6696edc 100644 --- a/spec/overcommit/hook_context/run_all_spec.rb +++ b/spec/overcommit/hook_context/run_all_spec.rb @@ -46,7 +46,8 @@ end repo do - `git submodule add #{submodule} test-sub 2>&1 > #{File::NULL}` + git_config = '-c protocol.file.allow=always' + `git #{git_config} submodule add #{submodule} test-sub 2>&1 > #{File::NULL}` example.run end end diff --git a/spec/overcommit/installer_spec.rb b/spec/overcommit/installer_spec.rb index c7cfb05e..8739a70e 100644 --- a/spec/overcommit/installer_spec.rb +++ b/spec/overcommit/installer_spec.rb @@ -231,7 +231,7 @@ def hook_files_installed?(hooks_dir) context 'which has an external git dir' do let(:submodule) { File.join(target, 'submodule') } before do - system 'git', 'submodule', 'add', target, 'submodule', + system 'git', '-c', 'protocol.file.allow=always', 'submodule', 'add', target, 'submodule', chdir: target, out: :close, err: :close end let(:submodule_git_file) { File.join(submodule, '.git') } From 65e211451816710afe3b530d2e319db08f2c2f1b Mon Sep 17 00:00:00 2001 From: Shane da Silva Date: Sat, 24 Feb 2024 15:57:56 -0800 Subject: [PATCH 09/10] Revert "Get suite running smoothly again (#824)" (#840) This reverts commit 607ce057b760b697dc63623e7b7dc06a79316eab. Going to try to merge a different branch. --- .github/workflows/tests.yml | 1 + .../pre_commit/rails_schema_up_to_date.rb | 4 +-- .../helpers/file_modifications.rb | 31 +++++++------------ spec/overcommit/git_repo_spec.rb | 22 ++++++------- .../hook/prepare_commit_msg/base_spec.rb | 4 ++- .../hook_context/commit_msg_spec.rb | 10 +++--- .../hook_context/post_checkout_spec.rb | 2 +- .../hook_context/post_commit_spec.rb | 2 +- .../hook_context/post_merge_spec.rb | 2 +- .../hook_context/post_rewrite_spec.rb | 3 +- .../hook_context/pre_commit_spec.rb | 10 +++--- spec/overcommit/hook_context/run_all_spec.rb | 3 +- spec/overcommit/installer_spec.rb | 2 +- 13 files changed, 42 insertions(+), 54 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 71a83ba6..26c20dd1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -14,6 +14,7 @@ jobs: fail-fast: false matrix: ruby-version: + - '2.6' - '2.7' - '3.0' - '3.1' diff --git a/lib/overcommit/hook/pre_commit/rails_schema_up_to_date.rb b/lib/overcommit/hook/pre_commit/rails_schema_up_to_date.rb index 1f2de970..dafd31a1 100644 --- a/lib/overcommit/hook/pre_commit/rails_schema_up_to_date.rb +++ b/lib/overcommit/hook/pre_commit/rails_schema_up_to_date.rb @@ -35,7 +35,7 @@ def run # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplex private def encoding - return {} unless @config.key?('encoding') + return unless @config.key?('encoding') { encoding: @config['encoding'] }.compact end @@ -53,7 +53,7 @@ def schema_files end def schema - @schema ||= schema_files.map { |file| File.read(file, **encoding) }.join + @schema ||= schema_files.map { |file| File.read(file, encoding) }.join @schema.tr('_', '') end diff --git a/lib/overcommit/hook_context/helpers/file_modifications.rb b/lib/overcommit/hook_context/helpers/file_modifications.rb index 8d221ddc..00aaccc8 100644 --- a/lib/overcommit/hook_context/helpers/file_modifications.rb +++ b/lib/overcommit/hook_context/helpers/file_modifications.rb @@ -12,7 +12,7 @@ def amendment? cmd = Overcommit::Utils.parent_command return unless cmd - amend_pattern = /commit(\s.*)?\s--amend/ + amend_pattern = 'commit(\s.*)?\s--amend(\s|$)' # Since the ps command can return invalid byte sequences for commands # containing unicode characters, we replace the offending characters, @@ -24,11 +24,18 @@ def amendment? encode('UTF-8') end - # True if the command is a commit with the --amend flag - return @amendment if @amendment = cmd.match?(amend_pattern) + return @amendment if + # True if the command is a commit with the --amend flag + @amendment = !(/\s#{amend_pattern}/ =~ cmd).nil? # Check for git aliases that call `commit --amend` - return @amendment if @amendment = command_is_amend_alias?(cmd, amend_pattern) + `git config --get-regexp "^alias\\." "#{amend_pattern}"`. + scan(/alias\.([-\w]+)/). # Extract the alias + each do |match| + return @amendment if + # True if the command uses a git alias for `commit --amend` + @amendment = !(/git(\.exe)?\s+#{match[0]}/ =~ cmd).nil? + end @amendment end @@ -67,22 +74,6 @@ def modified_lines_in_file(file) end @modified_lines[file] end - - private - - def command_is_amend_alias?(cmd, amend_pattern) - `git config --get-regexp "^alias"`.split("\n").each do |alias_def| - alias_map = alias_def.match /alias\.(?[-\w]+)\s+(?.+)/ - next unless alias_map - - alias_from_match = alias_map[:from].match? amend_pattern - alias_to_match = cmd.match? /git(\.exe)?\s+#{alias_map[:to]}/ - - # True if the command uses a git alias for `commit --amend` - return true if @amendment = alias_from_match && alias_to_match - end - false - end end end end diff --git a/spec/overcommit/git_repo_spec.rb b/spec/overcommit/git_repo_spec.rb index 08f3b585..128737c3 100644 --- a/spec/overcommit/git_repo_spec.rb +++ b/spec/overcommit/git_repo_spec.rb @@ -24,13 +24,12 @@ end submodule = repo do - git_config = '-c protocol.file.allow=always' - `git #{git_config} submodule add #{nested_submodule} nested-sub 2>&1 > #{File::NULL}` + `git submodule add #{nested_submodule} nested-sub 2>&1 > #{File::NULL}` `git commit -m "Add nested submodule"` end repo do - `git -c protocol.file.allow=always submodule add #{submodule} sub 2>&1 > #{File::NULL}` + `git submodule add #{submodule} sub 2>&1 > #{File::NULL}` example.run end end @@ -151,7 +150,7 @@ end before do - `git -c protocol.file.allow=always submodule add #{submodule} sub 2>&1 > #{File::NULL}` + `git submodule add #{submodule} sub 2>&1 > #{File::NULL}` end it { should_not include File.expand_path('sub') } @@ -179,8 +178,7 @@ `git commit --allow-empty -m "Submodule commit"` end - git_config = '-c protocol.file.allow=always' - `git #{git_config} submodule add #{submodule} #{submodule_dir} 2>&1 > #{File::NULL}` + `git submodule add #{submodule} #{submodule_dir} 2>&1 > #{File::NULL}` `git commit -m "Add submodule"` end @@ -284,7 +282,7 @@ touch 'tracked' `git add tracked` `git commit -m "Initial commit"` - `git -c protocol.file.allow=always submodule add #{submodule} sub 2>&1 > #{File::NULL}` + `git submodule add #{submodule} sub 2>&1 > #{File::NULL}` touch 'staged' `git add staged` example.run @@ -329,7 +327,7 @@ end repo do - `git -c protocol.file.allow=always submodule add #{submodule} sub-repo 2>&1 > #{File::NULL}` + `git submodule add #{submodule} sub-repo 2>&1 > #{File::NULL}` `git commit -m "Initial commit"` example.run end @@ -345,8 +343,7 @@ `git commit --allow-empty -m "Another submodule"` end - git_config = '-c protocol.file.allow=always' - `git #{git_config} submodule add #{another_submodule} another-sub-repo 2>&1 > #{File::NULL}` + `git submodule add #{another_submodule} another-sub-repo 2>&1 > #{File::NULL}` end it { should be_empty } @@ -368,12 +365,11 @@ context 'when there are multiple submodule removals staged' do before do - another_submod = repo do + another_submodule = repo do `git commit --allow-empty -m "Another submodule"` end - git_conf = '-c protocol.file.allow=always' - `git #{git_conf} submodule add #{another_submod} yet-another-sub-repo 2>&1 > #{File::NULL}` + `git submodule add #{another_submodule} yet-another-sub-repo 2>&1 > #{File::NULL}` `git commit -m "Add yet another submodule"` `git rm sub-repo` `git rm yet-another-sub-repo` diff --git a/spec/overcommit/hook/prepare_commit_msg/base_spec.rb b/spec/overcommit/hook/prepare_commit_msg/base_spec.rb index ef635a48..616d6b8e 100644 --- a/spec/overcommit/hook/prepare_commit_msg/base_spec.rb +++ b/spec/overcommit/hook/prepare_commit_msg/base_spec.rb @@ -38,7 +38,9 @@ contents + "bravo\n" end end - [Thread.new { hook_1.run }, Thread.new { hook_2.run }].each(&:join) + Thread.new { hook_1.run } + Thread.new { hook_2.run } + Thread.list.each { |t| t.join unless t == Thread.current } expect(File.read(tempfile)).to match(/alpha\n#{initial_content}bravo\n/m) end end diff --git a/spec/overcommit/hook_context/commit_msg_spec.rb b/spec/overcommit/hook_context/commit_msg_spec.rb index 058f1508..2aa68516 100644 --- a/spec/overcommit/hook_context/commit_msg_spec.rb +++ b/spec/overcommit/hook_context/commit_msg_spec.rb @@ -298,7 +298,7 @@ end repo do - `git -c protocol.file.allow=always submodule add #{submodule} sub > #{File::NULL} 2>&1` + `git submodule add #{submodule} sub > #{File::NULL} 2>&1` `git commit -m "Add submodule"` echo('Hello World', 'sub/submodule-file') `git submodule foreach "git add submodule-file" < #{File::NULL}` @@ -474,7 +474,7 @@ end repo do - `git -c protocol.file.allow=always submodule add #{submodule} sub > #{File::NULL} 2>&1` + `git submodule add #{submodule} sub > #{File::NULL} 2>&1` `git commit -m "Add submodule"` echo('Hello World', 'sub/submodule-file') `git submodule foreach "git add submodule-file" < #{File::NULL}` @@ -500,7 +500,7 @@ end repo do - `git -c protocol.file.allow=always submodule add #{submodule} sub > #{File::NULL} 2>&1` + `git submodule add #{submodule} sub > #{File::NULL} 2>&1` `git commit -m "Add submodule"` echo('Hello World', 'sub/submodule-file') `git submodule foreach "git add submodule-file" < #{File::NULL}` @@ -532,7 +532,7 @@ end repo do - `git -c protocol.file.allow=always submodule add #{submodule} sub > #{File::NULL} 2>&1` + `git submodule add #{submodule} sub > #{File::NULL} 2>&1` `git commit -m "Add submodule"` `git rm sub` example.run @@ -561,7 +561,7 @@ end repo do - `git -c protocol.file.allow=always submodule add #{submodule} test-sub 2>&1 > #{File::NULL}` + `git submodule add #{submodule} test-sub 2>&1 > #{File::NULL}` expect(subject).to_not include File.expand_path('test-sub') end end diff --git a/spec/overcommit/hook_context/post_checkout_spec.rb b/spec/overcommit/hook_context/post_checkout_spec.rb index df1dccd2..50657c37 100644 --- a/spec/overcommit/hook_context/post_checkout_spec.rb +++ b/spec/overcommit/hook_context/post_checkout_spec.rb @@ -67,7 +67,7 @@ repo do `git commit --allow-empty -m "Initial commit"` - `git -c protocol.file.allow=always submodule add #{submodule} test-sub 2>&1 > #{File::NULL}` + `git submodule add #{submodule} test-sub 2>&1 > #{File::NULL}` `git commit -m "Add submodule"` expect(subject).to_not include File.expand_path('test-sub') end diff --git a/spec/overcommit/hook_context/post_commit_spec.rb b/spec/overcommit/hook_context/post_commit_spec.rb index 5322a1f2..81758256 100644 --- a/spec/overcommit/hook_context/post_commit_spec.rb +++ b/spec/overcommit/hook_context/post_commit_spec.rb @@ -20,7 +20,7 @@ end repo do - `git -c protocol.file.allow=always submodule add #{submodule} test-sub 2>&1 > #{File::NULL}` + `git submodule add #{submodule} test-sub 2>&1 > #{File::NULL}` `git commit -m "Initial commit"` expect(subject).to_not include File.expand_path('test-sub') end diff --git a/spec/overcommit/hook_context/post_merge_spec.rb b/spec/overcommit/hook_context/post_merge_spec.rb index 0621b695..aa89fa82 100644 --- a/spec/overcommit/hook_context/post_merge_spec.rb +++ b/spec/overcommit/hook_context/post_merge_spec.rb @@ -94,7 +94,7 @@ repo do `git commit --allow-empty -m "Initial commit"` `git checkout -b child > #{File::NULL} 2>&1` - `git -c protocol.file.allow=always submodule add #{submodule} test-sub 2>&1 > #{File::NULL}` + `git submodule add #{submodule} test-sub 2>&1 > #{File::NULL}` `git commit -m "Add submodule"` `git checkout master > #{File::NULL} 2>&1` `git merge --no-ff --no-edit child` diff --git a/spec/overcommit/hook_context/post_rewrite_spec.rb b/spec/overcommit/hook_context/post_rewrite_spec.rb index 0d510c4a..d2f18f6e 100644 --- a/spec/overcommit/hook_context/post_rewrite_spec.rb +++ b/spec/overcommit/hook_context/post_rewrite_spec.rb @@ -101,9 +101,8 @@ end repo do - git_config = '-c protocol.file.allow=always' `git commit --allow-empty -m "Initial commit"` - `git #{git_config} submodule add #{submodule} test-sub 2>&1 > #{File::NULL}` + `git submodule add #{submodule} test-sub 2>&1 > #{File::NULL}` `git commit --amend -m "Add submodule"` expect(subject).to_not include File.expand_path('test-sub') end diff --git a/spec/overcommit/hook_context/pre_commit_spec.rb b/spec/overcommit/hook_context/pre_commit_spec.rb index 719982a1..dae42e66 100644 --- a/spec/overcommit/hook_context/pre_commit_spec.rb +++ b/spec/overcommit/hook_context/pre_commit_spec.rb @@ -207,7 +207,7 @@ end repo do - `git -c protocol.file.allow=always submodule add #{submodule} sub > #{File::NULL} 2>&1` + `git submodule add #{submodule} sub > #{File::NULL} 2>&1` `git commit -m "Add submodule"` echo('Hello World', 'sub/submodule-file') `git submodule foreach "git add submodule-file" < #{File::NULL}` @@ -383,7 +383,7 @@ end repo do - `git -c protocol.file.allow=always submodule add #{submodule} sub > #{File::NULL} 2>&1` + `git submodule add #{submodule} sub > #{File::NULL} 2>&1` `git commit -m "Add submodule"` echo('Hello World', 'sub/submodule-file') `git submodule foreach "git add submodule-file" < #{File::NULL}` @@ -409,7 +409,7 @@ end repo do - `git -c protocol.file.allow=always submodule add #{submodule} sub > #{File::NULL} 2>&1` + `git submodule add #{submodule} sub > #{File::NULL} 2>&1` `git commit -m "Add submodule"` echo('Hello World', 'sub/submodule-file') `git submodule foreach "git add submodule-file" < #{File::NULL}` @@ -441,7 +441,7 @@ end repo do - `git -c protocol.file.allow=always submodule add #{submodule} sub > #{File::NULL} 2>&1` + `git submodule add #{submodule} sub > #{File::NULL} 2>&1` `git commit -m "Add submodule"` `git rm sub` example.run @@ -470,7 +470,7 @@ end repo do - `git -c protocol.file.allow=always submodule add #{submodule} test-sub 2>&1 > #{File::NULL}` + `git submodule add #{submodule} test-sub 2>&1 > #{File::NULL}` expect(subject).to_not include File.expand_path('test-sub') end end diff --git a/spec/overcommit/hook_context/run_all_spec.rb b/spec/overcommit/hook_context/run_all_spec.rb index c6696edc..516fb70b 100644 --- a/spec/overcommit/hook_context/run_all_spec.rb +++ b/spec/overcommit/hook_context/run_all_spec.rb @@ -46,8 +46,7 @@ end repo do - git_config = '-c protocol.file.allow=always' - `git #{git_config} submodule add #{submodule} test-sub 2>&1 > #{File::NULL}` + `git submodule add #{submodule} test-sub 2>&1 > #{File::NULL}` example.run end end diff --git a/spec/overcommit/installer_spec.rb b/spec/overcommit/installer_spec.rb index 8739a70e..c7cfb05e 100644 --- a/spec/overcommit/installer_spec.rb +++ b/spec/overcommit/installer_spec.rb @@ -231,7 +231,7 @@ def hook_files_installed?(hooks_dir) context 'which has an external git dir' do let(:submodule) { File.join(target, 'submodule') } before do - system 'git', '-c', 'protocol.file.allow=always', 'submodule', 'add', target, 'submodule', + system 'git', 'submodule', 'add', target, 'submodule', chdir: target, out: :close, err: :close end let(:submodule_git_file) { File.join(submodule, '.git') } From 9c3d118b8f21ef8bf77d9a9dfc62a8051f8078d3 Mon Sep 17 00:00:00 2001 From: Sorin Guga Date: Sun, 25 Feb 2024 01:58:04 +0200 Subject: [PATCH 10/10] Green CI PoC (#833) Cherry-picked commits from #830, #831, #832, #835, #837 and #839. --- .github/workflows/lint.yml | 2 +- .github/workflows/tests.yml | 29 ++++++++----------- Gemfile | 6 +++- .../pre_commit/rails_schema_up_to_date.rb | 2 +- spec/overcommit/git_repo_spec.rb | 20 ++++++++----- .../hook/prepare_commit_msg/base_spec.rb | 6 ++-- .../hook_context/commit_msg_spec.rb | 10 +++---- .../hook_context/pre_commit_spec.rb | 10 +++---- spec/overcommit/installer_spec.rb | 4 +-- 9 files changed, 46 insertions(+), 43 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 8b23cbab..8cf8b4a0 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Ruby uses: ruby/setup-ruby@v1 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 26c20dd1..e9987e06 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -14,25 +14,20 @@ jobs: fail-fast: false matrix: ruby-version: - - '2.6' - - '2.7' - - '3.0' - - '3.1' - - '3.2' + - "2.6" + - "2.7" + - "3.0" + - "3.1" + - "3.2" os: - ubuntu - - windows - - # Tempfile behavior has changed on Ruby 3.1 such that tests - # fail with permission denied. Would welcome a PR with a fix. - exclude: - - ruby-version: '3.1' - os: windows - - ruby-version: '3.2' - os: windows + # At the moment of this commit various specs fail on Windows. + # Any contributor is welcome to fix them and enable the Windows build. + # Please see Issue #836 for more details. + # - windows steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Ruby ${{ matrix.ruby-version }} uses: ruby/setup-ruby@v1 @@ -47,7 +42,7 @@ jobs: bundle exec rspec - name: Code coverage reporting - uses: coverallsapp/github-action@master + uses: coverallsapp/github-action@v2 with: github-token: ${{ secrets.github_token }} flag-name: ruby${{ matrix.ruby-version }}-${{ matrix.os }} @@ -59,7 +54,7 @@ jobs: steps: - name: Finalize code coverage report - uses: coverallsapp/github-action@master + uses: coverallsapp/github-action@v2 with: github-token: ${{ secrets.github_token }} parallel-finished: true diff --git a/Gemfile b/Gemfile index 53b13c7f..49dc7923 100644 --- a/Gemfile +++ b/Gemfile @@ -12,6 +12,10 @@ gem 'simplecov', '~> 0.21.0' gem 'simplecov-lcov', '~> 0.8.0' # Pin RuboCop for CI builds -gem 'rubocop', '1.59.0' +if RUBY_VERSION < '2.7.0' + gem 'rubocop', '1.50.0' +else + gem 'rubocop', '1.59.0' +end gem 'ffi' if Gem.win_platform? diff --git a/lib/overcommit/hook/pre_commit/rails_schema_up_to_date.rb b/lib/overcommit/hook/pre_commit/rails_schema_up_to_date.rb index dafd31a1..61725074 100644 --- a/lib/overcommit/hook/pre_commit/rails_schema_up_to_date.rb +++ b/lib/overcommit/hook/pre_commit/rails_schema_up_to_date.rb @@ -53,7 +53,7 @@ def schema_files end def schema - @schema ||= schema_files.map { |file| File.read(file, encoding) }.join + @schema ||= schema_files.map { |file| File.read(file, **(encoding || {})) }.join @schema.tr('_', '') end diff --git a/spec/overcommit/git_repo_spec.rb b/spec/overcommit/git_repo_spec.rb index 128737c3..b887415b 100644 --- a/spec/overcommit/git_repo_spec.rb +++ b/spec/overcommit/git_repo_spec.rb @@ -24,12 +24,13 @@ end submodule = repo do - `git submodule add #{nested_submodule} nested-sub 2>&1 > #{File::NULL}` + `git -c protocol.file.allow=always submodule add \ + #{nested_submodule} nested-sub 2>&1 > #{File::NULL}` `git commit -m "Add nested submodule"` end repo do - `git submodule add #{submodule} sub 2>&1 > #{File::NULL}` + `git -c protocol.file.allow=always submodule add #{submodule} sub 2>&1 > #{File::NULL}` example.run end end @@ -150,7 +151,7 @@ end before do - `git submodule add #{submodule} sub 2>&1 > #{File::NULL}` + `git -c protocol.file.allow=always submodule add #{submodule} sub 2>&1 > #{File::NULL}` end it { should_not include File.expand_path('sub') } @@ -178,7 +179,8 @@ `git commit --allow-empty -m "Submodule commit"` end - `git submodule add #{submodule} #{submodule_dir} 2>&1 > #{File::NULL}` + `git -c protocol.file.allow=always submodule add \ + #{submodule} #{submodule_dir} 2>&1 > #{File::NULL}` `git commit -m "Add submodule"` end @@ -282,7 +284,7 @@ touch 'tracked' `git add tracked` `git commit -m "Initial commit"` - `git submodule add #{submodule} sub 2>&1 > #{File::NULL}` + `git -c protocol.file.allow=always submodule add #{submodule} sub 2>&1 > #{File::NULL}` touch 'staged' `git add staged` example.run @@ -327,7 +329,7 @@ end repo do - `git submodule add #{submodule} sub-repo 2>&1 > #{File::NULL}` + `git -c protocol.file.allow=always submodule add #{submodule} sub-repo 2>&1 > #{File::NULL}` `git commit -m "Initial commit"` example.run end @@ -343,7 +345,8 @@ `git commit --allow-empty -m "Another submodule"` end - `git submodule add #{another_submodule} another-sub-repo 2>&1 > #{File::NULL}` + `git -c protocol.file.allow=always submodule add \ + #{another_submodule} another-sub-repo 2>&1 > #{File::NULL}` end it { should be_empty } @@ -369,7 +372,8 @@ `git commit --allow-empty -m "Another submodule"` end - `git submodule add #{another_submodule} yet-another-sub-repo 2>&1 > #{File::NULL}` + `git -c protocol.file.allow=always submodule add \ + #{another_submodule} yet-another-sub-repo 2>&1 > #{File::NULL}` `git commit -m "Add yet another submodule"` `git rm sub-repo` `git rm yet-another-sub-repo` diff --git a/spec/overcommit/hook/prepare_commit_msg/base_spec.rb b/spec/overcommit/hook/prepare_commit_msg/base_spec.rb index 616d6b8e..873ed637 100644 --- a/spec/overcommit/hook/prepare_commit_msg/base_spec.rb +++ b/spec/overcommit/hook/prepare_commit_msg/base_spec.rb @@ -38,9 +38,9 @@ contents + "bravo\n" end end - Thread.new { hook_1.run } - Thread.new { hook_2.run } - Thread.list.each { |t| t.join unless t == Thread.current } + t1 = Thread.new { hook_1.run } + t2 = Thread.new { hook_2.run } + [t1, t2].each(&:join) expect(File.read(tempfile)).to match(/alpha\n#{initial_content}bravo\n/m) end end diff --git a/spec/overcommit/hook_context/commit_msg_spec.rb b/spec/overcommit/hook_context/commit_msg_spec.rb index 2aa68516..058f1508 100644 --- a/spec/overcommit/hook_context/commit_msg_spec.rb +++ b/spec/overcommit/hook_context/commit_msg_spec.rb @@ -298,7 +298,7 @@ end repo do - `git submodule add #{submodule} sub > #{File::NULL} 2>&1` + `git -c protocol.file.allow=always submodule add #{submodule} sub > #{File::NULL} 2>&1` `git commit -m "Add submodule"` echo('Hello World', 'sub/submodule-file') `git submodule foreach "git add submodule-file" < #{File::NULL}` @@ -474,7 +474,7 @@ end repo do - `git submodule add #{submodule} sub > #{File::NULL} 2>&1` + `git -c protocol.file.allow=always submodule add #{submodule} sub > #{File::NULL} 2>&1` `git commit -m "Add submodule"` echo('Hello World', 'sub/submodule-file') `git submodule foreach "git add submodule-file" < #{File::NULL}` @@ -500,7 +500,7 @@ end repo do - `git submodule add #{submodule} sub > #{File::NULL} 2>&1` + `git -c protocol.file.allow=always submodule add #{submodule} sub > #{File::NULL} 2>&1` `git commit -m "Add submodule"` echo('Hello World', 'sub/submodule-file') `git submodule foreach "git add submodule-file" < #{File::NULL}` @@ -532,7 +532,7 @@ end repo do - `git submodule add #{submodule} sub > #{File::NULL} 2>&1` + `git -c protocol.file.allow=always submodule add #{submodule} sub > #{File::NULL} 2>&1` `git commit -m "Add submodule"` `git rm sub` example.run @@ -561,7 +561,7 @@ end repo do - `git submodule add #{submodule} test-sub 2>&1 > #{File::NULL}` + `git -c protocol.file.allow=always submodule add #{submodule} test-sub 2>&1 > #{File::NULL}` expect(subject).to_not include File.expand_path('test-sub') end end diff --git a/spec/overcommit/hook_context/pre_commit_spec.rb b/spec/overcommit/hook_context/pre_commit_spec.rb index dae42e66..719982a1 100644 --- a/spec/overcommit/hook_context/pre_commit_spec.rb +++ b/spec/overcommit/hook_context/pre_commit_spec.rb @@ -207,7 +207,7 @@ end repo do - `git submodule add #{submodule} sub > #{File::NULL} 2>&1` + `git -c protocol.file.allow=always submodule add #{submodule} sub > #{File::NULL} 2>&1` `git commit -m "Add submodule"` echo('Hello World', 'sub/submodule-file') `git submodule foreach "git add submodule-file" < #{File::NULL}` @@ -383,7 +383,7 @@ end repo do - `git submodule add #{submodule} sub > #{File::NULL} 2>&1` + `git -c protocol.file.allow=always submodule add #{submodule} sub > #{File::NULL} 2>&1` `git commit -m "Add submodule"` echo('Hello World', 'sub/submodule-file') `git submodule foreach "git add submodule-file" < #{File::NULL}` @@ -409,7 +409,7 @@ end repo do - `git submodule add #{submodule} sub > #{File::NULL} 2>&1` + `git -c protocol.file.allow=always submodule add #{submodule} sub > #{File::NULL} 2>&1` `git commit -m "Add submodule"` echo('Hello World', 'sub/submodule-file') `git submodule foreach "git add submodule-file" < #{File::NULL}` @@ -441,7 +441,7 @@ end repo do - `git submodule add #{submodule} sub > #{File::NULL} 2>&1` + `git -c protocol.file.allow=always submodule add #{submodule} sub > #{File::NULL} 2>&1` `git commit -m "Add submodule"` `git rm sub` example.run @@ -470,7 +470,7 @@ end repo do - `git submodule add #{submodule} test-sub 2>&1 > #{File::NULL}` + `git -c protocol.file.allow=always submodule add #{submodule} test-sub 2>&1 > #{File::NULL}` expect(subject).to_not include File.expand_path('test-sub') end end diff --git a/spec/overcommit/installer_spec.rb b/spec/overcommit/installer_spec.rb index c7cfb05e..5283b2b6 100644 --- a/spec/overcommit/installer_spec.rb +++ b/spec/overcommit/installer_spec.rb @@ -231,8 +231,8 @@ def hook_files_installed?(hooks_dir) context 'which has an external git dir' do let(:submodule) { File.join(target, 'submodule') } before do - system 'git', 'submodule', 'add', target, 'submodule', - chdir: target, out: :close, err: :close + system 'git', '-c', 'protocol.file.allow=always', 'submodule', 'add', target, + 'submodule', chdir: target, out: :close, err: :close end let(:submodule_git_file) { File.join(submodule, '.git') } let(:submodule_git_dir) do