From d0b7069978809fa7b3aef789586438681cd2ab24 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Wed, 7 Feb 2024 01:28:26 +0300 Subject: [PATCH 1/4] Docs(unabsorbgitdirs): Add a link to StackOverflow This is where these scripts originated. --- submodules/unabsorbgitdirs | 1 + submodules/unabsorbgitdirs-recursive | 1 + 2 files changed, 2 insertions(+) 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`" -- 2.39.2 From e55ede1606d7e0220e7b6754f45347fc55e3070a Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Sat, 6 Apr 2024 15:07:02 +0300 Subject: [PATCH 2/4] Fix(pull-usrlocalsrc): Try `origin/main` if `master` absent --- pull-usrlocalsrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 -- 2.39.2 From f483adb65ce3845a400488bd289eb3b6eac4b53a Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Mon, 15 Apr 2024 15:28:36 +0300 Subject: [PATCH 3/4] Feat(submodules/remove): Cleanup Remove `.gitmodules` if it's empty. Remove `.git/modules` if it's empty. --- submodules/remove | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/submodules/remove b/submodules/remove index 90cb02f..1db57c2 100755 --- a/submodules/remove +++ b/submodules/remove @@ -23,4 +23,12 @@ fi git rm "$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 -- 2.39.2 From b0cdb013fbb3adb2f49035e3d36ddb6e96b87253 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Mon, 15 Apr 2024 16:04:46 +0300 Subject: [PATCH 4/4] Feat(submodules/remove): Add option `-c` Run `git rm --cached submodule` to preserve submodule's tree. --- submodules/remove | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/submodules/remove b/submodules/remove index 1db57c2..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,7 +25,7 @@ if [ -z "$path" ]; then exit 1 fi -git rm "$path" && +git rm $cached "$path" && rm -rf "`git rev-parse --git-dir`"/modules/"$name" && git config --remove-section submodule."$name" && -- 2.39.2