forked from ClickHouse/ClickHouse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_submodule_inputs.sh
More file actions
executable file
·31 lines (24 loc) · 1017 Bytes
/
generate_submodule_inputs.sh
File metadata and controls
executable file
·31 lines (24 loc) · 1017 Bytes
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
#!/usr/bin/env bash
set -euo pipefail
repo_root=$(git rev-parse --show-toplevel)
gitmodules="$repo_root/.gitmodules"
# Get all submodule keys like submodule.contrib/foo.path
submodules=$(git config -f "$gitmodules" --get-regexp '^submodule\..*\.path$' | cut -d' ' -f1)
for key in $submodules; do
path=$(git config -f "$gitmodules" --get "$key")
url=$(git config -f "$gitmodules" --get "${key/.path/.url}")
# Strip .git suffix if present
url_no_git=${url%.git}
# Regex: capture org, repo
# \1 = org (e.g. ClickHouse)
# \2 = repo (e.g. jwt-cpp)
if [[ ! "$url_no_git" =~ github.com[:/]+([^/]+)/([^/]+)$ ]]; then
echo "❌ Error: submodule '$key' has non-GitHub URL: $url" >&2
exit 1
fi
org="${BASH_REMATCH[1]}"
repo="${BASH_REMATCH[2]}"
rev=$(git -C "$repo_root" ls-tree HEAD "$path" | awk '{ print $3 }')
input_name=$(basename "$path")
echo " contrib-${input_name} = { url = \"github:${org}/${repo}/${rev}\"; flake = false; };"
done