forked from MoSync/MoSync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
writeAttributeFile.rb
executable file
·47 lines (40 loc) · 986 Bytes
/
writeAttributeFile.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
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
47
#!/usr/bin/ruby
# Create a .gitattributes file based on other_licenses.txt,
# to exclude its files from git diff-index --check.
BASEDIR = File.expand_path("#{File.dirname(__FILE__)}/..")
outName = "#{BASEDIR}/.gitattributes"
inName = "#{BASEDIR}/other_licenses.txt"
CHECK_PATTERNS = [
'workfile.rb',
'/templates',
'/githooks',
]
class String
def includeOneOf?(array)
array.each do |s|
return true if(self.include?(s))
end
return false
end
end
raise '.gitattributes exists!' if(File.exist?(outName))
@outFile = open(outName, 'w')
inFile = open(inName, 'r')
def putLine(line)
@outFile.puts line.gsub(' ', '.') + ' -diff' unless(line.includeOneOf?(CHECK_PATTERNS))
end
inFile.each do |line|
line.strip!
next if(line.length == 0)
test = File.expand_path(File.join(BASEDIR, line))
if(File.directory?(test))
dir = File.join(test, '**/*')
Dir[dir].each do |file|
putLine(file[BASEDIR.size..-1])
end
else
putLine(line)
end
end
@outFile.close
inFile.close