Skip to content

Commit 2756e12

Browse files
committed
Added a possibility to pass the branch or tag name to the update-all script.
1 parent 0ca9357 commit 2756e12

1 file changed

Lines changed: 35 additions & 10 deletions

File tree

scripts/update-all.sh

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ NC='\033[0m' # No Color
66

77
bypass=0
88
forceClearCache=0
9-
while getopts "hbc" option
9+
frontendRef=""
10+
while getopts "hbcf:" option
1011
do
1112
case $option in
1213
h)
1314
echo -e "Update or install all Monarc modules, frontend views and migrate database."
1415
echo -e "\t-b\tbypass migrate database"
1516
echo -e "\t-c\tforce clear cache"
17+
echo -e "\t-f\tfrontend git branch/tag to use for ng_backoffice and ng_anr"
1618
echo -e "\t-h\tdisplay this message"
1719
exit 1
1820
;;
@@ -23,20 +25,43 @@ do
2325
c)
2426
forceClearCache=1
2527
;;
28+
f)
29+
frontendRef="$OPTARG"
30+
;;
2631
esac
2732
done
2833

29-
checkout_to_latest_tag() {
30-
if [ -d $1 ]; then
31-
pushd $1
32-
git fetch --tags
33-
tag=$(git describe --tags `git rev-list --tags --max-count=1`)
34-
git checkout $tag -b $tag
35-
git pull origin $tag
34+
checkout_repo_ref() {
35+
if [ -d "$1" ]; then
36+
pushd "$1"
37+
if [[ -n "$2" ]]; then
38+
git fetch origin "$2"
39+
if git show-ref --verify --quiet "refs/heads/$2"; then
40+
git checkout "$2"
41+
else
42+
git checkout -B "$2" --track "origin/$2"
43+
fi
44+
git pull origin "$2"
45+
else
46+
git fetch --tags
47+
tag=$(git describe --tags `git rev-list --tags --max-count=1`)
48+
if git show-ref --verify --quiet "refs/heads/$tag"; then
49+
git checkout "$tag"
50+
else
51+
git checkout -b "$tag" "$tag"
52+
fi
53+
git pull origin "$tag"
54+
fi
3655
popd
3756
fi
3857
}
3958

59+
checkout_to_ref_if_set_or_latest_tag() {
60+
if [ -d "$1" ]; then
61+
checkout_repo_ref "$1" "$2"
62+
fi
63+
}
64+
4065
pull_if_exists() {
4166
if [ -d $1 ]; then
4267
pushd $1
@@ -80,8 +105,8 @@ fi
80105

81106
if [[ -d node_modules && -d node_modules/ng_anr ]]; then
82107
if [[ -d node_modules/ng_anr/.git ]]; then
83-
checkout_to_latest_tag node_modules/ng_backoffice
84-
checkout_to_latest_tag node_modules/ng_anr
108+
checkout_to_ref_if_set_or_latest_tag node_modules/ng_backoffice "$frontendRef"
109+
checkout_to_ref_if_set_or_latest_tag node_modules/ng_anr "$frontendRef"
85110
else
86111
npm update
87112
fi

0 commit comments

Comments
 (0)