From 5e4097453bc5a2fdb3c21ae4719d27a5ea3854e1 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Mon, 11 Jan 2021 12:39:41 -0800 Subject: [PATCH] Update submodule script to properly gather submodule paths. --- .gitmodules | 3 +++ code/libabacus | 1 + submodule-links.rb | 34 +++++++++++++++++++++------------- 3 files changed, 25 insertions(+), 13 deletions(-) create mode 160000 code/libabacus diff --git a/.gitmodules b/.gitmodules index ba84131..b65653c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "code/aoc-2020"] path = code/aoc-2020 url = https://dev.danilafe.com/Advent-of-Code/AdventOfCode-2020.git +[submodule "code/libabacus"] + path = code/libabacus + url = https://dev.danilafe.com/Experiments/libabacus diff --git a/code/libabacus b/code/libabacus new file mode 160000 index 0000000..06f17f4 --- /dev/null +++ b/code/libabacus @@ -0,0 +1 @@ +Subproject commit 06f17f491c4d1be1f4936e36cda81c4f1e13cf49 diff --git a/submodule-links.rb b/submodule-links.rb index 5bc5bb8..4e958ef 100644 --- a/submodule-links.rb +++ b/submodule-links.rb @@ -1,19 +1,27 @@ puts "[params]" puts " [params.submoduleLinks]" -`git submodule status --recursive`.lines do |line| - hash, path = line[1..].split " " - next unless path.start_with? "code/" - code_path = path.delete_prefix "code/" - url = `git config --file .gitmodules --get 'submodule.#{path}.url'`.chomp.delete_suffix(".git") - safe_name = code_path.gsub(/\/|-|_/, "") +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") + safe_name = full_path.gsub(/\/|-|_\./, "") - if url =~ /dev.danilafe.com/ - file_url = "#{url}/src/commit/#{hash}" - else - raise "Submodule URL not in a known format!" + 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, :name => safe_name }) + each_submodule(full_path) { |m| yield m } end - puts " [params.submoduleLinks.#{safe_name}]" - puts " path = #{code_path.dump}" - puts " url = #{file_url.dump}" +end + +each_submodule(".") do |m| + next unless m[:path].start_with? "./code/" + puts " [params.submoduleLinks.#{m[:name].delete_prefix(".code")}]" + puts " url = #{m[:url].dump}" + puts " path = #{m[:path].delete_prefix("./code/").dump}" end