Skip to content

Commit c1665a0

Browse files
logikoneChris Larsen
authored andcommitted
feat: add go-mod-vendor hook
* Add a hook that runs `go mod vendor` to ensure that vendored dependencies are up-to-date
1 parent 1a6fdf9 commit c1665a0

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

.pre-commit-hooks.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,9 @@
8181
files: '\.go$'
8282
language: 'script'
8383
description: "Runs `go mod tidy -v`, requires golang"
84+
- id: go-mod-vendor
85+
name: 'go-mod-vendor'
86+
entry: run-go-mod-vendor.sh
87+
files: '\.go$'
88+
language: 'script'
89+
description: "Runs `go mod vendor`, requires golang"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@ Add this to your `.pre-commit-config.yaml`
4444
- `go-unit-tests` - run `go test -tags=unit -timeout 30s -short -v`
4545
- `go-build` - run `go build`, requires golang
4646
- `go-mod-tidy` - run `go mod tidy -v`, requires golang
47+
- `go-mod-vendor` - run `go mod vendor`, requires golang

run-go-mod-vendor.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
go mod vendor
4+
git diff --exit-code vendor &> /dev/null
5+
6+
if [ $? -eq 1 ]; then
7+
echo "vendor dir differs, please re-add it to your commit"
8+
9+
exit 1
10+
fi

0 commit comments

Comments
 (0)