2 # The script cannot be run with `git submodule foreach --recursive`
3 # because the command runs recursively from top to bottom
4 # while the command is required to be run from bottom to top
5 # because it doesn't fix childrens' gitlinks.
6 # So the script runs recursion itself;
7 # it can be run with `git submodule foreach` without `--recursive`.
8 # See https://stackoverflow.com/a/77950870/7976758
16 # To the top-level directory of the current submodule or the superproject
17 cd "`git rev-parse --show-toplevel`"
21 # If .git/ subdirectory is already here
24 if ! [ -f .git ]; then
25 echo "Error: Cannot find gitlink, aborting" >&2
29 if [ -f .gitmodules ]; then
30 git submodule foreach "$PROG_DIR"/"`basename \"$0\"`"
33 # Fix core.worktree now
34 git config --unset core.worktree
36 read _gitdir gitpath < .git
37 if [ "$_gitdir" != gitdir: ]; then
38 echo "Error: Bad gitlink, aborting" >&2
43 exec mv "$gitpath" .git