55SCRIPTDIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
66source " ${SCRIPTDIR} /.validate"
77
8- tidy_files=(' go.mod' ' go.sum' )
8+ modules_files=(' api/go.mod' ' client/go.mod' ' man/go.mod' ' go.mod' )
9+ tidy_files=(" ${modules_files[@]} " ' api/go.sum' ' client/go.sum' ' man/go.sum' ' go.sum' )
910vendor_files=(" ${tidy_files[@]} " ' vendor/' )
1011
11- validate_vendor_files_exist () {
12- local file
13- for file in " ${vendor_files[@]} " ; do
14- if [ ! -e " $file " ]; then
15- echo >&2 " ERROR: required file '$file ' does not exist"
12+ validate_tidy_modules () {
13+ # check that all go.mod files exist in HEAD; go.sum files are generated by 'go mod tidy'
14+ # so we don't need to check for their existence beforehand
15+ for f in " ${modules_files[@]} " ; do
16+ if [ ! -f " $f " ]; then
17+ echo >&2 " ERROR: missing $f "
1618 return 1
1719 fi
1820 done
19- return 0
20- }
21-
22- validate_vendor_tidy () {
2321 # run mod tidy
2422 ./hack/vendor.sh tidy
2523 # check if any files have changed
26- git diff --quiet HEAD -- " ${tidy_files[@]} "
24+ git diff --quiet HEAD -- " ${tidy_files[@]} " && [ -z " $( git ls-files --others --exclude-standard ) " ]
2725}
2826
2927validate_vendor_diff () {
30- mapfile -t changed_files < <( validate_diff --diff-filter=ACMR --name-only -- " ${vendor_files[@]} " )
31-
32- if [ -n " ${TEST_FORCE_VALIDATE:- } " ] || [ " ${# changed_files[@]} " -gt 0 ]; then
33- # recreate vendor/
34- ./hack/vendor.sh vendor
35- # check if any files have changed
36- git diff --quiet HEAD -- " ${vendor_files[@]} "
37- else
38- echo >&2 ' INFO: no vendor changes in diff; skipping vendor check.'
39- fi
28+ # recreate vendor/
29+ ./hack/vendor.sh vendor
30+ # check if any files have changed
31+ git diff --quiet HEAD -- " ${vendor_files[@]} " && [ -z " $( git ls-files --others --exclude-standard) " ]
4032}
4133
4234validate_vendor_license () {
@@ -48,26 +40,22 @@ validate_vendor_license() {
4840 done < <( awk ' /^# /{ print $2 }' vendor/modules.txt)
4941}
5042
51- # First check the required files exist as git diff will not report missing files.
52- if ! validate_vendor_files_exist; then
53- {
54- echo ' FAIL: Vendoring was not performed correctly!'
55- echo
56- echo ' Please revendor with hack/vendor.sh'
57- } >&2
58- exit 1
59- fi
60-
61- if validate_vendor_tidy && validate_vendor_diff && validate_vendor_license; then
43+ if validate_tidy_modules && validate_vendor_diff && validate_vendor_license; then
6244 echo >&2 ' PASS: Vendoring has been performed correctly!'
6345else
6446 {
6547 echo ' FAIL: Vendoring was not performed correctly!'
6648 echo
67- echo ' The following files changed during re-vendor:'
68- echo
69- git diff --name-status HEAD -- " ${vendor_files[@]} "
70- echo
49+ if [ -n " $( git ls-files --others --exclude-standard) " ]; then
50+ echo ' The following files are missing:'
51+ git ls-files --others --exclude-standard
52+ echo
53+ fi
54+ if [ -n " $( git diff --name-status HEAD -- " ${vendor_files[@]} " ) " ]; then
55+ echo ' The following files changed during re-vendor:'
56+ git diff --name-status HEAD -- " ${vendor_files[@]} "
57+ echo
58+ fi
7159 echo ' Please revendor with hack/vendor.sh'
7260 echo
7361 git diff --diff-filter=M -- " ${vendor_files[@]} "
0 commit comments