From: Oleg Broytman Date: Mon, 15 Apr 2024 13:04:46 +0000 (+0300) Subject: Feat(submodules/remove): Add option `-c` X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;ds=sidebyside;h=HEAD;hp=50a94c682ccd5d2ab4cf2cfe954a10132077e608;p=git-scripts.git Feat(submodules/remove): Add option `-c` Run `git rm --cached submodule` to preserve submodule's tree. --- diff --git a/pull-usrlocalsrc b/pull-usrlocalsrc index ef9167b..c7159ad 100755 --- a/pull-usrlocalsrc +++ b/pull-usrlocalsrc @@ -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 diff --git a/submodules/remove b/submodules/remove index 90cb02f..f9436ce 100755 --- a/submodules/remove +++ b/submodules/remove @@ -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 diff --git a/submodules/unabsorbgitdirs b/submodules/unabsorbgitdirs index 76d1c40..53cd46d 100755 --- a/submodules/unabsorbgitdirs +++ b/submodules/unabsorbgitdirs @@ -1,4 +1,5 @@ #! /bin/sh +# See https://stackoverflow.com/a/77950870/7976758 set -e # To the top-level directory of the current submodule diff --git a/submodules/unabsorbgitdirs-recursive b/submodules/unabsorbgitdirs-recursive index f7427fc..bd1f10d 100755 --- a/submodules/unabsorbgitdirs-recursive +++ b/submodules/unabsorbgitdirs-recursive @@ -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`"