forked from ulx3s/ulx3s-toolchain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch_github.sh
executable file
·114 lines (101 loc) · 3.32 KB
/
fetch_github.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
105
106
107
108
109
110
111
112
113
114
#!/bin/bash
#"***************************************************************************************************"
# fetch_github.sh URL directoryName [hash]
#"***************************************************************************************************"
# when we get here, we are typically already in $WORKSPACE, ready to clone to a new directory
#
# perform some version control checks on this file
# $SAVED_CURRENT_PATH/gitcheck.sh $0
#
# we don't want tee to capture exit codes
set -o pipefail
# ensure we alwaye start from the $WORKSPACE directory
cd "$WORKSPACE"
echo ""
echo "fetch_github.sh working directory: $(pwd) with parameters:"
echo ""
THIS_REPO_URL=$1
THIS_DIR=$2
THIS_CHECKOUT=$3
THIS_ERROR=0
echo "THIS_REPO_URL = $THIS_REPO_URL"
echo "THIS_DIR = $THIS_DIR"
echo "THIS_CHECKOUT = $THIS_CHECKOUT"
echo ""
if [ "$THIS_DIR" != "" ]; then
if [ ! -d "$WORKSPACE"/$THIS_DIR ]; then
echo ""
echo "git clone $THIS_REPO_URL $THIS_DIR"
git clone --recursive $THIS_REPO_URL $THIS_DIR
if [ "$?" != "0" ]; then
echo ""
echo "Error encountered during: git clone --recursive $THIS_REPO_URL $THIS_DIR"
exit 1
fi
cd $THIS_DIR
else
cd $THIS_DIR
git remote show origin
THIS_UPSTREAM=$(git remote show origin | grep Fetch)
echo ""
echo "git fetch; # using upstream: $THIS_UPSTREAM"
git fetch
if [ "$?" != "0" ]; then
echo ""
echo "Error encountered during: git fetch; # $THIS_UPSTREAM"
exit 1
fi
echo ""
echo "git submodule update; # $THIS_UPSTREAM"
git submodule update
if [ "$?" != "0" ]; then
echo ""
echo "Error encountered during: git submodule update; # $THIS_UPSTREAM"
exit 1
fi
# before pulling in changes, check out master to ensure we are not detached
echo ""
echo "git checkout master; # $THIS_UPSTREAM"
git checkout master
if [ "$?" != "0" ]; then
echo ""
echo "Error encountered during: git checkout master; # $THIS_UPSTREAM"
echo ""
echo "Consider: git checkout . # warning! abandon all changes and check everything out"
exit 1
fi
echo ""
echo "git pull; # $THIS_UPSTREAM"
echo ""
git pull
if [ "$?" != "0" ]; then
echo ""
echo "Error encountered during: git pull; # $THIS_UPSTREAM"
echo ""
echo "Consider: git clean -df # warning! recursive, forced removal of untracked directories in addition to untracked files"
echo " and : git checkout . # warning! abandon all changes and check everything out"
echo ""
exit 1
fi
echo ""
echo "My checkout = $THIS_CHECKOUT; upstream = $THIS_UPSTREAM"
if [ "$THIS_CHECKOUT" != "" ] && [ "$THIS_CHECKOUT" != "master" ]; then
echo ""
echo "git checkout $THIS_CHECKOUT; # $THIS_REPO_URL"
git checkout $THIS_CHECKOUT
if [ "$?" != "0" ]; then
echo ""
echo "Error encountered during: git checkout $THIS_CHECKOUT; # $THIS_REPO_URL"
exit 1
fi
fi
fi
else
echo ""
echo "ERROR: Missing parameters for fetch_github.sh"
echo ""
echo "fetch_github.sh URL directoryName [hash]"
exit 1
fi
echo "git log: $(git log --pretty=format:'%h' -n 1)"
echo ""