code_owners 1.0.9 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ This is confoozing.txt
@@ -0,0 +1 @@
1
+ This is a fake gem to trigger .gitignore
@@ -0,0 +1 @@
1
+ this is a foo file
@@ -0,0 +1 @@
1
+ this is foo.txt
@@ -0,0 +1 @@
1
+ true facts
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'code_owners'
4
+ require 'tmpdir'
5
+ require 'json'
6
+ require 'pathname'
7
+ require 'byebug'
8
+
9
+ output = { permutations: {} }
10
+
11
+ def reset_file_to(file, content)
12
+ file.rewind
13
+ file.write(content)
14
+ file.flush
15
+ file.truncate(file.pos)
16
+ end
17
+
18
+ # UGGGGGH
19
+ # so, turns out, the part in git-scm where it says
20
+ # > A trailing "/**" matches everything inside. For example, "abc/**" matches all files inside directory "abc", relative to the location of the .gitignore file, with infinite depth.
21
+ # that "relative" bit gets REAL obnoxious when it comes to trying to evaluate using an adhoc core.excludesFile directive
22
+ # speaking of, it seems like if you have one defined in the tree of a project git will STILL use that
23
+ # see the special exception case mentioned below for the *.gem pattern conflicting with the project's .gitignore
24
+ # there was no way to replace/unset it I could find that doesn't affect something more permanent >:/
25
+
26
+ ignore_file = File.open("spec/files/.gitignore", "w+")
27
+
28
+ Dir.chdir("spec/files") do
29
+ all_files = Dir.glob(File.join("**","**"), File::FNM_DOTMATCH)
30
+ all_files.reject! { |f| File.directory?(f) }
31
+ output[:all_files] = all_files
32
+
33
+ permutables = ["", "*", ".", "/", "*/", "/*", "**", "**/", "/**", "**/**", "*/**", "**/*"]
34
+ ignore_cases = permutables.map do |p1|
35
+ ["foo", "bar", "foo/bar"].map do |p2|
36
+ permutables.map do |p3|
37
+ "#{p1}#{p2}#{p3}"
38
+ end
39
+ end
40
+ end.flatten
41
+
42
+ # can add more one-off cases we want to evaluate here
43
+ ignore_cases << ".dot*"
44
+
45
+ ignore_cases.sort!
46
+ puts "Evaluating #{ignore_cases.size} permutations"
47
+
48
+ rootpath = Pathname.new(".")
49
+
50
+ ignore_cases.each do |perm|
51
+ puts "evaluating #{perm}"
52
+ reset_file_to(ignore_file, perm)
53
+ ignore_matches = []
54
+ ignore_results = `find . -type f | sed "s|^\./||" | tr '\n' '\\0' | xargs -0 -- git -c "core.quotepath=off" check-ignore --no-index -v -n`
55
+ ignore_results.scan(/^([^:]+):(\d+):([^\t]*)\t(.*)/).each do |m_source, m_line, m_pattern, m_file|
56
+ if m_source != ignore_file.path || m_line != "1" || m_pattern != perm
57
+ next if m_source == ".gitignore" && m_line == "1" && m_pattern == "*.gem"
58
+ puts "ERROR?!"
59
+ puts "expecting #{ignore_file.path.inspect}, got #{m_source.inspect}"
60
+ puts "expecting 1, got #{m_line.inspect}"
61
+ puts "expecting #{perm.inspect}, got #{m_pattern.inspect}"
62
+ puts ignore_results
63
+ end
64
+ ignore_matches << Pathname.new(m_file).relative_path_from(rootpath).to_s
65
+ end
66
+ output[:permutations][perm] = ignore_matches.sort
67
+ end
68
+
69
+ reset_file_to(ignore_file, "blah blah blah")
70
+ end
71
+
72
+ File.open("spec/permutations.json", "w+") do |perm_file|
73
+ perm_file.write(JSON.pretty_generate(output))
74
+ end