aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2017-11-07 16:49:07 -0200
committerSilvio Rhatto <rhatto@riseup.net>2017-11-07 16:49:07 -0200
commit80cd7e588430f56f52a294d5a715ed0eae6d5d21 (patch)
treecbe145781bdcba38172f80ab32645398399bc52e
parente07b797124a7c8d9127f1114ac01230e28c88bad (diff)
downloadutils-git-80cd7e588430f56f52a294d5a715ed0eae6d5d21.tar.gz
utils-git-80cd7e588430f56f52a294d5a715ed0eae6d5d21.tar.bz2
Refactor git-submodule-move-all-git-dirs/git-submodule-move-git-dir
-rwxr-xr-xgit-submodule-move-all-git-dirs16
-rwxr-xr-xgit-submodule-move-git-dir9
2 files changed, 17 insertions, 8 deletions
diff --git a/git-submodule-move-all-git-dirs b/git-submodule-move-all-git-dirs
index 41a7352..72e1aa3 100755
--- a/git-submodule-move-all-git-dirs
+++ b/git-submodule-move-all-git-dirs
@@ -5,15 +5,23 @@
# Parameters
BASENAME="`basename $0`"
+FOLDER="$1"
# Checks
-if [ ! -e ".git" ]; then
- echo "please run this command in the top-level repository folder"
+if [ -z "$FOLDER" ]; then
+ echo "usage: $BASENAME <repository-path>"
+ exit 1
+elif [ ! -d "$FOLDER" ]; then
+ echo "$BASENAME: repository not found: $FOLDER"
+ exit 1
+elif [ ! -e "$FOLDER/.git" ]; then
+ echo "$BASENAME: $FOLDER/.git not found"
exit 1
fi
-# If we invert find results so we begin conversion at the toplevel folders
-#find -type f -name .git | tac | while read repo; do
+cd $FOLDER
+
+# Find returns innermost folders first
find -type f -name .git | while read repo; do
folder="`dirname $repo`"
git-submodule-move-git-dir $folder
diff --git a/git-submodule-move-git-dir b/git-submodule-move-git-dir
index 8c28e66..44fd054 100755
--- a/git-submodule-move-git-dir
+++ b/git-submodule-move-git-dir
@@ -30,14 +30,15 @@ elif [ -d "$MODULE/.git" ]; then
elif [ ! -e ".git" ]; then
echo "please run this command in the top-level repository folder"
exit 1
-fi
-
-if [ ! -f "$MODULE/.git" ]; then
+elif [ ! -f "$MODULE/.git" ]; then
echo "$BASENAME: not a file, or file not found: $MODULE/.git"
exit 1
+elif [ -e "$MODULE/.gitmodules" ]; then
+ echo "$BASENAME: this repository has submodules; use git-submodule-move-all-git-dirs instead"
+ exit 1
fi
-# Additional parameters
+# Setup
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`"