-
Notifications
You must be signed in to change notification settings - Fork 0
/
subtree
executable file
·101 lines (89 loc) · 2.34 KB
/
subtree
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env bash
#
# Helper to manage repetitive syntax of git subtrees.
#
# git remotes and directories must have the same name
#
# requires bash 4, see http://www.artificialworlds.net/blog/2012/10/17/bash-associative-array-examples/
# set -e
declare -A REMOTES
REMOTES=(
[elasticsearch]=git@github.com:crccheck/elasticsearch.git
[google-auth-proxy]=git@github.com:crccheck/docker-google-auth-proxy.git
[graphite]=git@github.com:crccheck/docker-graphite.git
[hello-world]=git@github.com:crccheck/docker-hello-world.git
[mysql]=git@github.com:crccheck/docker-mysql.git
[postgis]=git@github.com:crccheck/docker-postgis.git
[requestbin]=git@github.com:crccheck/docker-requestbin.git
[tcpdump]=git@github.com:crccheck/docker-tcpdump.git
[thumbor]=git@github.com:crccheck/docker-thumbor.git
[tor]=git@github.com:crccheck/docker-tor.git
[zz]=git@github.com:crccheck/docker-zz.git
)
# Print help
# Trying to conform to http://docopt.org/
function help() {
echo "Usage:"
echo " ./subtree remotes"
echo " ./subtree (init|pull|push) <name> [options]"
echo ""
echo "Commands:"
echo " remotes Add all git remotes"
echo " init Initialize a subtree from <name>'s remote"
echo " pull Pull in commits from <name>'s remote"
echo " push Push up commits to <name>'s remote"
echo ""
echo "Any options you specify pass through to \`git subtree\`"
}
# Make sure a subtree name was specified as an argument.
function check_name() {
if [ -z $2 ]; then
echo "ERROR: No <name>"
echo ""
help
exit 1
fi
if [ ! ${REMOTES[$2]+_} ]; then
echo "ERROR: $2 is not a known remote"
echo ""
help
exit 1
fi
}
case "$1" in
help)
help
;;
# add all remotes
remotes)
echo "Adding remotes for other docker images"
for name in "${!REMOTES[@]}"; do
remote=${REMOTES[$name]}
echo -en " $name\t$remote\t"
git remote add $name $remote 2> /dev/null
if [ $? -eq 0 ]; then
echo "[added]"
else
echo "[skipped]"
fi
done
;;
# initialize a subtree from an existing remote
init)
check_name $*
git subtree add --prefix=$2 $2 master
;;
# pull
pull)
check_name $*
git subtree pull --prefix=$2 $2 master
;;
# push
push)
check_name $*
git subtree push --prefix=$2 $2 master
;;
*)
help
;;
esac