]> gitweb.fluxo.info Git - utils-git.git/commitdiff
Refactor git-submodule-move-all-git-dirs/git-submodule-move-git-dir
authorSilvio Rhatto <rhatto@riseup.net>
Tue, 7 Nov 2017 18:49:07 +0000 (16:49 -0200)
committerSilvio Rhatto <rhatto@riseup.net>
Tue, 7 Nov 2017 18:49:07 +0000 (16:49 -0200)
git-submodule-move-all-git-dirs
git-submodule-move-git-dir

index 41a7352d19340649dc720147bef3ac3b9b4f49a5..72e1aa3fc83037b0bb58c7c1e4758875a8847ba8 100755 (executable)
@@ -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
index 8c28e66eb381afd52fb317f390885734815ed00a..44fd0546a7d2757c8dd2e05c286bcffa9278550d 100755 (executable)
@@ -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`"