aboutsummaryrefslogtreecommitdiff
path: root/apply-pullreq
blob: 0abab0c1660c3a4f4ee2033fafd6e922d32b52fe (plain)
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
#!/bin/sh -e

# Apply a pull request

# Copyright (C) 2014 Linaro Limited
# Author: Peter Maydell <peter.maydell@linaro.org>
# This work is licensed under the terms of the GNU GPL version 2 or later.

# Expects two arguments:  remote-url remote-branch-or-tagname

# This makes a bunch of assumptions about repo setup and
# preferred build-and-test commands.

SIGNOFF='Peter Maydell <peter.maydell@linaro.org>'

VRFY=yes

if [ $# != 0 ] && [ "$1" = "--no-verify-sig" ]; then
    shift
    VRFY=no
fi

if [ $# != 2 ]; then
    echo "Usage: apply-pullreq remote-url branch-or-tagname"
    exit 1
fi

REMOTEURL="$1"
REMOTETAG="$2"

# hard newline
NL='
'

BRANCH="$(git symbolic-ref -q HEAD || true)"
# NB that in the "detached head" case BRANCH will be the empty string

if [ "$BRANCH" != "refs/heads/staging" ]; then
    echo "Must be on staging branch"
    exit 1
fi

git checkout master
git pull
git checkout staging

if [ "$(git rev-parse master)" != "$(git rev-parse staging)" ]; then
    echo "staging not up to date : suggest 'git reset --hard master'"
    exit 1
fi

# Find the remote name corresponding to the URL. Note that we
# assume that any protocol on the remote is the same thing, and
# that a trailing ".git" makes no difference. This helps when
# submaintainers switch from specifying git:// to https:// and
# so on (particularly common with github URLs for some reason).

# trim leading protocol spec and trailing .git (if any)
REMURL=${REMOTEURL#*:}
REMURL=${REMURL%.git}
FGREPARG="$REMURL (fetch)$NL$REMURL.git (fetch)"

REMOTENAME="$(git remote -v | grep -F "$FGREPARG" | cut -f1)"

if [ -z "$REMOTENAME" ]; then
    echo "Unknown remote $REMOTEURL: add manually via"
    echo "add-merge-remote REMOTENAME $REMOTEURL"
    exit 1
fi

echo "fetching from remote $REMOTENAME"
git fetch "$REMOTENAME"

if [ "$VRFY" = "yes" ]; then
    if ! git verify-tag "remotes/$REMOTENAME/$REMOTETAG"; then
        echo "Does not appear to be a signed tag"
        echo "(use --no-verify-sig to override)"
        exit 1
    fi
fi

echo "merging..."
git merge --no-edit --no-ff "remotes/$REMOTENAME/$REMOTETAG"
# Edit the merge commit to add our signoff line
(git log -1 --format=%B HEAD ; echo "Signed-off-by: $SIGNOFF") | git commit --amend --file=-

# Check whether there seems to be a submodule update here. NB that this
# can have false positives..
if git diff master..staging | grep -q 'Subproject commit'; then
    echo "WARNING: pull appears to include submodule update, please check it!"
fi

# This should exit with an error status if any of the sub-builds fails.
parallel-buildtest

echo "WARNING: please check these results files!"

echo "Looks good; trying a dry-run publish:"
git push --dry-run publish-upstream staging:master

# For obvious reasons we don't let the script automatically
# do the publish to upstream master...

echo "OK; to publish for real run:"
echo "git push publish-upstream staging:master"