]> git.phdru.name Git - git-scripts.git/blob - submodules/unabsorbgitdirs-recursive
Feat(submodules/remove): Add option `-c`
[git-scripts.git] / submodules / unabsorbgitdirs-recursive
1 #! /bin/sh
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
9 set -e
10
11 START_DIR="`pwd`"
12 cd "`dirname \"$0\"`"
13 PROG_DIR="`pwd`"
14 cd "$START_DIR"
15
16 # To the top-level directory of the current submodule or the superproject
17 cd "`git rev-parse --show-toplevel`"
18
19 unset GIT_DIR
20
21 # If .git/ subdirectory is already here
22 [ -d .git ] && exit 0
23
24 if ! [ -f .git ]; then
25     echo "Error: Cannot find gitlink, aborting" >&2
26     exit 1
27 fi
28
29 if [ -f .gitmodules ]; then
30     git submodule foreach "$PROG_DIR"/"`basename \"$0\"`"
31 fi
32
33 # Fix core.worktree now
34 git config --unset core.worktree
35
36 read _gitdir gitpath < .git
37 if [ "$_gitdir" != gitdir: ]; then
38     echo "Error: Bad gitlink, aborting" >&2
39     exit 1
40 fi
41 unset _gitdir
42 rm .git
43 exec mv "$gitpath" .git