-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpdx86-pull-request
executable file
·121 lines (95 loc) · 2.54 KB
/
pdx86-pull-request
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
115
116
117
118
119
120
121
#!/bin/sh
PROG_NAME="${0##*/}"
PROG_DIR="${0%/*}"
. $PROG_DIR/pdx86-config
MAINTAINERS_FILE="$PROG_DIR/MAINTAINERS"
MAINTAINERS_DEFAULT="Darren Hart <dvhart@infradead.org>, Andy Shevchenko <andy@infradead.org>"
ML="LKML <linux-kernel@vger.kernel.org>"
MM="Linus Torvalds <torvalds@linux-foundation.org>"
usage() {
echo "usage: $PROG_NAME <TAG|IB>"
}
TAG_RANGE=$1
if [ $# -ne 1 ] || [ -z "$TAG_RANGE" ]; then
echo "ERROR: invalid arguments"
usage
exit 1
fi
BASE="$(echo $TAG_RANGE | sed -e 's,\(.\+\)\.\.\(.\+\),\1,')"
TAG="$(echo $TAG_RANGE | sed -e 's,\(.\+\)\.\.\(.\+\),\2,')"
[ "$BASE" = "$TAG" ] && BASE="$MASTER"
git cat-file -e $TAG 2>/dev/null
if [ $? -ne 0 ]; then
echo "$TAG is not a git object"
exit 1
fi
TAG_TYPE=$(git cat-file -t $TAG)
# Check if it's not an existing tag
if [ "$TAG_TYPE" != "tag" ]; then
IB=$(git name-rev --name-only --refs="$IB_PREFIX-*" $TAG)
# Check if it's undefined name reference
if [ "$IB" = "undefined" ]; then
echo "ERROR: $TAG is not a tag (it's a $TAG_TYPE)"
usage
exit 1
fi
# Check if it's not an immutable branch
if [ -z $(git branch --list --format="%(objectname)" "$IB") ]; then
echo "ERROR: $TAG is not an immutable branch"
usage
exit 1
fi
fi
MSG=$TAG.$PROG_NAME
if [ -e $MSG ]; then
echo "ERROR: $MSG exists, remove or rename and try again."
exit 1
fi
case "$TAG_TYPE" in
tag)
SUBJECT=$(echo $TAG | sed -e "s/\($TAG_PREFIX\)-v\(.*\)/\1 for \2/" || echo $TAG)
BODY="WRITEME: Anything relevant to the merge itself, but not the content."
;;
commit)
SUBJECT=$(echo $TAG | sed -e "s/$IB_PREFIX-\(.*\)/immutable branch for \1/" || echo $TAG)
BODY="Please, pull immutable branch between $TAG_PREFIX and your subsystem."
;;
esac
USERNAME=$(git config --get user.name)
USEREMAIL=$(git config --get user.email)
if [ -s ~/.signature ]; then
SIGNATURE=$(cat ~/.signature)
else
SIGNATURE="$USERNAME"
fi
if [ -s "$MAINTAINERS_FILE" ]; then
MAINTAINERS=$(sed -e '$!s/$/, /' $MAINTAINERS_FILE | tr -d '\n')
else
MAINTAINERS="$MAINTAINERS_DEFAULT"
fi
cat > $MSG << EOM
From: $USERNAME <$USEREMAIL>
Date: $(date -R)
To: $MM
Cc: $ML, $MAINTAINERS
Subject: [GIT PULL] $SUBJECT
Hi $(echo $MM | cut -f1 -d' '),
$BODY
Thanks,
$SIGNATURE
EOM
git request-pull $BASE $GIT_URL $TAG >> $MSG
if [ $? -ne 0 ]; then
rm $MSG
echo "ERROR: request pull failed"
exit 1
fi
# Replace SSH protocol based URL by Git
sed -i -e 's,git@gitolite.kernel.org:,git://git.kernel.org/,' $MSG
vim $MSG +3
if [ $? -ne 0 ]; then
rm $MSG
echo "ERROR: message editor failed"
exit 1
fi
echo "Use 'mutt -H $MSG' to send the pull request."