git-rev-label 2.15.13 → 2.18.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -7
- package/git-rev-label +86 -43
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -71,19 +71,18 @@ More info at https://gitlab.com/kyb/git-rev-label
|
|
|
71
71
|
or create executable file git-rev-label in PATH with the same contents.
|
|
72
72
|
|
|
73
73
|
## Install
|
|
74
|
-
####
|
|
74
|
+
#### Raw without package manager
|
|
75
75
|
```
|
|
76
|
-
|
|
76
|
+
curl -fsSL 'https://gitlab.com/kyb/git-rev-label/raw/artifacts/master/git-rev-label' | sudo bash -s -- --install
|
|
77
77
|
```
|
|
78
78
|
*Warning: sudo under hood.*
|
|
79
79
|
|
|
80
|
-
|
|
80
|
+
##### Manual to `$HOME/bin` without sudo:
|
|
81
81
|
```
|
|
82
|
-
|
|
83
|
-
bash ./git-rev-label --install --install-dir=$HOME/bin
|
|
82
|
+
curl -fsSL 'https://gitlab.com/kyb/git-rev-label/raw/artifacts/master/git-rev-label' | bash -s -- --install=$HOME/bin
|
|
84
83
|
```
|
|
85
84
|
|
|
86
|
-
|
|
85
|
+
Then make sure `$HOME/bin` is in `$PATH`:
|
|
87
86
|
* bash
|
|
88
87
|
```
|
|
89
88
|
[[ ":$PATH:" != *":$HOME/bin:"* ]] && PATH="$HOME/bin:$PATH"
|
|
@@ -96,7 +95,7 @@ Make sure `$HOME/bin` is in `$PATH`:
|
|
|
96
95
|
#### with [NPM](https://npm.org)
|
|
97
96
|
npm install --global git-rev-label
|
|
98
97
|
|
|
99
|
-
#### with [Homebrew](https://brew.sh)
|
|
98
|
+
#### with [Homebrew](https://brew.sh) **OUTDATED**
|
|
100
99
|
```
|
|
101
100
|
brew tap ivakyb/git-rev-label
|
|
102
101
|
brew install git-rev-label
|
|
@@ -104,6 +103,14 @@ brew install git-rev-label
|
|
|
104
103
|
|
|
105
104
|
|
|
106
105
|
-----------------------
|
|
106
|
+
|
|
107
|
+
## Examples
|
|
108
|
+
Take a look into [build_info-header](build_info-header).
|
|
109
|
+
It shows how `git-rev-label` is used to generate C header file `build_info.h`
|
|
110
|
+
with information about version extracted from Git.
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
107
114
|
-----------------------
|
|
108
115
|
|
|
109
116
|
|
package/git-rev-label
CHANGED
|
@@ -11,20 +11,39 @@
|
|
|
11
11
|
## or
|
|
12
12
|
## git rev-label '$refname-c$count-g$short$_dirty'
|
|
13
13
|
|
|
14
|
+
# shellcheck disable=SC2016 ## single quotes are intended not to be expanded
|
|
15
|
+
# shellcheck disable=SC2215 ## --function-name is used to coinside with flags
|
|
16
|
+
# shellcheck disable=SC2145 ## no real reason to replace $@ with $*
|
|
17
|
+
# shellcheck disable=SC2317 ## something appears to be unreachable, but it can be used indirectly or optionally
|
|
18
|
+
|
|
14
19
|
set -eEuo pipefail
|
|
15
20
|
shopt -s inherit_errexit
|
|
16
21
|
shopt -s lastpipe
|
|
22
|
+
shopt -s expand_aliases
|
|
23
|
+
|
|
24
|
+
VERSION=master-c18-g76653fe-b15
|
|
25
|
+
VERSION_NPM=2.18.15
|
|
17
26
|
|
|
18
|
-
|
|
19
|
-
|
|
27
|
+
## todo maybe use utils.bash from autorsync
|
|
28
|
+
function echomsg { echo $'\e[1;37m'"$@"$'\e[0m'; }
|
|
29
|
+
function echodbg { >&2 echo $'\e[0;36m'"$@"$'\e[0m'; }
|
|
30
|
+
function echowarn { >&2 echo $'\e[0;33m'WARNING$'\e[0m' "$@"; }
|
|
31
|
+
function echoerr { >&2 echo $'\e[0;31m'ERROR$'\e[0m' "$@"; }
|
|
32
|
+
function fatalerr { >&2 echoerr "$@"; exit 1; }
|
|
20
33
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
34
|
+
if test "$(uname)" == 'Darwin' ;then
|
|
35
|
+
alias sed=gsed
|
|
36
|
+
alias grep=ggrep
|
|
37
|
+
alias find=gfind
|
|
38
|
+
alias date=gdate
|
|
39
|
+
alias cp=gcp
|
|
40
|
+
alias mv=gmv
|
|
41
|
+
alias ls=gls
|
|
42
|
+
alias mktemp=gmktemp
|
|
43
|
+
alias readlink=greadlink
|
|
44
|
+
fi
|
|
26
45
|
|
|
27
|
-
function OnErr { caller | { read lno file; echoerr ">ERR in $file:$lno, $(sed -n $
|
|
46
|
+
function OnErr { caller | { read -r lno file; echoerr ">ERR in $file:$lno, $(sed -n "$lno"p "$file")" >&2; }; }
|
|
28
47
|
trap OnErr ERR
|
|
29
48
|
|
|
30
49
|
is_sourced(){
|
|
@@ -55,9 +74,9 @@ var_is_unset_or_empty(){
|
|
|
55
74
|
function --help {
|
|
56
75
|
echo -n \
|
|
57
76
|
'Gives information about Git repository revision in format like '"'master-c73-gbbb6bec'"'.
|
|
58
|
-
Can fill template string or file with environment variables and information from Git.
|
|
59
|
-
Useful to provide information about version of the program: branch, tag, commit hash,
|
|
60
|
-
commits count, dirty status, date and time. One of the most useful things is count of
|
|
77
|
+
Can fill template string or file with environment variables and information from Git.
|
|
78
|
+
Useful to provide information about version of the program: branch, tag, commit hash,
|
|
79
|
+
commits count, dirty status, date and time. One of the most useful things is count of
|
|
61
80
|
commits, not taking into account merged branches - only first parent.
|
|
62
81
|
|
|
63
82
|
USAGE:
|
|
@@ -72,8 +91,8 @@ USAGE:
|
|
|
72
91
|
eval $(git rev-label --variables | sed s,^,export\ ,) ## Export variables to environment
|
|
73
92
|
|
|
74
93
|
COMPLEX USE CASE:
|
|
75
|
-
* Fill `build_info.template.h` with branch, tag, commit hash, commits count, dirty status.
|
|
76
|
-
Than include result header to access build information from code.
|
|
94
|
+
* Fill `build_info.template.h` with branch, tag, commit hash, commits count, dirty status.
|
|
95
|
+
Than include result header to access build information from code.
|
|
77
96
|
See https://gitlab.com/kyb/git-rev-label/blob/master/build_info.template.h and
|
|
78
97
|
https://gitlab.com/kyb/git-rev-label/blob/master/create-build-info.sh
|
|
79
98
|
|
|
@@ -87,7 +106,7 @@ More info at https://gitlab.com/kyb/git-rev-label
|
|
|
87
106
|
'
|
|
88
107
|
}
|
|
89
108
|
function --version {
|
|
90
|
-
echo "git-rev-label v$VERSION_NPM
|
|
109
|
+
echo "git-rev-label v$VERSION_NPM
|
|
91
110
|
$VERSION
|
|
92
111
|
https://gitlab.com/kyb/git-rev-label"
|
|
93
112
|
}
|
|
@@ -99,6 +118,7 @@ function --rev-label {
|
|
|
99
118
|
--version-npm(){ echo $VERSION_NPM; }
|
|
100
119
|
--npm-version(){ --version-npm "$@"; }
|
|
101
120
|
|
|
121
|
+
# shellcheck disable=SC2086 ## varname cannot contain spaces
|
|
102
122
|
set_with_warn(){
|
|
103
123
|
varname=$1
|
|
104
124
|
shift
|
|
@@ -106,7 +126,7 @@ set_with_warn(){
|
|
|
106
126
|
declare -g $varname="$@"
|
|
107
127
|
}
|
|
108
128
|
set_action(){
|
|
109
|
-
set_with_warn action $1
|
|
129
|
+
set_with_warn action "$1"
|
|
110
130
|
}
|
|
111
131
|
|
|
112
132
|
readonly FULL_LIST="commit short SHORT long LONG count COUNT dirty _dirty DIRTY _DIRTY tag branch refname"
|
|
@@ -114,9 +134,9 @@ readonly FULL_LIST="commit short SHORT long LONG count COUNT dirty _dirty DI
|
|
|
114
134
|
## Unset variables from environment
|
|
115
135
|
unset format install_dir
|
|
116
136
|
|
|
117
|
-
while
|
|
118
|
-
case $1 in
|
|
119
|
-
--help|-help|help|-h|\?|-\?)
|
|
137
|
+
while (( $# > 0 )) ;do
|
|
138
|
+
case $1 in
|
|
139
|
+
--help|-help|help|-h|\?|-\?)
|
|
120
140
|
--help
|
|
121
141
|
exit
|
|
122
142
|
;;
|
|
@@ -125,7 +145,7 @@ while [[ $# > 0 ]] ;do
|
|
|
125
145
|
exit
|
|
126
146
|
;;
|
|
127
147
|
--install-link|--install|--install-script|--update|--update-script)
|
|
128
|
-
set_action $1
|
|
148
|
+
set_action "$1"
|
|
129
149
|
;;
|
|
130
150
|
--install-dir=*)
|
|
131
151
|
set_with_warn install_dir "${1##--install-dir=}"
|
|
@@ -142,15 +162,15 @@ while [[ $# > 0 ]] ;do
|
|
|
142
162
|
force=f
|
|
143
163
|
;;
|
|
144
164
|
--variables|--vars|-v)
|
|
145
|
-
set_action $1
|
|
165
|
+
set_action "$1"
|
|
146
166
|
format=$(echo "$FULL_LIST" | sed -E 's, *([A-Za-z_]+),\1=\$\1\n,g')
|
|
147
167
|
--variables(){ default_action; }
|
|
148
168
|
-v() { --variables "$@"; }
|
|
149
169
|
--vars(){ --variables "$@"; }
|
|
150
170
|
;;
|
|
151
171
|
--format=*) set_with_warn format "${1##--format=}";;
|
|
152
|
-
--format-file=*) set_with_warn format "$(cat ${1##--format-file=})";;
|
|
153
|
-
--format-from=*) set_with_warn format "$(cat ${1##--format-from=})";;
|
|
172
|
+
--format-file=*) set_with_warn format "$(cat "${1##--format-file=}")";;
|
|
173
|
+
--format-from=*) set_with_warn format "$(cat "${1##--format-from=}")";;
|
|
154
174
|
--format-from) fatalerr "option --format-from requires value";;
|
|
155
175
|
-x|--trace|--xtrace)
|
|
156
176
|
# PS4=$'\e[32m+ '
|
|
@@ -177,7 +197,7 @@ while [[ $# > 0 ]] ;do
|
|
|
177
197
|
script_file="${1##--generate-script=}"
|
|
178
198
|
script_file="${script_file:=/dev/stdout}"
|
|
179
199
|
;;
|
|
180
|
-
|
|
200
|
+
-*) fatalerr "!!! Unknown option $1";;
|
|
181
201
|
*)
|
|
182
202
|
set_with_warn format "$1"
|
|
183
203
|
;;
|
|
@@ -185,43 +205,59 @@ while [[ $# > 0 ]] ;do
|
|
|
185
205
|
shift
|
|
186
206
|
done
|
|
187
207
|
|
|
188
|
-
if test ${DEBUG:-empty} != 'empty' ;then
|
|
208
|
+
if test "${DEBUG:-empty}" != 'empty' ;then
|
|
189
209
|
function echodbg { >/dev/stderr echo $'\e[0;36m'"$@"$'\e[0m'; }
|
|
190
|
-
function DEBUG { "$@" | while read;do echodbg "$REPLY";done ;}
|
|
210
|
+
function DEBUG { "$@" | while read -r ;do echodbg "$REPLY";done ;}
|
|
191
211
|
else
|
|
192
212
|
function echodbg { :;}
|
|
193
213
|
function DEBUG { :;}
|
|
194
214
|
fi
|
|
195
215
|
|
|
216
|
+
curl_release(){
|
|
217
|
+
curl 'https://gitlab.com/kyb/git-rev-label/raw/artifacts/master/git-rev-label' -LsSf "$@"
|
|
218
|
+
}
|
|
196
219
|
########### MAINTENANCE ACTIONS ###########
|
|
197
220
|
if var_is_set_not_empty action ;then
|
|
221
|
+
# shellcheck disable=SC2154 ## action is referenced but not assigned.
|
|
198
222
|
case "$action" in
|
|
199
223
|
--update|--update-script)
|
|
200
|
-
TEMP
|
|
201
|
-
|
|
202
|
-
chmod +x $TEMP
|
|
203
|
-
if diff -q "${BASH_SOURCE[0]}" $TEMP &>/dev/null ;then
|
|
224
|
+
TEMP=$(mktemp)
|
|
225
|
+
curl_release -o "$TEMP"
|
|
226
|
+
chmod +x "$TEMP"
|
|
227
|
+
if diff -q "${BASH_SOURCE[0]}" "$TEMP" &>/dev/null ;then
|
|
204
228
|
echomsg "Already up to date."
|
|
205
|
-
rm -f $TEMP
|
|
229
|
+
rm -f "$TEMP"
|
|
206
230
|
exit
|
|
207
231
|
else
|
|
208
|
-
exec mv $TEMP $(readlink -f "${BASH_SOURCE[0]}")
|
|
232
|
+
exec mv "$TEMP" "$(readlink -f "${BASH_SOURCE[0]}")"
|
|
209
233
|
fi
|
|
210
234
|
;;
|
|
211
235
|
--install-link)
|
|
212
236
|
install_dir=${install_dir:='/usr/local/bin'}
|
|
213
|
-
exec ln -s ${force:+-f} $(readlink -f "${BASH_SOURCE[0]}") "$install_dir/git-rev-label"
|
|
237
|
+
exec ln -s ${force:+-f} "$(readlink -f "${BASH_SOURCE[0]}")" "$install_dir/git-rev-label"
|
|
214
238
|
;;
|
|
215
239
|
--install|--install-script)
|
|
216
240
|
install_dir=${install_dir:='/usr/local/bin'}
|
|
217
|
-
install_dir=$(eval echo $install_dir)
|
|
218
|
-
|
|
241
|
+
#install_dir=$(eval echo $install_dir) ## eval is to expand ~, security leak
|
|
242
|
+
touch "$install_dir/git-rev-label" 2>&- ||
|
|
243
|
+
fatalerr "Cannot touch '$install_dir/git-rev-label'. "\
|
|
244
|
+
"Check if directory exists and you have enough access rights!"
|
|
245
|
+
if test -n "${BASH_SOURCE[0]:-}" ;then
|
|
246
|
+
cp "${BASH_SOURCE[0]}" "$install_dir/git-rev-label"
|
|
247
|
+
else
|
|
248
|
+
curl_release > "$install_dir/git-rev-label"
|
|
249
|
+
fi
|
|
219
250
|
chmod +x "$install_dir/git-rev-label"
|
|
220
251
|
exit
|
|
221
252
|
;;
|
|
222
253
|
esac
|
|
223
254
|
fi
|
|
224
255
|
|
|
256
|
+
## Sanity check
|
|
257
|
+
var_is_set install_dir &&
|
|
258
|
+
atalerr "--install_dir should only be used with --install action."
|
|
259
|
+
|
|
260
|
+
|
|
225
261
|
#####################################################
|
|
226
262
|
########## SET git rev-label VARIABLES ##############
|
|
227
263
|
######### Quintessence (quīnta essentia) ############
|
|
@@ -231,7 +267,7 @@ if test -z "$format" ;then
|
|
|
231
267
|
exit 0
|
|
232
268
|
fi
|
|
233
269
|
|
|
234
|
-
resolve_dependancies(){
|
|
270
|
+
resolve_dependancies(){
|
|
235
271
|
sed -E '
|
|
236
272
|
s,\bSHORT\b,short SHORT,g
|
|
237
273
|
s,\bshort\b,commit short,g
|
|
@@ -243,6 +279,8 @@ resolve_dependancies(){
|
|
|
243
279
|
'
|
|
244
280
|
}
|
|
245
281
|
space_newline(){ sed -E 's, +,\n,g' ;}
|
|
282
|
+
|
|
283
|
+
# shellcheck disable=SC2034 ## shellcheck cannot track variables usage because they are referenced individually
|
|
246
284
|
variables(){
|
|
247
285
|
commit=$(git rev-parse --short HEAD)
|
|
248
286
|
short=$commit
|
|
@@ -257,11 +295,14 @@ variables(){
|
|
|
257
295
|
_DIRTY=${_dirty^^}
|
|
258
296
|
branch="$(git rev-parse --abbrev-ref HEAD | sed s,^HEAD$,DETACHED,)"
|
|
259
297
|
tag="$(git tag --list --points-at HEAD | head -1)"
|
|
260
|
-
refname=$
|
|
298
|
+
refname=${branch/^DETACHED$/${tag:-DETACHED}}
|
|
299
|
+
}
|
|
300
|
+
# shellcheck disable=SC2034 ## shellcheck cannot track variables usage because they are referenced individually
|
|
301
|
+
variables_always_calculated(){
|
|
302
|
+
branch="$(git rev-parse --abbrev-ref HEAD | sed s,^HEAD$,DETACHED,)"
|
|
303
|
+
tag="$(git tag --list --points-at HEAD | head -1)"
|
|
304
|
+
refname=${branch/^DETACHED$/${tag:-DETACHED}}
|
|
261
305
|
}
|
|
262
|
-
branch="$(git rev-parse --abbrev-ref HEAD | sed s,^HEAD$,DETACHED,)"
|
|
263
|
-
tag="$(git tag --list --points-at HEAD | head -1)"
|
|
264
|
-
refname=$(if test "$branch" == DETACHED; then echo "${tag:-DETACHED}"; else echo "$branch";fi;)
|
|
265
306
|
get_function_body(){
|
|
266
307
|
for f ;do
|
|
267
308
|
declare -f "$f" | sed '1,2d;$d ; s,^ ,,'
|
|
@@ -270,14 +311,14 @@ get_function_body(){
|
|
|
270
311
|
requested_variables_to_be_evaluated(){
|
|
271
312
|
## Calculate only requested variables: parse $format, detect required vars, then calculate required variables.
|
|
272
313
|
requested_variables=$(echo "$format"| perl -ne '$var="[A-Za-z_][A-Za-z0-9_]+"; print "$1$2 " while m,\$(?:($var)|\{($var)\}),g')
|
|
273
|
-
echodbg requested_variables
|
|
314
|
+
echodbg requested_variables="$requested_variables"
|
|
274
315
|
if test -z "$requested_variables"
|
|
275
316
|
then return ;fi
|
|
276
|
-
needed_variables=$(grep -Fx -f <(echo $requested_variables|resolve_dependancies|space_newline) <(echo $FULL_LIST|space_newline))
|
|
277
|
-
echodbg needed_variables
|
|
317
|
+
needed_variables=$(grep -Fx -f <(echo "$requested_variables"|resolve_dependancies|space_newline) <(echo $FULL_LIST|space_newline))
|
|
318
|
+
echodbg needed_variables="$needed_variables"
|
|
278
319
|
func_variables_body="$(get_function_body variables)"
|
|
279
320
|
for varname in $needed_variables ;do
|
|
280
|
-
echo "$func_variables_body" |
|
|
321
|
+
echo "$func_variables_body" | grep "^\s*$varname="
|
|
281
322
|
done
|
|
282
323
|
echo "export $requested_variables"
|
|
283
324
|
}
|
|
@@ -293,6 +334,8 @@ expand_env_vars(){
|
|
|
293
334
|
perl -pe'$var="[A-Za-z_][A-Za-z0-9_]+"; s,\$(?:($var)|\{($var)\}),$ENV{$1//$2}//$&,eg' ## see https://stackoverflow.com/questions/57635730/match-substitute-and-expand-shell-variable-using-perl
|
|
294
335
|
}
|
|
295
336
|
|
|
337
|
+
variables_always_calculated
|
|
338
|
+
|
|
296
339
|
########################################################
|
|
297
340
|
########## Handle non-maintenance actions ##############
|
|
298
341
|
default_action(){
|
package/package.json
CHANGED