Skip to content

Commit c80e381

Browse files
authored
fix(go-mod-tidy): go mod tidy recursive (#29)
Run `go mod tidy` in directories where `go.mod` exist Signed-off-by: Bryan Hundven <[email protected]>
1 parent cb2e520 commit c80e381

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

pre-commit-hooks/go-mod-tidy.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@
44

55
set -euo pipefail
66

7-
if ! go mod tidy -v "$@"
8-
then
9-
exit 2
10-
fi
7+
set -x
8+
9+
while IFS= read -r gomod
10+
do
11+
pushd "$(dirname "${gomod}")" >/dev/null 2>&1
12+
if ! go mod tidy -v
13+
then
14+
exit 2
15+
fi
16+
popd >/dev/null 2>&1
17+
done < <(find . -type f -name 'go.mod' -print)
1118

1219
if ! git diff --exit-code go.* &> /dev/null
1320
then

0 commit comments

Comments
 (0)