-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-db
executable file
·79 lines (65 loc) · 2.06 KB
/
update-db
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
#! /bin/sh -e
# Update reference repos
trap 'Error at $LINENO' ERR
SCRIPT=$(readlink -f "$0")
SCRIPT_PATH="${SCRIPT%/*}"
{
[ ! -z "${REPO_MAIN:+x}" ] &&
[ "$REPO_MAIN" = "$SCRIPT_PATH" ]
} || REPO_MAIN=$SCRIPT_PATH
[ ! -z "${REPO_MAIN:+x}" ] || {
echo "\$REPO_MAIN = ${REPO_MAIN-} looks not correct"
exit 1
}
echo "\$REPO_MAIN = $REPO_MAIN"
repo_main_parent="${REPO_MAIN%/*}"
repo_root="$repo_main_parent"
[ ! -z "${REPO_ROOT:+x}" ] || {
echo "\$REPO_ROOT = ${REPO_ROOT-} looks not correct"
exit 1
}
echo "\$REPO_ROOT = $REPO_ROOT"
[ ! -z "${REPO_ROOT_IMPL:+x}" ] || {
echo "\$REPO_ROOT_IMPL = ${REPO_ROOT_IMPL-} looks not correct"
exit 1
}
echo "\$REPO_ROOT_IMPL = $REPO_ROOT_IMPL"
[ ! -z "${repo_main_parent:+x}" ] &&
[ -z "${repo_main_parent##*"${REPO_ROOT}"*}" ] || {
echo "\$REPO_ROOT = $REPO_ROOT"
echo "\$repo_main_parent = ${repo_main_parent-} looks not correct"
exit 1
}
[ ! -z "${repo_main_parent:+x}" ] &&
[ -z "${repo_main_parent##*"${REPO_ROOT_IMPL}"*}" ] || {
echo "\$REPO_ROOT_IMPL = $REPO_ROOT_IMPL"
echo "\$repo_main_parent = ${repo_main_parent-} looks not correct"
exit 1
}
[ "$repo_main_parent" = "${REPO_ROOT_IMPL}" ] ||
repo_root="${REPO_ROOT_IMPL}"
[ ! -z "${repo_root:+x}" ] || {
echo "\$repo_root = ${repo_root-} looks not correct"
exit 1
}
echo "\$repo_root = $repo_root"
cd $repo_root
for item in $(\ls -1 "$repo_root"); do
[ -d "$item" ] || continue
echo "\$item = $item"
[ "$item" = "${REPO_MAIN##*/}" ] ||
[ "$item" = "installed" ] ||
[ "$item" = "choices" ] ||
# No "false" will be returned in the following git test
[ "$(git -C "$item" rev-parse --is-inside-work-tree 2>/dev/null)" != "true" ] || {
cd "$item"
printf "%b%s%b\n" '\033[1;34m' "Entered $item" '\033[m'
[ "$item" != "${REPO_MAIN##*/}" ] || { echo "What!!!!! Do not touch '$item'"; continue; }
echo "Operating on $PWD"
BRANCH_NAME=$(git show-branch --list | grep \* | awk '{print $2}' | sed 's/\[//g' | sed 's/\]//g')
[ -z "$(git diff 2>/dev/null)" ] ||
git reset --hard origin/$BRANCH_NAME
( git pull 2>/dev/null ) || echo "pull failed"
}
cd $repo_root
done