From 50b94353e49ddf9a453ddb8730b34dacb101880a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Fernando=20S=C3=A1nchez?= Date: Thu, 14 Jun 2018 19:33:08 +0200 Subject: [PATCH] --- submodules2subtrees.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 submodules2subtrees.sh diff --git a/submodules2subtrees.sh b/submodules2subtrees.sh new file mode 100644 index 0000000..947a491 --- /dev/null +++ b/submodules2subtrees.sh @@ -0,0 +1,42 @@ +#!/bin/bash -x +# extract the list of submodules from .gitmodule +cat .gitmodules |while read i +do +if [[ $i == \[submodule* ]]; then + echo converting $i + + # extract the module's prefix + mpath=$(echo $i | cut -d\" -f2) + + # skip two lines + read i; read i; + + # extract the url of the submodule + murl=$(echo $i|cut -d\= -f2|xargs) + + # extract the module name + mname=$(basename $mpath) + + # deinit the module + git submodule deinit $mpath + + # remove the module from git + git rm -r --cached $mpath + + # remove the module from the filesystem + rm -rf $mpath + + # commit the change + git commit -m "Removed $mpath submodule" + + # add the remote + git remote add -f $mname $murl + + # add the subtree + git subtree add --prefix $mpath $mname master --squash + + # fetch the files + git fetch $murl master +fi +done +git rm .gitmodules \ No newline at end of file