-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathfetch-branch.sh
executable file
·50 lines (43 loc) · 1.27 KB
/
fetch-branch.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
#!/bin/sh
#
# Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
#
# SPDX-License-Identifier: BSD-2-Clause
# Fetches the branch in ${GITHUB_REF} into a repo manifest checkout.
# Does nothing if INPUT_XML is set, because that means we have already done this.
if [ -z "${INPUT_XML}" ]
then
# Assumes a repo manifest checkout, and current working dir in the repo
# to fetch the branch for.
REPO_PATH="github.com/${GITHUB_REPOSITORY}.git"
if [ -n "${INPUT_TOKEN}" ]
then
URL="https://${INPUT_TOKEN}@${REPO_PATH}"
REPO_PATH="token@${REPO_PATH}"
else
URL="https://${REPO_PATH}"
fi
# if an explicit SHA is set as INPUT (e.g. for pull request target), prefer that
if [ -n "${INPUT_SHA}" ]
then
REF=${INPUT_SHA}
FETCH=${REF}
# if GITHUB_SHA is available, prefer that over REF, because the branch GITHUB_REF
# refers to may have been pushed to again to since we have been invoked.
elif [ -n "${GITHUB_SHA}" ]
then
REF=${GITHUB_SHA}
FETCH=${REF}
# if nothing better is available, use GITHUB_REF
else
REF=${GITHUB_REF}
FETCH=${REF}:${REF}
fi
echo "Fetching ${REF} from ${REPO_PATH}"
git fetch -q --depth 1 ${URL} ${FETCH}
git checkout -q ${REF}
if [ -n "${BRANCH_NAME}" ]
then
git checkout -b "${BRANCH_NAME}"
fi
fi