-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
executable file
·104 lines (88 loc) · 2.61 KB
/
update.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
101
102
103
104
#!/bin/bash
# Options:
# -p Project name of the extension to update
# -v Version To which version branch this extension should be upgraded (will be used with -w to form -w/-v)
# -u Path branch path to use, default https://gerrit.wikimedia.org/r/mediawiki/extensions/
# -w Version-prefix prefix used to build version branch to fecth from (default: wmf/)
# -s Submodules should submodules updated, too?
# -d Debug Output all the spam!
branchPath="https://gerrit.wikimedia.org/r/mediawiki/extensions/"
wmf="wmf/"
scriptPath="$( cd "$(dirname "$0")" ; pwd -P )"
while getopts ":u:v:p:w:skd" opt; do
case $opt in
u)
branchPath=$OPTARG
;;
v)
newBranch=$OPTARG
;;
p)
project=$OPTARG
;;
w)
wmf=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" >&2
;;
esac
done
function coloredEcho(){
local exp=$1;
local color=$2;
if ! [[ $color =~ '^[0-9]$' ]] ; then
case $(echo $color | tr '[:upper:]' '[:lower:]') in
black) color=0 ;;
red) color=1 ;;
green) color=2 ;;
yellow) color=3 ;;
blue) color=4 ;;
magenta) color=5 ;;
cyan) color=6 ;;
white|*) color=7 ;; # white or invalid color
esac
fi
tput setaf $color;
echo $exp;
tput sgr0;
}
checkoutBranch=${wmf}${newBranch}
coloredEcho "Starting update of $project to ${checkoutBranch} using $branchPath." yellow
shopt -s nullglob
IFS='%'
if [ ! -d "$project" ]; then
coloredEcho "The directory $project does not exist" red
exit;
fi
coloredEcho " | cd to $project..." green
cd $project/
coloredEcho " | Prepare git repository..." green
git reset --hard &> /dev/null
git clean -f -d &> /dev/null
git ls-remote --exit-code upstream &> /dev/null
if test $? != 0; then
git remote add upstream $branchPath$project
fi
coloredEcho " | Fetch upstream..." green
git fetch upstream &> /dev/null
if [ `git ls-remote upstream ${checkoutBranch} | wc -l` != 1 ]; then
coloredEcho "The target branch ${checkoutBranch} does not exist in the remote..." red
exit;
fi
git rev-parse --verify ${checkoutBranch} &> /dev/null
if [ $? == 0 ]; then
coloredEcho " | Deleting already existing local branch ${checkoutBranch}" yellow
git checkout upstream/${checkoutBranch} &> /dev/null
git branch -D ${checkoutBranch} > /dev/null
fi
git checkout -b ${checkoutBranch} upstream/${checkoutBranch} &> /dev/null
git pull &> /dev/null
coloredEcho " | Applying patches, if available..." green
for patch in $scriptPath/patches/$project/*.patch ; do
coloredEcho " | Applying patch $patch..." green
git am $patch
done
git submodule update --init &> /dev/null
coloredEcho "Finished" yellow
exit 0