2024-05-16 15:38:59 -07:00
|
|
|
require "json"
|
2021-01-10 20:24:22 -08:00
|
|
|
|
2021-01-11 12:39:41 -08:00
|
|
|
def each_submodule(base_path)
|
|
|
|
`cd #{base_path} && git submodule status`.lines do |line|
|
|
|
|
hash, path = line[1..].split " "
|
|
|
|
full_path = "#{base_path}/#{path}"
|
|
|
|
url = `git config --file #{base_path}/.gitmodules --get 'submodule.#{path}.url'`.chomp.delete_suffix(".git")
|
2021-01-10 20:24:22 -08:00
|
|
|
|
2021-01-11 12:39:41 -08:00
|
|
|
if url =~ /dev.danilafe.com/
|
|
|
|
file_url = "#{url}/src/commit/#{hash}"
|
|
|
|
else
|
|
|
|
raise "Submodule URL #{url.dump} not in a known format!"
|
|
|
|
end
|
|
|
|
|
2024-05-16 15:38:59 -07:00
|
|
|
yield ({ :path => full_path, :url => file_url })
|
2021-01-11 12:39:41 -08:00
|
|
|
each_submodule(full_path) { |m| yield m }
|
2021-01-10 20:24:22 -08:00
|
|
|
end
|
2021-01-11 12:39:41 -08:00
|
|
|
end
|
|
|
|
|
2024-05-16 15:38:59 -07:00
|
|
|
hash = {}
|
2021-01-11 12:39:41 -08:00
|
|
|
each_submodule(".") do |m|
|
|
|
|
next unless m[:path].start_with? "./code/"
|
2024-05-16 15:38:59 -07:00
|
|
|
hash[m[:path].delete_prefix("./code/")] = m[:url]
|
2021-01-10 20:24:22 -08:00
|
|
|
end
|
2024-05-16 15:38:59 -07:00
|
|
|
|
|
|
|
puts JSON.pretty_generate(hash)
|