Skip to content

Commit f4c4f77

Browse files
tuedajodavies
authored andcommitted
fix(build): update git-version-gen script to use LC_ALL
Replace LANG with LC_ALL as the locale setting to ensure consistent date formatting, because LANG can be overridden by LC_TIME or LC_ALL. Also add --date-locale and --date-timezone command line options.
1 parent 053ce7a commit f4c4f77

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

scripts/git-version-gen.sh

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,17 @@ Options:
2525
-s, --shell shell script output
2626
-v, --only-version only-version output
2727
-o <file>, --output <file> output to <file>
28-
--date-format <format> date format (default: '%b %e %Y')
28+
--date-format <format> date format (default: '%b %e %Y' as __DATE__)
29+
--date-locale <locale> date locale (default: C)
30+
--date-timezone <timezone> date timezone (default: GMT0)
2931
END
3032
}
3133

3234
# Format the date given in the form of '%Y-%m-%d %H:%M:%S %z'.
3335
# fmt_isodate <isodate> <format>
3436
fmt_isodate() {
3537
# dash (0.5.5.1) needs the following exports.
36-
export LANG
38+
export LC_ALL
3739
export TZ
3840
# BSD date
3941
date -j -f '%Y-%m-%d %H:%M:%S %z' "$1" +"$2" 2>/dev/null ||
@@ -56,6 +58,8 @@ refdir=$rootdir
5658
mode=raw
5759
output_file=
5860
date_format='%b %e %Y'
61+
date_locale=C
62+
date_timezone=GMT0 # for better compatibility than UTC0
5963

6064
next=
6165
for a in "$@"; do
@@ -93,6 +97,12 @@ for a in "$@"; do
9397
--date-format)
9498
next=date_format
9599
;;
100+
--date-locale)
101+
next=date_locale
102+
;;
103+
--date-timezone)
104+
next=date_timezone
105+
;;
96106
*)
97107
echo "$prog: error: unknown option $a" >&2
98108
exit 1
@@ -140,12 +150,12 @@ if [ "$mode" != "only-version" ]; then
140150
if git_C diff-index --quiet HEAD .; then
141151
# If the working tree is not dirty, use the latest commit date.
142152
isodate=$(git_C log -1 --pretty=%ci .)
143-
date=$(LANG=C TZ=UTC fmt_isodate "$isodate" "$date_format")
153+
date=$(LC_ALL="$date_locale" TZ="$date_timezone" fmt_isodate "$isodate" "$date_format")
144154
else
145155
# If the working tree is dirty, suffix "-dirty" to the revision identifier
146156
# and use the current date time.
147157
revision="$revision-dirty"
148-
date=$(LANG=C TZ=UTC date +"$date_format")
158+
date=$(LC_ALL="$date_locale" TZ="$date_timezone" date +"$date_format")
149159
fi
150160
# Version description.
151161
# Examples: "4.3.0", "v4.3.0-1-g7c9706c"

0 commit comments

Comments
 (0)