aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xgit-submodule-move-git-dir25
1 files changed, 22 insertions, 3 deletions
diff --git a/git-submodule-move-git-dir b/git-submodule-move-git-dir
index cd89517..b30f247 100755
--- a/git-submodule-move-git-dir
+++ b/git-submodule-move-git-dir
@@ -32,12 +32,31 @@ elif [ ! -d ".git" ]; then
exit 1
fi
+if [ ! -f "$MODULE/.git" ]; then
+ echo "$BASENAME: not a file, or file not found: $MODULE/.git"
+ exit 1
+fi
+
# Additional parameters
+RELATIVE_REPO_DIR="$(cd $MODULE &> /dev/null && cd `cut -d : -f 2 .git` &> /dev/null && pwd)"
REPO_DIR="`pwd`"
MODULE_DIR="`cd $MODULE &> /dev/null && pwd`"
-RELATIVE_REPO_DIR="$(echo $MODULE_DIR | sed -e "s|^$REPO_DIR/||")"
+
+if [ -z "$RELATIVE_REPO_DIR" ] || [ ! -d "$RELATIVE_REPO_DIR" ]; then
+ RELATIVE_REPO_DIR=".git/modules/$RELATIVE_REPO_DIR/$(echo $MODULE_DIR | sed -e "s|^$REPO_DIR/||")"
+fi
+
+if [ -z "$RELATIVE_REPO_DIR" ] || [ ! -d "$RELATIVE_REPO_DIR" ]; then
+ echo "$BASENAME: no git folder found for submodule $MODULE"
+ exit 1
+fi
+
+if [ ! -e "$RELATIVE_REPO_DIR/config" ]; then
+ echo "$BASENAME: config not found at $RELATIVE_REPO_DIR/config"
+ exit 1
+fi
# Convert
-rm $MODULE/.git
-mv ".git/modules/$RELATIVE_REPO_DIR" "$MODULE/.git"
+rm $MODULE/.git && \
+mv "$RELATIVE_REPO_DIR" "$MODULE/.git" && \
sed -i -e '/worktree =/d' "$MODULE/.git/config"