Skip to content

Commit c47b32f

Browse files
committed
pre-push: automagically update the version
Apart from keeping the `.js` and `npm prepare` parts and adjusting the expected package name in `package*.json` to `rss-to-issues`, this is pretty much a verbatim copy-pasta of the `pre-push.hook` from https://github.com/git-for-windows/get-azure-pipelines-artifact/. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent f9a23e8 commit c47b32f

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

pre-push.hook

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,37 @@ LF='
1313
'
1414

1515
git diff --no-index --quiet pre-push.hook "$(git rev-parse --git-path hooks/pre-push)" ||
16-
die 'The `pre-push` hook is not up to date with `pre-push.hook`'
16+
die 'The `pre-push` hook is not up to date with `pre-push.hook`. Please update:
17+
18+
cp pre-push.hook .git/hooks/pre-push'
1719

1820
# Verify that any tagged version is reflected in its `package.json`
1921
for tag in $(git for-each-ref --format='%(refname:short)' --points-at=HEAD 'refs/tags/v[0-9]*')
2022
do
2123
out="$(git tag --verify $tag 2>&1)" ||
2224
die "$out$LF${LF}Tag $tag is not signed/signature cannot be verified"
2325

24-
git grep -q '"version": "'"${tag#v}"'"' refs/tags/$tag -- package.json || {
25-
sed 's/\("version": "\)[^"]*/\1'"${tag#v}"/ <package.json >package.json.new &&
26+
test 0 = $(git rev-list --count ...main) || die 'HEAD is not up to date with `main`'
27+
test 0 = $(git rev-list --count ...origin/main) ||
28+
echo 'warning: HEAD is not up to date with `origin/main`' >&2
29+
30+
regex="^ \"version\": \"$(echo "${tag#v}" | sed 's/\./\\./g')\",\$"
31+
substitute="/\"name\": \"rss-to-issues\"/{N;s/\\(\"version\": \"\\).*\",\$/\\1${tag#v}\",/}"
32+
git grep -q "$regex" refs/tags/$tag -- package.json || {
33+
sed "$substitute" <package.json >package.json.new &&
2634
mv -f package.json.new package.json
35+
sed "$substitute" <package-lock.json >package-lock.json.new &&
36+
mv -f package-lock.json.new package-lock.json
2737
die "package.json did not reflect $tag; It was adjusted."
2838
exit 1
2939
}
40+
41+
git grep -q "$regex" refs/tags/$tag -- package-lock.json || {
42+
sed "$substitute" <package-lock.json >package-lock.json.new &&
43+
mv -f package-lock.json.new package-lock.json
44+
die "package-lock.json did not reflect $tag; It was adjusted."
45+
exit 1
46+
}
3047
done
3148

3249
git diff --quiet dist/ ||
@@ -42,4 +59,4 @@ then
4259
echo "Committing dist/ because it was not up to date" >&2
4360
git commit -sm "npm run prepare" dist/
4461
fi
45-
fi
62+
fi

0 commit comments

Comments
 (0)