forked from baohaojun/system-config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.after-push-hook
executable file
·116 lines (104 loc) · 3.47 KB
/
.after-push-hook
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
#!/bin/bash
set -e
if test -e ~/.local-config/.system-config-private-after-push-hook; then
~/.local-config/.system-config-private-after-push-hook
fi || true
function push-all-projects() {
(
. ~/system-config/etc/github-projects
projects=$(
echo ~/system-config
for x in ${github_projects[*]} ${smartcm_projects[*]}; do
echo ~/src/github/$x
done
)
if s_branch=$(cd ~/system-config; git config sc.branch) && test "$s_branch"; then
true
else
s_branch=dev
fi
if test "$s_branch" = dev; then
(
cd ~/src/system-config/ || exit
if test "$(git-tracking-branch)" = master; then
exit
fi
git reset --hard
git clean -xfd
git co master
)
else
(
cd ~/src/system-config/ || exit
if test "$(git-tracking-branch)" = unstable; then
exit
fi
git reset --hard
git clean -xfd
git co unstable
)
fi
if test ! -e ~/.config/system-config/push-all-submodules ||
test "$(perl -e 'print int(-M "$ENV{HOME}/.config/system-config/push-all-submodules")')" -gt 7; then
touch ~/.config/system-config/push-all-submodules
for p in "${github_projects[@]}"; do
(
# to make system-config projects download faster
cd ~/src/github/"$p"
git push github.com:baohaojun/system-config HEAD:refs/heads/submodules/$p ||
bhj-notify $PWD "push to submodules failed"
)
done
fi
)&
}
if test -d ~/src/system-config/; then
(
set -x;
push-all-projects
) > ~/src/system-config/.git/push-all-projects.log 2>&1
(
for x in ~/src/github/*/.after-push-hook; do
cd "$(dirname "$x")"
en_US bash "$x"&
done
) >/dev/null 2>&1
(
cd ~/src/system-config
HEAD=$(git rev-parse HEAD)
git pull ~/system-config --no-edit
)
mkdir -p ~/src/system-config/src/github
(
cd ~/src/system-config/
. ~/system-config/etc/github-projects
for x in ${github_projects[*]} ${smartcm_projects[*]}; do
(
if test ! -d src/github/${x}; then
git subtree add --prefix=src/github/${x} ~/src/github/${x}/ HEAD
else
HEAD=$(
cd ~/src/github/${x}
git rev-parse HEAD
)
git subtree pull --prefix=src/github/${x} ~/src/github/${x} HEAD -m "Merge from ~/src/github/${x} ${HEAD}"
fi
)
done
wait
)
cd ~/src/system-config/
if git-any-changes >/dev/null 2>&1; then
git add .
git commit -m "auto commit from system-config:$(cd ~/system-config; git log --pretty=%H -1)"
fi
if ! git push; then
bhj-notify $PWD "push to s failed"
fi
if ! (
timeout 30 git push github HEAD:system-config -f >/dev/null 2>&1 ||
timeout 30 tsocks git push github HEAD:system-config -f >/dev/null 2>&1
); then
bhj-notify system-config "Failed to push system-config @$PWD to github"
fi&
fi