fix-git-submodules 556 Bytes
#!/bin/bash

set -ex

cmd="$1"
shift
case "$cmd" in
	(-start)
		dir="$1"
		shift
		find "$dir" -type f -name '.git' -exec "$0" -fix "$dir" '{}' \;
		;;
	(-fix)
		dir="$1"
		gitdir_link="$2"
		gitdir_dir="$(dirname "$gitdir_link")"
		read gitdir_token gitdir_location < "$gitdir_link"
		case "$gitdir_location" in
			(/*)
				echo "Can't handle absolute gitdir location: $gitdir_location" 1>&2
				exit 1
				;;
		esac
		cd "$gitdir_dir"
		pushd "$gitdir_location"
		git config --unset core.worktree
		popd
		rm .git
		mv "$gitdir_location" .git
		;;
esac