git-rev-label 2.16.14 → 2.19.16

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.
Files changed (2) hide show
  1. package/git-rev-label +54 -39
  2. package/package.json +1 -1
package/git-rev-label CHANGED
@@ -11,21 +11,27 @@
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
17
22
  shopt -s expand_aliases
18
23
 
19
- VERSION=master-c16-g154e93e-b14
20
- VERSION_NPM=2.16.14
24
+ VERSION=master-c19-g708fa40-b16
25
+ VERSION_NPM=2.19.16
21
26
 
27
+ ## todo maybe use utils.bash from autorsync
22
28
  function echomsg { echo $'\e[1;37m'"$@"$'\e[0m'; }
23
29
  function echodbg { >&2 echo $'\e[0;36m'"$@"$'\e[0m'; }
24
30
  function echowarn { >&2 echo $'\e[0;33m'WARNING$'\e[0m' "$@"; }
25
31
  function echoerr { >&2 echo $'\e[0;31m'ERROR$'\e[0m' "$@"; }
26
32
  function fatalerr { >&2 echoerr "$@"; exit 1; }
27
33
 
28
- if test `uname` == Darwin ;then
34
+ if test "$(uname)" == 'Darwin' ;then
29
35
  alias sed=gsed
30
36
  alias grep=ggrep
31
37
  alias find=gfind
@@ -37,7 +43,7 @@ if test `uname` == Darwin ;then
37
43
  alias readlink=greadlink
38
44
  fi
39
45
 
40
- function OnErr { caller | { read lno file; echoerr ">ERR in $file:$lno, $(sed -n ${lno}p $file)" >&2; }; }
46
+ function OnErr { caller | { read -r lno file; echoerr ">ERR in $file:$lno, $(sed -n "$lno"p "$file")" >&2; }; }
41
47
  trap OnErr ERR
42
48
 
