pin-dependency.sh: enhance forking of a dependency

This addresses a problem that occurred when trying the following replacement:
   hack/pin-dependency.sh k8s.io/klog/v2=github.com/pohly/klog/v2 flush-log-sink

That itself worked, but update-vendor.sh then failed:

   === tidying go.mod/go.sum in staging/src/k8s.io/code-generator/examples
  go: k8s.io/apimachinery@v0.0.0 requires
  	k8s.io/klog/v2@v2.4.1-0.20210909144920-0b91caa8c854: invalid version: unknown revision 0b91caa8c854
  go: k8s.io/apimachinery@v0.0.0 requires
  	k8s.io/klog/v2@v2.4.1-0.20210909144920-0b91caa8c854: invalid version: unknown revision 0b91caa8c854
This commit is contained in:
Patrick Ohly 2021-09-09 17:20:55 +02:00
parent 047a6b9f86
commit de47d00865

View File

@ -104,6 +104,18 @@ for repo in $(kube::util::list_staging_repos); do
go mod edit -require "${dep}@${rev}"
go mod edit -replace "${dep}=${replacement}@${rev}"
fi
# When replacing with a fork, always add a replace statement in all go.mod
# files (not just the root of the staging repos!) because there might be
# indirect dependencies on the fork.
#
# This is excessive, but the resulting commit should never be merged, so it
# isn't that important to get this exactly right.
if [ "${replacement}" != "${dep}" ]; then
find . -name go.mod -print | while read -r modfile; do
(cd "$(dirname "${modfile}")" && go mod edit -replace "${dep}=${replacement}@${rev}")
done
fi
popd >/dev/null 2>&1
done