Class: CaseClashHook

Inherits:
RubyGitHooks::Hook show all
Defined in:
lib/ruby_git_hooks/case_clash.rb

Overview

This hook checks whether a similar file exists with the same name except for uppercase/lowercase. It’s useful when Mac OS and Unix people need to coexist in a single Git repository. You can be sure that the Linux people can’t check in files that the Mac people can neither see nor delete.

Constant Summary

Constants inherited from RubyGitHooks::Hook

RubyGitHooks::Hook::HOOK_INFO, RubyGitHooks::Hook::HOOK_TYPE_SETUP

Instance Method Summary collapse

Methods inherited from RubyGitHooks::Hook

get_hooks_to_run, initial_setup, register, run, run_as_specific_githook, #setup, shell!

Instance Method Details

#checkObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ruby_git_hooks/case_clash.rb', line 12

def check
  downcase_hash = {}

  ls_files.map(&:strip).each do |filename|
    downcase_hash[filename.downcase] ||= []
    downcase_hash[filename.downcase].push filename
  end

  okay = true
  downcase_hash.each do |_, filenames|
    if filenames.length > 1
      okay = false
      STDERR.puts "Duplicate-except-case files detected: #{filenames.inspect}"
    end
  end

  okay
end