43
49
  is_sourced(){
@@ -68,9 +74,9 @@ var_is_unset_or_empty(){
68
74
  function --help {
69
75
  echo -n \
70
76
  'Gives information about Git repository revision in format like '"'master-c73-gbbb6bec'"'.
71
- Can fill template string or file with environment variables and information from Git.
72
- Useful to provide information about version of the program: branch, tag, commit hash,
73
- 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
74
80
  commits, not taking into account merged branches - only first parent.
75
81
 
76
82
  USAGE:
@@ -85,8 +91,8 @@ USAGE:
85
91
  eval $(git rev-label --variables | sed s,^,export\ ,) ## Export variables to environment
86
92
 
87
93
  COMPLEX USE CASE:
88
- * Fill `build_info.template.h` with branch, tag, commit hash, commits count, dirty status.
89
- 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.
90
96
  See https://gitlab.com/kyb/git-rev-label/blob/master/build_info.template.h and
91
97
  https://gitlab.com/kyb/git-rev-label/blob/master/create-build-info.sh
92
98
 
@@ -100,7 +106,7 @@ More info at https://gitlab.com/kyb/git-rev-label
100
106
  '
101
107
  }
102
108
  function --version {
103
- echo "git-rev-label v$VERSION_NPM
109
+ echo "git-rev-label v$VERSION_NPM
104
110
  $VERSION
105
111
  https://gitlab.com/kyb/git-rev-label"
106
112
  }
@@ -112,6 +118,7 @@ function --rev-label {
112
118
  --version-npm(){ echo $VERSION_NPM; }
113
119
  --npm-version(){ --version-npm "$@"; }
114
120
 
121
+ # shellcheck disable=SC2086 ## varname cannot contain spaces
115
122
  set_with_warn(){
116
123
  varname=$1
117
124
  shift
@@ -119,7 +126,7 @@ set_with_warn(){
119
126
  declare -g $varname="$@"
120
127
  }
121
128
  set_action(){
122
- set_with_warn action $1
129
+ set_with_warn action "$1"
123
130
  }
124
131
 
125
132
  readonly FULL_LIST="commit short SHORT long LONG count COUNT dirty _dirty DIRTY _DIRTY tag branch refname"
@@ -127,9 +134,9 @@ readonly FULL_LIST="commit short SHORT long LONG count COUNT dirty _dirty DI
127
134
  ## Unset variables from environment
128
135
  unset format install_dir
129
136
 
130
- while [[ $# > 0 ]] ;do
131
- case $1 in
132
- --help|-help|help|-h|\?|-\?)
137
+ while (( $# > 0 )) ;do
138
+ case $1 in
139
+ --help|-help|help|-h|\?|-\?)
133
140
  --help
134
141
  exit
135
142
  ;;
@@ -138,7 +145,7 @@ while [[ $# > 0 ]] ;do
138
145
  exit
139
146
  ;;
140
147
  --install-link|--install|--install-script|--update|--update-script)
141
- set_action $1
148
+ set_action "$1"
142
149
  ;;
143
150
  --install-dir=*)
144
151
  set_with_warn install_dir "${1##--install-dir=}"
@@ -155,15 +162,15 @@ while [[ $# > 0 ]] ;do
155
162
  force=f
156
163
  ;;
157
164
  --variables|--vars|-v)
158
- set_action $1
165
+ set_action "$1"
159
166
  format=$(echo "$FULL_LIST" | sed -E 's, *([A-Za-z_]+),\1=\$\1\n,g')
160
167
  --variables(){ default_action; }
161
168
  -v() { --variables "$@"; }
162
169
  --vars(){ --variables "$@"; }
163
170
  ;;
164
171
  --format=*) set_with_warn format "${1##--format=}";;
165
- --format-file=*) set_with_warn format "$(cat ${1##--format-file=})";;
166
- --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=}")";;
167
174
  --format-from) fatalerr "option --format-from requires value";;
168
175
  -x|--trace|--xtrace)
169
176
  # PS4=$'\e[32m+ '
@@ -190,7 +197,7 @@ while [[ $# > 0 ]] ;do
190
197
  script_file="${1##--generate-script=}"
191
198
  script_file="${script_file:=/dev/stdout}"
192
199
  ;;
193
- -*|--*) fatalerr "!!! Unknown option $1";;
200
+ -*) fatalerr "!!! Unknown option $1";;
194
201
  *)
195
202
  set_with_warn format "$1"
196
203
  ;;
@@ -198,9 +205,9 @@ while [[ $# > 0 ]] ;do
198
205
  shift
199
206
  done
200
207
 
201
- if test ${DEBUG:-empty} != 'empty' ;then
208
+ if test "${DEBUG:-empty}" != 'empty' ;then
202
209
  function echodbg { >/dev/stderr echo $'\e[0;36m'"$@"$'\e[0m'; }
203
- function DEBUG { "$@" | while read;do echodbg "$REPLY";done ;}
210
+ function DEBUG { "$@" | while read -r ;do echodbg "$REPLY";done ;}
204
211
  else
205
212
  function echodbg { :;}
206
213
  function DEBUG { :;}
@@ -211,27 +218,28 @@ curl_release(){
211
218
  }
212
219
  ########### MAINTENANCE ACTIONS ###########
213
220
  if var_is_set_not_empty action ;then
221
+ # shellcheck disable=SC2154 ## action is referenced but not assigned.
214
222
  case "$action" in
215
223
  --update|--update-script)
216
- TEMP=`mktemp`
217
- curl_release -o $TEMP
218
- chmod +x $TEMP
219
- 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
220
228
  echomsg "Already up to date."
221
- rm -f $TEMP
229
+ rm -f "$TEMP"
222
230
  exit
223
231
  else
224
- exec mv $TEMP $(readlink -f "${BASH_SOURCE[0]}")
232
+ exec mv "$TEMP" "$(readlink -f "${BASH_SOURCE[0]}")"
225
233
  fi
226
234
  ;;
227
235
  --install-link)
228
236
  install_dir=${install_dir:='/usr/local/bin'}
229
- 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"
230
238
  ;;
231
239
  --install|--install-script)
232
240
  install_dir=${install_dir:='/usr/local/bin'}
233
241
  #install_dir=$(eval echo $install_dir) ## eval is to expand ~, security leak
