Skip to content

Commit 8a56710

Browse files
committed
path: Strip _GO_SCRIPTS_DIR from _GO_PLUGINS_PATHS
This is part of the refactoring of `_GO_USE_MODULES` to provide correct `@go` command script scope for plugin modules. Specifically, it allows the `@go plugins` builtin command to produce the proper output relative to each plugin, but more generally, it makes sense to strip a plugin's `_GO_SCRIPTS_DIR` out of its `_GO_PLUGINS_PATHS`, rather than just stripping it from `_GO_SEARCH_PATHS`.
1 parent 6455607 commit 8a56710

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

lib/internal/set-search-paths

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@
22

33
_@go.set_search_paths_add_plugin_paths() {
44
local plugin_paths=("$1"/*/bin)
5+
local plugin_path
6+
57
if [[ "${plugin_paths[0]}" != "$1/*/bin" ]]; then
6-
_GO_PLUGINS_PATHS+=("${plugin_paths[@]}")
8+
# Ensure a plugin's _GO_SCRIPTS_DIR isn't duplicated in _GO_PLUGINS_PATHS.
9+
for plugin_path in "${plugin_paths[@]}"; do
10+
if [[ "$plugin_path" != "$_GO_SCRIPTS_DIR" ]]; then
11+
_GO_PLUGINS_PATHS+=("$plugin_path")
12+
fi
13+
done
714
fi
815
return 1
916
}
@@ -20,13 +27,7 @@ _@go.set_search_paths() {
2027
# there is a version incompatibility issue with other installed plugins, this
2128
# allows a plugin's preferred version to take precedence.
2229
@go.search_plugins '_@go.set_search_paths_add_plugin_paths'
23-
24-
# Ensure a plugin's _GO_SCRIPTS_DIR isn't duplicated in _GO_SEARCH_PATHS.
25-
for plugin_path in "${_GO_PLUGINS_PATHS[@]}"; do
26-
if [[ "$plugin_path" != "$_GO_SCRIPTS_DIR" ]]; then
27-
_GO_SEARCH_PATHS+=("$plugin_path")
28-
fi
29-
done
30+
_GO_SEARCH_PATHS+=("${_GO_PLUGINS_PATHS[@]}")
3031
}
3132

3233
if [[ "${#_GO_SEARCH_PATHS[@]}" -eq 0 ]]; then

tests/core/plugin-scope-variable-values.bats

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ assert_scope_values_equal() {
104104
'_GO_SCRIPTS_DIR:' \
105105
"$TEST_GO_PLUGINS_DIR/first/bin" \
106106
'_GO_PLUGINS_PATHS:' \
107-
"$TEST_GO_PLUGINS_DIR/first/bin" \
108107
"$TEST_GO_PLUGINS_DIR/second/bin" \
109108
'_GO_SEARCH_PATHS:' \
110109
"$_GO_CORE_DIR/libexec" \
@@ -131,7 +130,6 @@ assert_scope_values_equal() {
131130
'_GO_SCRIPTS_DIR:' \
132131
"$TEST_GO_PLUGINS_DIR/second/bin/plugins/third/bin" \
133132
'_GO_PLUGINS_PATHS:' \
134-
"$TEST_GO_PLUGINS_DIR/second/bin/plugins/third/bin" \
135133
"$TEST_GO_PLUGINS_DIR/first/bin" \
136134
"$TEST_GO_PLUGINS_DIR/second/bin" \
137135
'_GO_SEARCH_PATHS:' \
@@ -151,7 +149,6 @@ assert_scope_values_equal() {
151149
'_GO_PLUGINS_PATHS:' \
152150
"$TEST_GO_PLUGINS_DIR/second/bin/plugins/third/bin" \
153151
"$TEST_GO_PLUGINS_DIR/first/bin" \
154-
"$TEST_GO_PLUGINS_DIR/second/bin" \
155152
'_GO_SEARCH_PATHS:' \
156153
"$_GO_CORE_DIR/libexec" \
157154
"$TEST_GO_PLUGINS_DIR/second/bin" \
@@ -173,7 +170,6 @@ assert_scope_values_equal() {
173170
'_GO_SCRIPTS_DIR:' \
174171
"$TEST_GO_PLUGINS_DIR/first/bin" \
175172
'_GO_PLUGINS_PATHS:' \
176-
"$TEST_GO_PLUGINS_DIR/first/bin" \
177173
"$TEST_GO_PLUGINS_DIR/second/bin" \
178174
'_GO_SEARCH_PATHS:' \
179175
"$_GO_CORE_DIR/libexec" \
@@ -189,7 +185,6 @@ assert_scope_values_equal() {
189185
'_GO_PLUGINS_PATHS:' \
190186
"$TEST_GO_PLUGINS_DIR/second/bin/plugins/third/bin" \
191187
"$TEST_GO_PLUGINS_DIR/first/bin" \
192-
"$TEST_GO_PLUGINS_DIR/second/bin" \
193188
'_GO_SEARCH_PATHS:' \
194189
"$_GO_CORE_DIR/libexec" \
195190
"$TEST_GO_PLUGINS_DIR/second/bin" \

0 commit comments

Comments
 (0)