Skip to content

Commit 9d28024

Browse files
committed
pre-commit-no-snapshots.sh: improve SNAPSHOT check
The check now examines only the staged diff rather than the entire working copy. So if you add a SNAPSHOT reference locally for development purposes, but are not actually committing it, the commit will not fail. Thanks to Barry DeZonia for the suggestion.
1 parent 438fcda commit 9d28024

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

hooks/pre-commit-no-snapshots.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#!/bin/sh
22

3-
# Fail if any pom.xml files have more than one SNAPSHOT reference.
4-
# One reference to the parent is expected, but that's it!
5-
# Otherwise, builds will not be repeatable.
6-
if git grep -c SNAPSHOT $(git ls-files | grep pom.xml) | grep -v ':1$';
3+
# Fail if any new SNAPSHOT references are introduced into pom.xml files.
4+
# In general, SNAPSHOT references result in unstable/nonrepeatable builds.
5+
if git diff --staged -U0 $(git ls-files | grep pom.xml) | grep '^\+.*SNAPSHOT';
76
then
87
echo 'Potential SNAPSHOT references!'
98
exit 1

0 commit comments

Comments
 (0)