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
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/pod_builder/command/generate_lfs.rb', line 6
def self.call(options)
Configuration.check_inited
unless Configuration.update_lfs_gitattributes
return false
end
base_path = PodBuilder::basepath
framework_files = filter_files_by_size(Dir.glob("#{base_path}/Rome/**/*.framework/**/**"), 256)
dSYM_files_iphone = filter_files_by_size(Dir.glob("#{base_path}/dSYM/**/*.dSYM/**/**"), 256)
total_size = (framework_files + dSYM_files_iphone).map { |x| File.size(x) }.inject(0, :+)
puts "Total size in LFS: #{total_size / 1024 / 1024}MB"
home_path = Pathname.new(PodBuilder::home)
paths = (framework_files + dSYM_files_iphone).map { |x| Pathname.new(x) }
rel_paths = paths.map { |x| x.relative_path_from(home_path).to_s }
stop_marker = "# pb<stop>"
start_marker = "# pb<start> (lines up to `#{stop_marker}` are autogenerated, don't modify this section)"
gitattributes_items = [start_marker]
gitattributes_items += rel_paths.map { |x| "#{x} filter=lfs diff=lfs merge=lfs -text" }
gitattributes_items += [stop_marker]
gitattributes_path = File.join(PodBuilder::home, ".gitattributes")
if !File.exist?(gitattributes_path)
FileUtils.touch(gitattributes_path)
end
gitattributes_content = File.read(gitattributes_path)
podbuilder_start_line_found = false
gitattributes_content.each_line do |line|
stripped_line = line.strip
if stripped_line.start_with?(stop_marker)
podbuilder_start_line_found = false
next
elsif stripped_line.start_with?(start_marker)
podbuilder_start_line_found = true
end
unless !podbuilder_start_line_found
next
end
gitattributes_items.push(line.strip)
end
File.write(gitattributes_path, gitattributes_items.join("\n"))
end
|