Skip to content

Commit 91c037e

Browse files
authored
Merge pull request element-hq#8225 from jryans/fetch-more-branches
Try fetching more branches for PRs
2 parents 6d7492d + cf150fc commit 91c037e

1 file changed

Lines changed: 29 additions & 27 deletions

File tree

‎scripts/fetch-develop.deps.sh‎

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,45 +9,47 @@
99
set -e
1010

1111
GIT_CLONE_ARGS=("$@")
12-
13-
# Look in the many different CI env vars for which branch we're
14-
# building
15-
if [[ "$TRAVIS" == true ]]; then
16-
curbranch="${TRAVIS_PULL_REQUEST_BRANCH:-$TRAVIS_BRANCH}"
17-
else
18-
# ghprbSourceBranch for jenkins github pull request builder
19-
# GIT_BRANCH for other jenkins builds
20-
curbranch="${ghprbSourceBranch:-$GIT_BRANCH}"
21-
# Otherwise look at the actual branch we're on
22-
if [ -z "$curbranch" ]
23-
then
24-
curbranch=`git rev-parse --abbrev-ref HEAD`
25-
fi
26-
fi
27-
28-
# Chop 'origin' off the start as jenkins ends up using
29-
# branches on the origin, but this doesn't work if we
30-
# specify the branch when cloning.
31-
curbranch=${curbranch#origin/}
32-
33-
echo "Determined branch to be $curbranch"
12+
[ -z "$defbranch" ] && defbranch="develop"
3413

3514
# clone a specific branch of a github repo
3615
function clone() {
3716
org=$1
3817
repo=$2
3918
branch=$3
40-
git clone https://github.com/$org/$repo.git $repo --branch $branch \
41-
"${GIT_CLONE_ARGS[@]}"
19+
20+
# Chop 'origin' off the start as jenkins ends up using
21+
# branches on the origin, but this doesn't work if we
22+
# specify the branch when cloning.
23+
branch=${branch#origin/}
24+
25+
if [ -n "$branch" ]
26+
then
27+
echo "Trying to use $org/$repo#$branch"
28+
git clone https://github.com/$org/$repo.git $repo --branch $branch \
29+
"${GIT_CLONE_ARGS[@]}"
30+
fi
4231
}
4332

4433
function dodep() {
4534
org=$1
4635
repo=$2
4736
rm -rf $repo
48-
clone $org $repo $curbranch || {
49-
[ "$curbranch" != 'develop' ] && clone $org $repo develop
50-
} || return $?
37+
38+
# Try the PR author's branch in case it exists on the deps as well.
39+
# Try the target branch of the push or PR.
40+
# Use the default branch as the last resort.
41+
if [[ "$TRAVIS" == true ]]; then
42+
clone $org $repo $TRAVIS_PULL_REQUEST_BRANCH ||
43+
clone $org $repo $TRAVIS_BRANCH ||
44+
clone $org $repo $defbranch ||
45+
return $?
46+
else
47+
clone $org $repo $ghprbSourceBranch ||
48+
clone $org $repo $GIT_BRANCH ||
49+
clone $org $repo `git rev-parse --abbrev-ref HEAD` ||
50+
clone $org $repo $defbranch ||
51+
return $?
52+
fi
5153

5254
echo "$repo set to branch "`git -C "$repo" rev-parse --abbrev-ref HEAD`
5355

0 commit comments

Comments
 (0)