-
Notifications
You must be signed in to change notification settings - Fork 0
/
gear-create-tag
executable file
·180 lines (157 loc) · 5.05 KB
/
gear-create-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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/bin/sh -efu
#
# Copyright (C) 2007-2014 Alexey Gladkov <[email protected]>
# Copyright (C) 2007-2021 Dmitry V. Levin <[email protected]>
# Copyright (C) 2008 Alexey I. Froloff <[email protected]>
#
# gear-create-tag - create a signed release tag object.
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
#
. gear-utils-sh-functions
print_version()
{
cat <<EOF
$PROG version $PROG_VERSION
Written by Alexey Gladkov <[email protected]>
Copyright (C) 2007-2014 Alexey Gladkov <[email protected]>
Copyright (C) 2007-2021 Dmitry V. Levin <[email protected]>
Copyright (C) 2008 Alexey I. Froloff <[email protected]>
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
EOF
exit
}
show_help()
{
cat <<EOF
$PROG - create a signed release tag object for the given commit object
Usage: $PROG [commit-ish]
Options:
-f, --force replace an existing tag (instead of failing);
-u, --key-id=KEYID use the given GPG key to create a signed tag;
-m, --message=TEXT override custom tag message
(default: <NAME> <VERSION>-<RELEASE>);
-n, --name=TEXT override custom tag name
(default: <VERSION>-<RELEASE>);
-r, --rules=FILENAME override rules file name;
-s, --specsubst=VARIABLE=VALUE
add specsubst definition to the tag message,
this option can be specified more than once;
-t, --time=DATE-FMT set the date used in tag;
-q, --quiet try to be more quiet;
-v, --verbose print a message for each action;
-V, --version print program version and exit;
-h, --help show this text and exit.
Report bugs to https://bugzilla.altlinux.org/
EOF
exit
}
TEMP=$(getopt -n $PROG -o f,m:,n:,r:,s:,t:,u:,q,v,V,h -l force,key-id:,message:,name:,rules:,specsubst:,time:,quiet,verbose,version,help -- "$@") ||
show_usage
eval set -- "$TEMP"
force=
keyid=
opt_s='-s'
nl='
'
specsubst_prefix='X-gear-specsubst: '
specsubst_msg=
gear_config_option tag_name name '@version@-@release@'
gear_config_option tag_msg message '@name@ @version@-@release@'
main_tree_id='HEAD'
while :; do
case "$1" in
-f|--force) force=-f
;;
-m|--message) shift; tag_msg="$1"
;;
-n|--name) shift; tag_name="$1"
;;
-r|--rules) shift; rules="$1"
;;
-s|--specsubst)
case "$2" in
[^=]*=*)
[ -z "$(printf %s "${2%%=*}" |
LANG=C tr -d '[:alnum:]_')" ] ||
fatal "invalid $1 value: $2" ;;
*) fatal "invalid $1 value: $2" ;;
esac
shift
specsubst_msg="$specsubst_msg$nl$specsubst_prefix$1"
;;
-t|--time) shift
[ -z "$1" ] ||
export GIT_COMMITTER_DATE="$1"
;;
-u|--key-id) shift; keyid="$1"; opt_s=
;;
-q|--quiet) quiet=-q verbose=
;;
-v|--verbose) verbose=-v quiet=
;;
-V|--version) print_version
;;
-h|--help) show_help
;;
--) shift; break
;;
*) fatal "unrecognized option: $1"
;;
esac
shift
done
if [ "$#" -gt 0 ]; then
main_tree_id="$1"
shift
fi
[ "$#" -eq 0 ] ||
show_usage 'Too many arguments.'
chdir_to_toplevel
main_commit_sha1="$(get_commit_sha1 "$main_tree_id")" ||
fatal "$main_tree_id: Invalid commit object name"
disable_specsubst=1
install_cleanup_handler cleanup_workdir
workdir="$(mktemp -dt "$PROG.XXXXXXXXXX")"
find_specfile
subst_NVR_from_spec_file '' tag_name tag_msg
[ -z "$specsubst_msg" ] ||
tag_msg="$tag_msg$nl$specsubst_msg"
# Check whether all required specsubst variables are defined in the tag message.
# The implementation is derived from substitute_vars_in_spec().
get_uniq_directive_from_rules specsubst specsubst
[ -z "$(printf %s "$specsubst" |LANG=C tr -d '[:alnum:]_[:space:]')" ] ||
rules_error "Invalid specsubst value \"$specsubst\" specified"
# $specsubst is a space-separated sequence of alphanumerics
for var in $specsubst; do
printf %s "$tag_msg" |
grep -qs "^X-gear-specsubst:[[:space:]]\\+$var=" ||
fatal "specsubst variable \"$var\" is not defined in the tag message"
done
unset var
cleanup_workdir
uninstall_cleanup_handler
[ -n "$quiet" ] ||
message "Creating tag named \"$tag_name\" using tag message \"$tag_msg\" for commit $main_commit_sha1"
rc=0
git tag $force $opt_s ${keyid:+-u "$keyid"} -m "$tag_msg" "$tag_name" "$main_commit_sha1" ||
rc=$?
if [ -z "$quiet" ]; then
[ "$rc" = 0 ] &&
message "Created tag \"$tag_name\"" ||
message "Failed to create tag \"$tag_name\""
fi
exit $rc