Skip to content

Commit ade2736

Browse files
committed
Add a basic script to clone multiple Gerrit projects in parallel
1 parent 36568d7 commit ade2736

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

gerrit/gerrit-clone.sh

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/bash
2+
3+
refname="for"
4+
skip=0
5+
6+
while [ -n "$1" ]; do
7+
case "$1" in
8+
--help)
9+
help=true
10+
;;
11+
-*)
12+
echo "Error: Invalid option \"$1\"."
13+
exit 2
14+
;;
15+
*)
16+
# Stop parsing options on the first non-option argument.
17+
break
18+
;;
19+
esac
20+
21+
shift
22+
done
23+
24+
if [ -n "$help" -o $# -ne 2 ]; then
25+
echo "Rationale"
26+
echo " Clone all projects matching the given pattern from Gerrit."
27+
echo
28+
echo "Usage"
29+
echo " $(basename $0) <host> <pattern>"
30+
echo
31+
echo "Example"
32+
echo " $(basename $0) review.openstack.org openstack-attic/akanda"
33+
echo
34+
echo "Options"
35+
echo " --help"
36+
echo " Show this help."
37+
exit 1
38+
fi
39+
40+
host=$(echo $1 | cut -d":" -f1)
41+
port=$(echo $1 | cut -d":" -f2 -s)
42+
[ -z "$port" ] && port=29418
43+
44+
pattern=$2
45+
matches=$(ssh -p $port $host gerrit ls-projects --type code | grep -E $pattern)
46+
47+
if [ -z "$matches" ]; then
48+
echo "No matching projects found."
49+
exit 2
50+
fi
51+
52+
echo "$matches"
53+
echo
54+
read -p "Do you want to clone these projects? [(Y)es/(n)o] " -n 1 -r
55+
56+
if [ "$REPLY" != "n" -a "$REPLY" != "N" ]; then
57+
echo "$matches" | xargs -I % -n 1 -P 8 git clone -q ssh://$host:$port/% %
58+
fi

0 commit comments

Comments
 (0)