blog-static/submodule-links.rb
Danila Fedorin a29bca499f Switch to using data/ for submodule information
Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
2024-05-16 15:52:33 -07:00

27 lines
736 B
Ruby

require "json"
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")
if url =~ /dev.danilafe.com/
file_url = "#{url}/src/commit/#{hash}"
else
raise "Submodule URL #{url.dump} not in a known format!"
end
yield ({ :path => full_path, :url => file_url })
each_submodule(full_path) { |m| yield m }
end
end
hash = {}
each_submodule(".") do |m|
next unless m[:path].start_with? "./code/"
hash[m[:path].delete_prefix("./code/")] = m[:url]
end
puts JSON.pretty_generate(hash)