From 99f22d0045c5002c384a599cc0f0b203f429eedf Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Wed, 7 Feb 2024 00:30:03 +0300 Subject: [PATCH] Add scripts to unabsorb git dirs They do reverse of `git submodule absorbgitdirs`. There are simple and recursive variants. --- submodules/unabsorbgitdirs | 23 +++++++++++++++++ submodules/unabsorbgitdirs-recursive | 38 ++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100755 submodules/unabsorbgitdirs create mode 100755 submodules/unabsorbgitdirs-recursive diff --git a/submodules/unabsorbgitdirs b/submodules/unabsorbgitdirs new file mode 100755 index 0000000..2416477 --- /dev/null +++ b/submodules/unabsorbgitdirs @@ -0,0 +1,23 @@ +#! /bin/sh +set -e + +# To the top-level directory of the current submodule +cd "`git rev-parse --show-toplevel`" + +unset GIT_DIR + +# If .git/ subdirectory is already here +test -d .git && exit 0 + +if ! test -f .git; then + echo "Error: Cannot find gitlink, aborting" >&2 + exit 1 +fi + +# Fix core.worktree now +git config --unset core.worktree + +read _gitdir gitpath < .git +unset _gitdir +rm .git +exec mv "$gitpath" .git diff --git a/submodules/unabsorbgitdirs-recursive b/submodules/unabsorbgitdirs-recursive new file mode 100755 index 0000000..72b4464 --- /dev/null +++ b/submodules/unabsorbgitdirs-recursive @@ -0,0 +1,38 @@ +#! /bin/sh +# The script cannot be run with `git submodule foreach --recursive` +# because the command runs recursively from top to bottom +# while the command is required to be run from bottom to top +# because it doesn't fix childrens' gitlinks. +# So the script runs recursion itself; +# it can be run with `git submodule foreach` without `--recursive`. +set -e + +START_DIR="`pwd`" +cd "`dirname \"$0\"`" +PROG_DIR="`pwd`" +cd "$START_DIR" + +# To the top-level directory of the current submodule or the superproject +cd "`git rev-parse --show-toplevel`" + +unset GIT_DIR + +# If .git/ subdirectory is already here +test -d .git && exit 0 + +if ! test -f .git; then + echo "Error: Cannot find gitlink, aborting" >&2 + exit 1 +fi + +if test -f .gitmodules; then + git submodule foreach "$PROG_DIR"/"`basename \"$0\"`" +fi + +# Fix core.worktree now +git config --unset core.worktree + +read _gitdir gitpath < .git +unset _gitdir +rm .git +exec mv "$gitpath" .git -- 2.39.2