Skip to content

Commit d9691ac

Browse files
committed
pre-push: match the "version" tag in package.json more precisely
There is no other `"version"` tag in there, of course, but in the next commit, we will extend the logic to `package-lock.json` (and there are tons more `"version"` tags in there, let me tell you). Signed-off-by: Johannes Schindelin <[email protected]>
1 parent be9fd81 commit d9691ac

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

pre-push.hook

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ do
2323
out="$(git tag --verify $tag 2>&1)" ||
2424
die "$out$LF${LF}Tag $tag is not signed/signature cannot be verified"
2525

26-
git grep -q '"version": "'"${tag#v}"'"' refs/tags/$tag -- package.json || {
27-
sed 's/\("version": "\)[^"]*/\1'"${tag#v}"/ <package.json >package.json.new &&
26+
regex="^ \"version\": \"$(echo "${tag#v}" | sed 's/\./\\./g')\",\$"
27+
substitute="s/^\\( \"version\": \"\\).*\",\$/\\1${tag#v}\",/"
28+
git grep -q "$regex" refs/tags/$tag -- package.json || {
29+
sed "$substitute" <package.json >package.json.new &&
2830
mv -f package.json.new package.json
2931
die "package.json did not reflect $tag; It was adjusted."
3032
exit 1

0 commit comments

Comments
 (0)