-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetatool
executable file
·125 lines (106 loc) · 1.74 KB
/
metatool
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/sh
set -e
set -x
org_name=`
git remote -v |
head -n 1 |
sed -r 's#^.*[:/]([^/]*)/_meta.*$#\1#'
`
manyrepos_dir=.many
manyrepos_branch=master
metarepo_branch=meta
init() {
ls $manyrepos_dir |
while read project
do
git subtree add --prefix=$project $manyrepos_dir/$project $manyrepos_branch
done
}
populate() {
mkdir -p .many
find * -maxdepth 0 -type d |
parallel -I"{}" hub clone "${org_name}/{}" "${manyrepos_dir}/{}"
}
sync() {
ls $manyrepos_dir |
while read project
do
pull $project
done
ls $manyrepos_dir |
while read project
do
check_merge $project
done
ls $manyrepos_dir |
parallel -I"{}" git subtree push --prefix="{}" $manyrepos_dir/"{}" $metarepo_branch
ls $manyrepos_dir |
while read project
do
merge $project
done
}
pull() {
project=$1
git subtree pull --prefix=$project $manyrepos_dir/$project $manyrepos_branch
}
check_merge() {
project=$1
(
cd $manyrepos_dir/$project
check_clean
)
}
check_clean() {
[ "`git status --porcelain | head -n 3`" = "" ]
}
merge() {
project=$1
(
cd $manyrepos_dir/$project
if [ "`git log ${manyrepos_branch}..${metarepo_branch} | head -n 3`" = "" ]
then
return
fi
git merge $metarepo_branch --no-commit
if ! check_clean
then
git commit --no-edit
else
git merge --abort
fi
)
}
print_usage() {
echo "Usage:"
echo
echo "$0 [subcommand]"
echo
echo "Supported subcommands:"
echo
echo " init"
echo " sync"
}
usage() {
print_usage 1>&2
exit 1
}
command=$1
if [ "$command" = "" ]; then
usage
fi
shift
case $command in
init)
init $@
;;
populate)
populate $@
;;
sync)
sync $@
;;
*)
usage
;;
esac