-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkForAnitaBuildToolUpdate.sh
executable file
·62 lines (51 loc) · 1.71 KB
/
checkForAnitaBuildToolUpdate.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
#!/bin/bash
# First check if we have a .git subdirectory
if [ ! -d ".git" ]; then
echo "Error! Could not find .git subdirectory!"
echo "anitaBuildTool must be cloned from the anitaBuildTool repository. Aborting build."
echo "If you did not get the anitaBuildTool by running this command:"
echo ""
echo " git clone https://github.com/anitaNeutrino/anitaBuildTool"
echo ""
echo "then please redownload this repository using the above command"
echo "(this will create a directory called anitaBuildTool initialised with git)"
exit 1;
fi;
method=$(head -1 clone_method)
#echo $method
desiredUrl="https://github.com/anitaNeutrino/anitaBuildTool.git"
if [ "${method}" = "ssh" ]; then
desiredUrl="git@github.com:anitaNeutrino/anitaBuildTool.git"
fi
currentUrl=$(git remote get-url origin)
if [ "${currentUrl}" = "${desiredUrl}" ]; then
echo -n ""
else
echo "Updating anitaBuildTool clone_method"
git remote set-url origin ${desiredUrl}
git remote -v
fi
# Update the repository
git fetch
fetchSuccess=$?
if [ ${fetchSuccess} -gt 0 ]; then
echo "Error! anitaBuildTool could not connect to remote repository. Aborting build."
exit 2;
fi;
LOCAL=$(git rev-parse @{0})
REMOTE=$(git rev-parse @{u})
BASE=$(git merge-base @{0} @{u})
if [ $LOCAL = $REMOTE ]; then
echo "anitaBuildTool is up to date."
elif [ $LOCAL = $BASE ]; then
echo "Local anitaBuildTool is behind upstream. Attempting merge."
git merge origin/master
exit 1
elif [ $REMOTE = $BASE ]; then
echo "Local anitaBuildTool is ahead of upstream. Consider pushing your changes."
else
echo "Local anitaBuildTool has diverged from upstream. Aborting update."
exit 3;
fi;
echo "Continuing build."
exit 0;