-
Notifications
You must be signed in to change notification settings - Fork 2
/
add_remotes.sh
executable file
·58 lines (53 loc) · 1.87 KB
/
add_remotes.sh
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/zsh
#if [ -z "$SUDO_COMMAND" ]
# then
# echo -e "Only root can run this script.\nRelaunching script with sudo.\n"
# sudo -E $0 $*
# exit 0
#fi
while getopts u:a:hr flag
do
case "${flag}" in
r)
git remote set-url origin git@github.com:discoverygarden/${repository}
echo "Redirected origin back to discoverygarden repo"
exit;;
u) contributor=${OPTARG};;
h)
echo "Add specified fork to local git repository remotes. Defaults to noel"
echo
echo "Syntax: ${0##*/} [-u|h]"
echo "Options:"
echo " -u User to account to target. Available: noel, morgan, chris, jordan, alex, jojo, adam."
echo " -a Add all currently available remotes.(Not currently available)"
echo " -r Redirects origin remote target to discoverygarden repo."
echo " -h Print this help."
exit;;
\?)
echo "Error: Invalid Option"
exit;;
esac
done
# Get the current git repo plus .git (eg. drupal-project.git)
repository=$(basename $(git remote get-url origin))
# Declaring associative array of known repos
declare -A gitrepos=( [noel]=nchiasson-dgi [morgan]=morgandawe [chris]=chrismacdonaldw [jordan]=jordandukart [alex]=alexander-cairns [jojo]=jojoves [adam]=adam-vessey )
# Set contributor default if not specified.
if [[ -z $contributor ]]
then
contributor="noel"
fi
# Check if contributor key exists
if [[ ${gitrepos[${contributor}]+_} ]]
then
# Check that the remote is not currently set
if [[ $(git remote | grep ${contributor}) ]]
then
echo "Remote for '${contributor}' already configured"
else
git remote add ${contributor} git@github.com:${gitrepos[${contributor}]}/${repository}
echo "Remote '${contributor}' set"
fi
else
echo "'${contributor}' not found."
fi