]> git.parisson.com Git - docker-django-scripts.git/commitdiff
Add misc script to switch git URLs
authorGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Thu, 15 Mar 2018 10:05:53 +0000 (11:05 +0100)
committerGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Thu, 15 Mar 2018 10:05:53 +0000 (11:05 +0100)
dev/update.sh
misc/git_switch_urls.sh [new file with mode: 0755]
prod/update.sh

index e0235af2abc555f08e1a42d160bc6343e0cc7f04..0594c7eb0dc05065340b3a8925f0201d57203a4b 100755 (executable)
@@ -21,13 +21,6 @@ then
     curr_branch="dev"
 fi
 
-function update_git_urls {
-    find ./ -type f \( -name ".gitmodules" -o -name "config" \)  -exec sed -i $REGEX {} +
-}
-
-REGEX='s/https:\/\/github.com\//git@github.com:/g'
-update_git_urls
-
 # checkout new submodule
 git submodule update --init
 # Synchronizes submodules' remote URL configuration setting to the value specified in .gitmodules
diff --git a/misc/git_switch_urls.sh b/misc/git_switch_urls.sh
new file mode 100755 (executable)
index 0000000..d8c1718
--- /dev/null
@@ -0,0 +1,52 @@
+#!/bin/bash
+
+# The script detect the right main project branch, then update the submodule function of branch-[mainProjectBranch]
+# For example, if you define these variables in .gitmodules :
+# - branch-dev
+# - branch-master
+# If you are on dev branch in main project, the script will update submodule functions of branch-dev you've defined
+# In main project, if you are in another branch than master or dev, it will take by default dev branch
+# If you don't define any branches for you submodule, the script will update from master
+
+cd "$(dirname "$0")"/../../
+
+function usage() {
+    echo "switch all git URLs to SSH or HTTPS and vice versa"
+    echo ""
+    echo "./git_switch_urls.sh"
+    echo "  -h --help"
+    echo "  -s --ssh : switch all repositories to SSH"
+    echo "  -t --https : switch all repositories to HTTPS"
+    echo ""
+}
+
+
+function update_git_urls() {
+    find ./ -path ./var/lib -prune -o -type f \( -name ".gitmodules" -o -name "config" \)  -exec sed -i $REGEX {} +
+}
+
+
+while [ "$1" != "" ]; do
+    PARAM=`echo $1 | awk -F= '{print $1}'`
+    VALUE=`echo $1 | awk -F= '{print $2}'`
+    case $PARAM in
+        -h | --help)
+            usage
+            exit
+            ;;
+        -s | --ssh)
+            REGEX='s/https:\/\/github.com\//git@github.com:/g'
+            update_git_urls
+            ;;
+        -t | --https)
+            REGEX='s/git@github.com:/https:\/\/github.com\//g'
+            update_git_urls
+            ;;
+        *)
+            echo "ERROR: unknown parameter \"$PARAM\""
+            usage
+            exit 1
+            ;;
+    esac
+    shift
+done
index 4a684e906fc4574d7bb9cf084f25de88bb72154f..0594c7eb0dc05065340b3a8925f0201d57203a4b 100755 (executable)
@@ -21,13 +21,6 @@ then
     curr_branch="dev"
 fi
 
-function update_git_urls {
-    find ./ -type f \( -name ".gitmodules" -o -name "config" \)  -exec sed -i $REGEX {} +
-}
-
-REGEX='s/git@github.com:/https:\/\/github.com\//g'
-update_git_urls
-
 # checkout new submodule
 git submodule update --init
 # Synchronizes submodules' remote URL configuration setting to the value specified in .gitmodules