Class: Overcommit::Hook::PreCommit::CaseConflicts

Inherits:
Base
  • Object
show all
Defined in:
lib/overcommit/hook/pre_commit/case_conflicts.rb

Overview

Checks for files that would conflict in case-insensitive filesystems Adapted from github.com/pre-commit/pre-commit-hooks

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods inherited from Base

#applicable_files, #command, #description, #enabled?, #excluded?, #execute, #execute_in_background, #flags, #in_path?, #included_files, #initialize, #name, #parallelize?, #processors, #quiet?, #required?, #required_executable, #required_libraries, #run?, #run_and_transform, #skip?

Constructor Details

This class inherits a constructor from Overcommit::Hook::Base

Instance Method Details

#runObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/overcommit/hook/pre_commit/case_conflicts.rb', line 7

def run
  repo_files = Set.new(applicable_files)

  unless Overcommit::GitRepo.initial_commit?
    paths = repo_files.map { |file| File.dirname(file) + File::SEPARATOR }.uniq
    repo_files += Overcommit::GitRepo.list_files(paths)
  end

  conflict_hash = repo_files.classify(&:downcase).
    select { |_, files| files.size > 1 }
  conflict_files = applicable_files.
    select { |file| conflict_hash.include?(file.downcase) }

  conflict_files.map do |file|
    conflicts = conflict_hash[file.downcase].map { |f| File.basename(f) }
    msg = "Conflict detected for case-insensitive file systems: #{conflicts.join(', ')}"
    Overcommit::Hook::Message.new(:error, file, nil, msg)
  end
end