#! /bin/sh # The script cannot be run with `git submodule foreach --recursive` # because the command runs recursively from top to bottom # while the command is required to be run from bottom to top # because it doesn't fix childrens' gitlinks. # So the script runs recursion itself; # it can be run with `git submodule foreach` without `--recursive`. set -e START_DIR="`pwd`" cd "`dirname \"$0\"`" PROG_DIR="`pwd`" cd "$START_DIR" # To the top-level directory of the current submodule or the superproject cd "`git rev-parse --show-toplevel`" unset GIT_DIR # If .git/ subdirectory is already here [ -d .git ] && exit 0 if ! [ -f .git ]; then echo "Error: Cannot find gitlink, aborting" >&2 exit 1 fi if [ -f .gitmodules ]; then git submodule foreach "$PROG_DIR"/"`basename \"$0\"`" fi # Fix core.worktree now git config --unset core.worktree read _gitdir gitpath < .git if [ "$_gitdir" != gitdir: ]; then echo "Error: Bad gitlink, aborting" >&2 exit 1 fi unset _gitdir rm .git exec mv "$gitpath" .git