Skip to content

Commit d898ff5

Browse files
jawshooahsds
authored andcommitted
Check against existing files only if not initial commit
Otherwise you get 'fatal: Not a valid object name HEAD' since `git ls-tree` requires an existing rev.
1 parent 7049631 commit d898ff5

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lib/overcommit/hook/pre_commit/case_conflicts.rb

+7-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@ module Overcommit::Hook::PreCommit
33
# Adapted from https://github.com/pre-commit/pre-commit-hooks
44
class CaseConflicts < Base
55
def run
6-
paths = Set.new(applicable_files.map { |file| File.dirname(file) + File::SEPARATOR })
7-
repo_files = Set.new(Overcommit::GitRepo.list_files(paths.to_a) + applicable_files)
6+
repo_files = Set.new(applicable_files)
7+
8+
unless Overcommit::GitRepo.initial_commit?
9+
paths = repo_files.map { |file| File.dirname(file) + File::SEPARATOR }
10+
repo_files += Overcommit::GitRepo.list_files(paths)
11+
end
12+
813
conflict_hash = repo_files.classify(&:downcase).
914
select { |_, files| files.size > 1 }
1015
conflict_files = applicable_files.

spec/overcommit/hook/pre_commit/case_conflicts_spec.rb

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
subject { described_class.new(config, context) }
77

88
before do
9+
Overcommit::GitRepo.stub(:initial_commit?).and_return(false)
910
Overcommit::GitRepo.stub(:list_files).and_return(%w[foo])
1011
end
1112

0 commit comments

Comments
 (0)