aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2017-03-23 18:48:49 -0300
committerSilvio Rhatto <rhatto@riseup.net>2017-03-23 18:48:49 -0300
commit58d7c44affff801a412a5b1ac5f3240fb59be68b (patch)
tree41c9b7cb138f115ce568465d6a4db079a62cf57f
parent05198a3e36ec402677773df0255b41be4a565d56 (diff)
downloadutils-git-58d7c44affff801a412a5b1ac5f3240fb59be68b.tar.gz
utils-git-58d7c44affff801a412a5b1ac5f3240fb59be68b.tar.bz2
Adds git-submodule-move-git-dir
-rwxr-xr-xgit-submodule-move-git-dir43
1 files changed, 43 insertions, 0 deletions
diff --git a/git-submodule-move-git-dir b/git-submodule-move-git-dir
new file mode 100755
index 0000000..cd89517
--- /dev/null
+++ b/git-submodule-move-git-dir
@@ -0,0 +1,43 @@
+#!/bin/bash
+#
+# Put the .git submodule folder back to the right place.
+#
+# When initializing a git submodule, git usually puts the
+# submodules' .git folder inside the .git/modules folder
+# in the parent repository.
+#
+# While this keeps all submodule metadata in a single place,
+# it may not be confortable when you also want to develop
+# the submodule.
+#
+# This plugin simply moves the submodules' git folder back
+# to the standard place.
+
+# Parameters
+BASENAME="`basename $0`"
+MODULE="$1"
+
+# Checks
+if [ -z "$MODULE" ]; then
+ echo "usage: $BASENAME <submodule-path>"
+ exit 1
+elif [ ! -d "$MODULE" ]; then
+ echo "module not found: $MODULE"
+ exit 1
+elif [ -d "$MODULE/.git" ]; then
+ echo "module $MODULE already converted"
+ exit 1
+elif [ ! -d ".git" ]; then
+ echo "please run this command in the top-level repository folder"
+ exit 1
+fi
+
+# Additional parameters
+REPO_DIR="`pwd`"
+MODULE_DIR="`cd $MODULE &> /dev/null && pwd`"
+RELATIVE_REPO_DIR="$(echo $MODULE_DIR | sed -e "s|^$REPO_DIR/||")"
+
+# Convert
+rm $MODULE/.git
+mv ".git/modules/$RELATIVE_REPO_DIR" "$MODULE/.git"
+sed -i -e '/worktree =/d' "$MODULE/.git/config"