14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/hooks/linked-files-not-in-repo.rb', line 14
def adjudge!()
puts 'Checking linked files in your csproj are not in the repository...'
csproj_path = File.join(@git_root, @project_dir, @csproj_filename)
return Result.error("Cannot find #{csproj_path}") unless File.exists? csproj_path
puts "Checking csproj: '#{csproj_path}'"
csproj = Nokogiri::XML(File.read(csproj_path))
sins = []
Dir.chdir(@git_root) do
csproj.css('ItemGroup > Content > Link').each do |link|
path = File.join(@project_dir, link.text.gsub('\\', '/'))
puts link.text
result = `git ls-files --stage #{path}`
sins.push(result) unless result.empty?
end
end
return Result.success("Congratulations, this is a righteous commit!") if sins.empty?
message = "\nYou have sinned! The following files are csproj links, but exist in your repo..."
sins.each do |sin|
message = message + "\n#{sin}"
end
message = message + "\nPlease delete them before committing. You may need to add them to .gitignore as well."
return Result.error(message)
end
|