BefatorNix/gitModulesFixer.nix
2025-08-18 13:48:00 +02:00

55 lines
1.4 KiB
Nix

{stdenv, writeShellApplication, git}: writeShellApplication rec {
name = "gitModulesFixer";
#propagatedBuildInputs = [python26Packages.setuptools];
#nativeBuildInputs = [ libxml2 libxslt ];
#buildInputs = [ zlib ];
runtimeInputs = [ git ];
#env = {
# NIX_CFLAGS_COMPILE="-Wno-incompatible-pointer-types";
#};
text = ''
root_dir=$(pwd)
processed_files=()
echo ">>> Starting recursive submodule fix & init"
while :; do
found_new=false
while IFS= read -r gitmodules_file; do
# Skip already processed
echo "''${processed_files[@]}"
if printf '%s\n' "''${processed_files[@]}" | grep -qx "$gitmodules_file"; then
continue
fi
echo ">>> Patching $gitmodules_file"
processed_files+=("$gitmodules_file")
found_new=true
sed -i 's#git://#https://#g' "$gitmodules_file"
# Init only first-level submodules for this directory
mod_dir=$(dirname "$gitmodules_file")
(
cd "$mod_dir"
echo "$mod_dir"
git status
git submodule status
git submodule update --init
)
done < <(find "$root_dir" -name .gitmodules)
if ! $found_new; then
echo ">>> No new submodules found. Done."
break
fi
done
'';
}