~dricottone/my-utils

ref: 8b4fb7404819b4ada8ac5429865a22d5570ef58b my-utils/src/git-set-remotes -rwxr-xr-x 900 bytes
8b4fb740Dominic Ricottone README formatting; refactor qemu-test; new git script 3 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/sh

name="git-set-remotes"
version="1.0"
help_message=$(/usr/bin/cat <<-EOF
	Set all git remotes for my public repositories
	Usage: git-set-remotes
	Options:
	 -h, --help     print this message and exit
	 -q, --quiet    suppress error messages
	 -v, --version  print version number and exit
EOF
)

. /usr/local/lib/myminiparse.sh

error_msg() {
  if [ "$quiet" -eq 0 ]; then
    (>&2 /usr/bin/printf "%s: %s\n" "$name" "$1")
  fi
}

git_add_or_set() {
  if ! git remote add "$1" "$2" >/dev/null 2>&1; then
    error_msg "remote '${1}' already exists; resetting the URL"
    git remote set-url "$1" "$2" >/dev/null 2>&1
  fi
}

if [ ! -d .git ]; then
  error_msg "not a git repository"
  exit 1
fi

NAME="$(basename "$(pwd)")"

git_add_or_set "origin" "git:${NAME}.git"
git_add_or_set "github" "git@github.com:dricottone/${NAME}.git"
git_add_or_set "gitweb" "deploy-aws2:/var/git/${NAME}.git"