234
- touch "$install_dir/git-rev-label" 2>&- ||
242
+ touch "$install_dir/git-rev-label" 2>&- ||
235
243
  fatalerr "Cannot touch '$install_dir/git-rev-label'. "\
236
244
  "Check if directory exists and you have enough access rights!"
237
245
  if test -n "${BASH_SOURCE[0]:-}" ;then
@@ -246,7 +254,7 @@ if var_is_set_not_empty action ;then
246
254
  fi
247
255
 
248
256
  ## Sanity check
249
- var_is_set install_dir &&
257
+ var_is_set install_dir &&
250
258
  atalerr "--install_dir should only be used with --install action."
251
259
 
252
260
 
@@ -259,7 +267,7 @@ if test -z "$format" ;then
259
267
  exit 0
260
268
  fi
261
269
 
262
- resolve_dependancies(){
270
+ resolve_dependancies(){
263
271
  sed -E '
264
272
  s,\bSHORT\b,short SHORT,g
265
273
  s,\bshort\b,commit short,g
@@ -271,6 +279,8 @@ resolve_dependancies(){
271
279
  '
272
280
  }
273
281
  space_newline(){ sed -E 's, +,\n,g' ;}
282
+
283
+ # shellcheck disable=SC2034 ## shellcheck cannot track variables usage because they are referenced individually
274
284
  variables(){
275
285
  commit=$(git rev-parse --short HEAD)
276
286
  short=$commit
@@ -285,11 +295,14 @@ variables(){
285
295
  _DIRTY=${_dirty^^}
286
296
  branch="$(git rev-parse --abbrev-ref HEAD | sed s,^HEAD$,DETACHED,)"
287
297
  tag="$(git tag --list --points-at HEAD | head -1)"
288
- refname=$(if test "$branch" == DETACHED; then echo "${tag:-DETACHED}"; else echo "$branch";fi;)
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}}
289
305
  }
290
- branch="$(git rev-parse --abbrev-ref HEAD | sed s,^HEAD$,DETACHED,)"
291
- tag="$(git tag --list --points-at HEAD | head -1)"
292
- refname=$(if test "$branch" == DETACHED; then echo "${tag:-DETACHED}"; else echo "$branch";fi;)
293
306
  get_function_body(){
294
307
  for f ;do
295
308
  declare -f "$f" | sed '1,2d;$d ; s,^ ,,'
@@ -298,14 +311,14 @@ get_function_body(){
298
311
  requested_variables_to_be_evaluated(){
299
312
  ## Calculate only requested variables: parse $format, detect required vars, then calculate required variables.
300
313
  requested_variables=$(echo "$format"| perl -ne '$var="[A-Za-z_][A-Za-z0-9_]+"; print "$1$2 " while m,\$(?:($var)|\{($var)\}),g')
301
- echodbg requested_variables=$requested_variables
314
+ echodbg requested_variables="$requested_variables"
302
315
  if test -z "$requested_variables"
303
316
  then return ;fi
304
- needed_variables=$(grep -Fx -f <(echo $requested_variables|resolve_dependancies|space_newline) <(echo $FULL_LIST|space_newline))
305
- echodbg needed_variables=$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"
306
319
  func_variables_body="$(get_function_body variables)"
307
320
  for varname in $needed_variables ;do
308
- echo "$func_variables_body" |egrep "^\s*$varname="
321
+ echo "$func_variables_body" | grep "^\s*$varname="
309
322
  done
310
323
  echo "export $requested_variables"
311
324
  }
@@ -321,6 +334,8 @@ expand_env_vars(){
321
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
322
335
  }
323
336
 
337
+ variables_always_calculated
338
+
324
339
  ########################################################
325
340
  ########## Handle non-maintenance actions ##############
326
341
  default_action(){
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "git-rev-label",
3
3
  "description": "Obtain information about Git repository revision in format like 'master-c73-gbbb6bec'",
4
- "version":"2.16.14",
4
+ "version":"2.19.16",
5
5
  "homepage": "https://gitlab.com/kyb/git-rev-label",
6
6
  "keywords": [
7
7
  "git",