]> git.phdru.name Git - git-scripts.git/commitdiff
Feat(submodules/remove): Add option `-c` master
authorOleg Broytman <phd@phdru.name>
Mon, 15 Apr 2024 13:04:46 +0000 (16:04 +0300)
committerOleg Broytman <phd@phdru.name>
Mon, 15 Apr 2024 13:04:46 +0000 (16:04 +0300)
Run `git rm --cached submodule` to preserve submodule's tree.

pull-usrlocalsrc
submodules/remove
submodules/unabsorbgitdirs
submodules/unabsorbgitdirs-recursive

index ef9167b7f70561a8ac522b1400adda822c7cae33..c7159ada349311b42b2170e494c4c84c7621f9dd 100755 (executable)
@@ -13,6 +13,6 @@ while read d; do
       { git pull upstream master || git pull upstream main:master; } &&
          git push origin master || exit 1
    elif has_remote origin; then
-      git pull origin master || exit 1
+      git pull origin master || git pull origin main:master || exit 1
    fi
 done
index 90cb02f6fc10904725a88f461df2c99902706bea..f9436cead70e12fdd84b414fb746d3c89aff7e83 100755 (executable)
@@ -1,8 +1,12 @@
 #! /bin/sh
 # See https://stackoverflow.com/q/1260748/7976758
 
+case "$1" in
+    -c|--cached) cached=--cached; shift ;;
+esac &&
+
 if [ $# != 1 ]; then
-    echo "Usage: $0 submodule_name" >&2
+    echo "Usage: $0 [-c|--cached] submodule_name" >&2
     exit 1
 fi
 
@@ -21,6 +25,14 @@ if [ -z "$path" ]; then
     exit 1
 fi
 
-git rm "$path" &&
+git rm $cached "$path" &&
 rm -rf "`git rev-parse --git-dir`"/modules/"$name" &&
-exec git config --remove-section submodule."$name"
+git config --remove-section submodule."$name" &&
+
+if [ \! -s .gitmodules ]; then
+    git rm -f .gitmodules
+fi &&
+
+if [ -z $(ls -A "`git rev-parse --git-dir`/modules") ]; then
+    exec rmdir "`git rev-parse --git-dir`/modules"
+fi
index 76d1c40f2797ef1609c3d566738d1e67b7066a5e..53cd46dab2764444d9c8fa23c7729627c8ca9c80 100755 (executable)
@@ -1,4 +1,5 @@
 #! /bin/sh
+# See https://stackoverflow.com/a/77950870/7976758
 set -e
 
 # To the top-level directory of the current submodule
index f7427fc31e191985067804f29043074d3d35d003..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`"