Explorar el Código

Add ghtp script to set remotes to HTTP or SSL

Scott Lahteine hace 8 años
padre
commit
340f97d635
Se han modificado 1 ficheros con 33 adiciones y 0 borrados
  1. 33
    0
      buildroot/share/git/ghtp

+ 33
- 0
buildroot/share/git/ghtp Ver fichero

@@ -0,0 +1,33 @@
1
+#!/usr/bin/env bash
2
+#
3
+# ghtp (GitHub Transport Protocol)
4
+#
5
+# Set all remotes in the current repo to HTTPS or SSH connection.
6
+# Useful when switching environments, using public wifi, etc.
7
+#
8
+
9
+GH_SSH="git@github\.com:"
10
+GH_HTTPS="https:\/\/github\.com\/"
11
+
12
+case "$1" in
13
+  -[Hh]) TYPE=HTTPS ; MATCH="git@" ; FORMULA="$GH_SSH/$GH_HTTPS" ;;
14
+  -[Ss]) TYPE=SSH ; MATCH="https:" ; FORMULA="$GH_HTTPS/$GH_SSH" ;;
15
+  *)
16
+    echo "Usage: `basename $0` -h | -s" 1>&2
17
+    echo -e " \e[0;92m-h\e[0m to switch to HTTPS" 1>&2
18
+    echo -e " \e[0;92m-s\e[0m to switch to SSH" 1>&2
19
+    exit 1
20
+    ;;
21
+esac
22
+
23
+REMOTES=$(git remote -v | egrep "\t$MATCH" | gawk '{print $1 " " $2}' | sort -u | sed  "s/$FORMULA/")
24
+
25
+if [[ -z $REMOTES ]]; then
26
+  echo "Nothing to do." ; exit
27
+fi
28
+
29
+echo "$REMOTES" | xargs -n2 git remote set-url
30
+
31
+echo -n "Remotes set to $TYPE: "
32
+echo "$REMOTES" | gawk '{printf "%s ", $1}'
33
+echo

Loading…
Cancelar
Guardar