From f737c5d3410e88524d18e26c633c89e2d495832a Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Mon, 26 Sep 2022 14:45:33 +0200 Subject: [PATCH] update-vendor.sh: handle empty staging repo A staging repo which just got created with only the doc.go file in it won't have any dependencies yet, which caused the script to fail because the dependency files didn't get created: +++ [0926 14:33:22] go.mod: tidying cat: /tmp/update-vendor.1VTv/group_replace.ZbIT/go.mod.require_direct.tmp: No such file or directory !!! [0926 14:33:23] Call tree: !!! [0926 14:33:23] 1: hack/update-vendor.sh:354 group_directives(...) --- hack/update-vendor.sh | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/hack/update-vendor.sh b/hack/update-vendor.sh index 0f0fe47af77..5b35ef7cfb1 100755 --- a/hack/update-vendor.sh +++ b/hack/update-vendor.sh @@ -114,6 +114,17 @@ function ensure_require_replace_directives_for_all_dependencies() { | xargs -L 100 go mod edit -fmt } +function print_go_mod_section() { + local directive="$1" + local file="$2" + + if [ -s "${file}" ]; then + echo "${directive} (" + cat "$file" + echo ")" + fi +} + function group_directives() { local local_tmp_dir local_tmp_dir=$(mktemp -d "${TMP_DIR}/group_replace.XXXX") @@ -146,15 +157,9 @@ function group_directives() { " < go.mod { cat "${go_mod_other}"; - echo "require ("; - cat "${go_mod_require_direct}"; - echo ")"; - echo "require ("; - cat "${go_mod_require_indirect}"; - echo ")"; - echo "replace ("; - cat "${go_mod_replace}"; - echo ")"; + print_go_mod_section "require" "${go_mod_require_direct}" + print_go_mod_section "require" "${go_mod_require_indirect}" + print_go_mod_section "replace" "${go_mod_replace}" } > go.mod go mod edit -fmt