-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdx86-tag
executable file
·99 lines (83 loc) · 2.21 KB
/
pdx86-tag
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
#!/bin/sh
PROG_NAME="${0##*/}"
PROG_DIR="${0%/*}"
. $PROG_DIR/pdx86-config
usage() {
echo "Usage: $PROG_NAME [options] <VERSION> <COMMIT>"
echo "e.g. $PROG_NAME v4.4-2 for-next"
}
exit_on_error() {
local code="$1"; shift
local msg="$1"; shift
[ $code -eq 0 ] && return 0
echo "$msg"
exit $code
}
new_tag_prefix="$TAG_PREFIX"
while [ "$#" -ge "1" ]; do
case "$1" in
-t)
new_tag_prefix="$2"; shift;;
*)
break;;
esac
shift
done
if [ $# -ne 2 ]; then
echo $#
usage
exit 1
fi
VERSION="v${1##*v}" # Always produce "v4.4-2"-like version
COMMIT_RANGE=$2 # Whatever commit ID Git recognizes
TAG="${new_tag_prefix}-${VERSION}"
# Verify the tag does not already exist
git rev-parse $TAG > /dev/null 2>&1 && exit_on_error 1 "Tag already exists: $TAG"
# Perform a sanity check before creating the tag
$PROG_DIR/pdx86-cherry $2
if [ $? -ne 0 ]; then
echo "Duplicate commits detected, tag anyway? [y/N] "
read RESPONSE
[ "$RESPONSE" = "y" -o "$RESPONSE" = "Y" ] || exit_on_error $? "Aborted by user"
fi
TMP=
which tempfile > /dev/null 2>&1
if [ $? -eq 0 ]; then
TMP=$(tempfile -s .$PROG_NAME)
else
which mktemp > /dev/null 2>&1
if [ $? -eq 0 ]; then
TMP=$(mktemp --suffix=.$PROG_NAME)
fi
fi
[ -n "$TMP" ] || exit_on_error $? "ERROR: Failed to create a suitable temp file"
COMMIT="$(echo $COMMIT_RANGE | sed -e 's,\(.\+\)\.\.\(.\+\),\2,')"
[ "$COMMIT_RANGE" = "$COMMIT" ] && COMMIT_RANGE="$MASTER..$COMMIT"
PREFIX=''
(
echo "$new_tag_prefix for $VERSION";
echo "";
echo "WRITEME: Highlights and summary";
echo "";
echo "The following is an automated git shortlog grouped by driver:";
git log --pretty='format:%s' $COMMIT_RANGE | \
sed -e "s,^$SUBJ_PREFIX: \?,," | \
sort -k1,1 -t ':' -s | \
while read line || [ -n "$line" ]; do
NEW_PREFIX=$(echo $line | cut -d ':' -f1)
SUBJECT=$(echo $line | cut -d ':' -f2-)
if [ "$PREFIX" != "$NEW_PREFIX" ]; then
echo ""
echo "$NEW_PREFIX:"
PREFIX="$NEW_PREFIX"
fi
echo " - $SUBJECT"
done
) > $TMP
$EDITOR $TMP
exit_on_error $? "ERROR: Editor exited with error code $?."
git tag -s -F $TMP -a $new_tag_prefix-$VERSION $COMMIT
exit_on_error $? "git tag failed. Edited tag message saved in $TMP."
echo "Created tag: $TAG"
echo "Push with 'git push $REMOTE $TAG'"
rm $TMP