@@ -85,57 +85,63 @@ modules::get_indirect_deps() {
8585
8686# Update modules in batch
8787# Set GOPROXY=direct to avoid https://github.com/golang/go/issues/49111
88- # Args: dry_run patch_only modules...
88+ # Args: dry_run version_query modules...
89+ # - version_query: "latest" or "patch"
8990modules::update_modules_batch () {
9091 local dry_run=$1
91- local patch_only =$2
92+ local version_query =$2
9293 shift 2
9394 local modules=(" $@ " )
9495
9596 if [[ ${# modules[@]} -eq 0 ]]; then
9697 return 0
9798 fi
9899
99- local flag=" -u"
100- local mode=" latest"
101- if [[ " $patch_only " == " true" ]]; then
102- flag=" -u=patch"
103- mode=" patch only"
104- fi
100+ # Build module specs with version query (e.g., module@latest or module@patch)
101+ local module_specs=()
102+ for module in " ${modules[@]} " ; do
103+ module_specs+=(" ${module} @${version_query} " )
104+ done
105105
106- modules::info " Updating ${# modules[@]} modules ($mode ): ${modules[*]} "
106+ modules::info " Updating ${# modules[@]} modules (@ ${version_query} ): ${modules[*]} "
107107
108108 if [[ " $dry_run " == " true" ]]; then
109- echo " [DRY-RUN] GOPROXY=direct go get $flag ${modules [*]}"
109+ echo " [DRY-RUN] GOPROXY=direct go get ${module_specs [*]} "
110110 else
111- if ! GOPROXY=direct go get " $flag " " ${modules [@]}" 2>&1 ; then
111+ if ! GOPROXY=direct go get " ${module_specs [@]} " 2>&1 ; then
112112 modules::error " Some modules failed to update"
113113 return 1
114114 fi
115115 fi
116116}
117117
118118# Update all modules in a directory
119- # Args: dir dry_run patch_prefixes_str allowed_prefixes_str
119+ # Args: dir dry_run patch_prefixes_str allowed_prefixes_str denied_prefixes_str
120120# - dir: directory containing go.mod
121121# - dry_run: "true" or "false"
122122# - patch_prefixes_str: space-separated prefixes for patch-only updates
123123# - allowed_prefixes_str: space-separated prefixes to filter modules (only update matching modules, empty means all direct deps)
124+ # - denied_prefixes_str: space-separated prefixes to exclude modules (if a module matches both allowed and denied, it will NOT be updated)
124125modules::update_dir () {
125126 local dir=$1
126127 local dry_run=$2
127128 local patch_prefixes_str=$3
128129 local allowed_prefixes_str=$4
130+ local denied_prefixes_str=${5:- }
129131
130132 # Convert prefix strings to arrays
131133 local patch_prefixes=()
132134 local allowed_prefixes=()
135+ local denied_prefixes=()
133136 if [[ -n " $patch_prefixes_str " ]]; then
134137 read -ra patch_prefixes <<< " $patch_prefixes_str"
135138 fi
136139 if [[ -n " $allowed_prefixes_str " ]]; then
137140 read -ra allowed_prefixes <<< " $allowed_prefixes_str"
138141 fi
142+ if [[ -n " $denied_prefixes_str " ]]; then
143+ read -ra denied_prefixes <<< " $denied_prefixes_str"
144+ fi
139145
140146 if [[ ! -f " $dir /go.mod" ]]; then
141147 modules::error " No go.mod found in $dir "
@@ -163,13 +169,22 @@ modules::update_dir() {
163169 # Helper function to categorize a module
164170 categorize_module () {
165171 local dep=$1
172+ # Skip if module matches any denied prefix
173+ if [[ ${# denied_prefixes[@]} -gt 0 ]] && modules::match_prefix " $dep " " ${denied_prefixes[@]} " ; then
174+ modules::info " Skipping denied module: $dep "
175+ return 0
176+ fi
166177 if [[ ${# patch_prefixes[@]} -gt 0 ]] && modules::match_prefix " $dep " " ${patch_prefixes[@]} " ; then
167178 patch_modules+=(" $dep " )
168179 else
169180 latest_modules+=(" $dep " )
170181 fi
171182 }
172183
184+ if [[ ${# denied_prefixes[@]} -gt 0 ]]; then
185+ modules::info " Excluding modules by denied prefixes: ${denied_prefixes[*]} "
186+ fi
187+
173188 if [[ ${# allowed_prefixes[@]} -gt 0 ]]; then
174189 # Filter mode: only update modules matching allowed prefixes (both direct and indirect)
175190 modules::info " Filtering modules by allowed prefixes: ${allowed_prefixes[*]} "
@@ -206,15 +221,15 @@ modules::update_dir() {
206221 fi
207222 fi
208223
209- # Batch update modules
224+ # Update modules
210225 if [[ ${# latest_modules[@]} -gt 0 ]]; then
211- if ! modules::update_modules_batch " $dry_run " " false " " ${latest_modules[@]} " ; then
226+ if ! modules::update_modules_batch " $dry_run " " latest " " ${latest_modules[@]} " ; then
212227 popd > /dev/null
213228 return 1
214229 fi
215230 fi
216231 if [[ ${# patch_modules[@]} -gt 0 ]]; then
217- if ! modules::update_modules_batch " $dry_run " " true " " ${patch_modules[@]} " ; then
232+ if ! modules::update_modules_batch " $dry_run " " patch " " ${patch_modules[@]} " ; then
218233 popd > /dev/null
219234 return 1
220235 fi
0 commit comments