Skip to content

Commit

Permalink
Revert "Get suite running smoothly again (#824)" (#840)
Browse files Browse the repository at this point in the history
This reverts commit 607ce05.

Going to try to merge a different branch.
  • Loading branch information
sds authored Feb 24, 2024
1 parent 607ce05 commit 65e2114
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 54 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
fail-fast: false
matrix:
ruby-version:
- '2.6'
- '2.7'
- '3.0'
- '3.1'
Expand Down
4 changes: 2 additions & 2 deletions lib/overcommit/hook/pre_commit/rails_schema_up_to_date.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
31 changes: 11 additions & 20 deletions lib/overcommit/hook_context/helpers/file_modifications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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\.(?<to>[-\w]+)\s+(?<from>.+)/
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
22 changes: 9 additions & 13 deletions spec/overcommit/git_repo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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') }
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 }
Expand All @@ -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`
Expand Down
4 changes: 3 additions & 1 deletion spec/overcommit/hook/prepare_commit_msg/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions spec/overcommit/hook_context/commit_msg_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down Expand Up @@ -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}`
Expand All @@ -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}`
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/overcommit/hook_context/post_checkout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/overcommit/hook_context/post_commit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/overcommit/hook_context/post_merge_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
3 changes: 1 addition & 2 deletions spec/overcommit/hook_context/post_rewrite_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions spec/overcommit/hook_context/pre_commit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down Expand Up @@ -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}`
Expand All @@ -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}`
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions spec/overcommit/hook_context/run_all_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/overcommit/installer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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') }
Expand Down

0 comments on commit 65e2114

Please sign in to comment.