forked from adithya2306/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
merge-caf-tag-ginkgo.sh
100 lines (81 loc) · 2.32 KB
/
merge-caf-tag-ginkgo.sh
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
#!/bin/bash
# CAF tag merge script for caf-ginkgo
# Colors
red=$'\e[1;31m'
grn=$'\e[1;32m'
blu=$'\e[1;34m'
end=$'\e[0m'
REMOTE="ginkgo"
BRANCH="11.0"
VENDOR="trinket"
# fetch tag from user
read -p "Enter the CAF tag you wanna merge: " TAG
echo
# check if the tag is QSSI or vendor
if [[ $TAG = *"QSSI"* ]]; then
QSSI=true
echo "${blu}QSSI tag detected!"
else
QSSI=false
echo "${blu}Vendor tag detected!"
fi
# fetch all existing repos
echo "${blu}Fetching list of repos to be merged..."
repo forall -c "if [ \"\$REPO_REMOTE\" = \"$REMOTE\" ]; then echo \$REPO_PATH; fi" > .temp 2> /dev/null
# save current dir
cur_dir=$(pwd)
# initialize some files
for file in failed success unchanged; do
rm -f $file
touch $file
done
# main
for path in $(cat .temp); do
echo
if $QSSI && ! grep -q $path manifest/default.xml; then
echo "${red}$path not found in QSSI manifest! Skipping..."
continue
fi
if grep -q $path manifest/$VENDOR.xml; then
echo "${red}$path not found in vendor manifest! Skipping..."
continue
fi
echo "${blu}Merging ${path}..."
name=$(grep "path=\"$path\"" manifest/$VENDOR.xml manifest/default.xml | sed -e 's/.*name="//' -e 's/".*//')
cd $path
if [[ $(git status --porcelain) = *" M "* ]]; then
# save uncommitted changes that could be important
git checkout -q -b "staging-$(date -%s)" &> /dev/null
git commit -a -q -m "Staging $(date)" &> /dev/null
fi
# reset HEAD to our branch
git checkout -q $BRANCH &> /dev/null
git fetch -q $REMOTE $BRANCH &> /dev/null
git reset --hard $REMOTE/$BRANCH &> /dev/null
git fetch -q https://source.codeaurora.org/quic/la/$name $TAG &> /dev/null
if git merge FETCH_HEAD -q -m "Merge tag '$TAG' into $BRANCH" &> /dev/null; then
if [[ $(git rev-parse HEAD) != $(git rev-parse $REMOTE/$BRANCH) ]] && [[ $(git diff HEAD $REMOTE/$BRANCH) ]]; then
echo "$path" >> $cur_dir/success
echo "${grn}Merging $path succeeded!"
else
echo "${end}$path - unchanged"
echo "$path" >> $cur_dir/unchanged
git reset --hard $REMOTE/$BRANCH &> /dev/null
fi
else
echo "$path" >> $cur_dir/failed
echo "${red}$path merging failed!"
fi
cd $cur_dir
done
echo -e "$grn \nPushing succeeded repos: $end"
for repo in $(cat success); do
cd $repo
echo $repo
git push -q &> /dev/null
cd $cur_dir
done
echo -e "$red \nThese repos failed merging: $end"
cat failed
rm -f .temp
echo $end