pre-commit-golang icon indicating copy to clipboard operation
pre-commit-golang copied to clipboard

go-mod-tidy-repo should have an argument for excludes

Open balihb opened this issue 8 months ago • 1 comments

we have a repository with multiple modules depending on each other. the problem is that in the CI we are storing some tool's go dependencies inside the repo dir with asdf ( https://github.com/asdf-community/asdf-golang?tab=readme-ov-file#when-using-go-get-or-go-install ) under the .cache directory, so the CI can save it and go-mod-tidy-repo will try to run on them too. I've tried with hard-coding an exclusion for .cache and it worked.

diff --git a/lib/cmd-repo-mod.bash b/lib/cmd-repo-mod.bash
index c44b9d50a51e5ab7a0362d6544bf9b45f30df9d1..163a9449394a73ade50cd0b7c4d84df9e4e44753 100644
--- a/lib/cmd-repo-mod.bash
+++ b/lib/cmd-repo-mod.bash
@@ -12,7 +12,7 @@ export GO111MODULE=on
 error_code=0
 # Assume parent folder of go.mod is module root folder
 #
-for sub in $(find . -name go.mod -not -path '*/vendor/*' -exec dirname "{}" ';' | sort -u); do
+for sub in $(find . -name go.mod -not -path '*/vendor/*' -not -path '*/.cache/*' -exec dirname "{}" ';' | sort -u); do
 	pushd "${sub}" > /dev/null || exit 1
 	if [ "${error_on_output:-}" -eq 1 ]; then
 		output=$(/usr/bin/env "${ENV_VARS[@]}" "${cmd[@]}" "${OPTIONS[@]}" 2>&1)

obviously it won't scale for other similar use cases.

balihb avatar Apr 14 '25 18:04 balihb

#23

balihb avatar Apr 14 '25 18:04 balihb

Closing this as resolved by #38 - Thanks for taking the time and for using my project!

TekWizely avatar Jul 31 '25 22:07 TekWizely