Skip to content

Instantly share code, notes, and snippets.

@kuznero
Last active March 10, 2016 15:18
Show Gist options
  • Save kuznero/294d6c42aeaf14a1050b to your computer and use it in GitHub Desktop.
Save kuznero/294d6c42aeaf14a1050b to your computer and use it in GitHub Desktop.
Synchronizing Git Submodules Modifying URLs

Synchronizing Git Submodules Modifying URLs

Sometimes it is not possible to access submodules as they were registered. Solution is here:

#!/bin/bash

NUMARGS=$#
SCRIPT=`basename ${BASH_SOURCE[0]}`
GREEN='\033[1;32m'
NC='\033[0m'

function HELP {
  echo -e "${GREEN}Usage${NC}: ${SCRIPT} server-name ip-address timeout-sec"
  exit 1
}

if [ $NUMARGS -ne 3 ]; then
  HELP
fi

name=$1
address=$2
timeout=$3

rc=1
while [ $rc -ne 0 ]; do
  find ./ -type f \( -name .gitmodules \) -print0 | xargs -0 sed -i "s/$name/$address/g"
  git submodule sync --recursive
  timeout $timeout git submodule update --init --recursive
  rc=$?
done

echo -e "${GREEN}All done.${NC}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment