-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_clones.sh
More file actions
55 lines (37 loc) · 1.16 KB
/
update_clones.sh
File metadata and controls
55 lines (37 loc) · 1.16 KB
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
#!/bin/bash
source "$(dirname "$0")/common.sh"
GIT_CMD=""
SNAPSHOT_ROOT_DIR=""
ADDITIONAL_GIT_ARGS=""
usage() {
echo -e "Usage: $0 [--help] pull|fetch <SNAPSHOT_ROOT_DIRECTORY> [<ADDITIONAL_GIT_ARGS>...]"
echo -ne "\nThis will either pull or fetch all the repositories located in "
echo -e "<SNAPSHOT_ROOT_DIRECTORY> (not recursively, only the first-level subdirectories)"
exit 0
}
parse_args() {
[[ "$1" = "--help" || "$2" = "--help" ]] && usage
if [[ "$1" = "fetch" || "$1" = "pull" ]]; then
GIT_CMD="$1"
else
die "The first argument must be either pull or fetch"
fi
[[ -z "$2" ]] && \
die "You have to specify the snapshot root directory as the second argument"
[[ "${2:0:1}" = "-" ]] && \
die "The directory name $2 starts with a hyphen. Did you really mean that? If so, \
make it ./$2"
SNAPSHOT_ROOT_DIR="$2"
shift 2
ADDITIONAL_GIT_ARGS="$@"
}
main() {
parse_args "$@"
cd "$SNAPSHOT_ROOT_DIR" || die "Failed to enter the directory $SNAPSHOT_ROOT_DIR"
for subdir in */*/; do
pushd "$subdir" && git "$GIT_CMD" $ADDITIONAL_GIT_ARGS || \
echo "FAILED TO $GIT_CMD the repo $subdir. Trying to continue..."
popd >/dev/null
done
}
main "$@"