]> git.phdru.name Git - git-scripts.git/blobdiff - submodules/unabsorbgitdirs-recursive
Feat(submodules/remove): Add option `-c`
[git-scripts.git] / submodules / unabsorbgitdirs-recursive
index 72b4464a6ceb8ba54acc8eb3d4fd12b462b2fdb8..bd1f10d789078e46b22eedfaed6adb48e0299af0 100755 (executable)
@@ -5,6 +5,7 @@
 # because it doesn't fix childrens' gitlinks.
 # So the script runs recursion itself;
 # it can be run with `git submodule foreach` without `--recursive`.
+# See https://stackoverflow.com/a/77950870/7976758
 set -e
 
 START_DIR="`pwd`"
@@ -18,14 +19,14 @@ cd "`git rev-parse --show-toplevel`"
 unset GIT_DIR
 
 # If .git/ subdirectory is already here
-test -d .git && exit 0
+[ -d .git ] && exit 0
 
-if ! test -f .git; then
+if ! [ -f .git ]; then
     echo "Error: Cannot find gitlink, aborting" >&2
     exit 1
 fi
 
-if test -f .gitmodules; then
+if [ -f .gitmodules ]; then
     git submodule foreach "$PROG_DIR"/"`basename \"$0\"`"
 fi
 
@@ -33,6 +34,10 @@ fi
 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