Skip to content

Commit fdaaa98

Browse files
mnriemCopilot
andcommitted
fix: make bash scripts portable to bash 3.2 (macOS system /bin/bash)
Adding macos-latest to the CI matrix surfaced two pre-existing bash 3.2 incompatibilities (macOS ships bash 3.2 as /bin/bash): 1. update-agent-context.sh embedded Python heredocs inside $(...) command substitution. bash 3.2 mis-parses an apostrophe in a heredoc body nested in $(...), failing with "unexpected EOF while looking for matching `''". Removed the apostrophes from the affected $()-nested heredoc body and documented the constraint to prevent regressions. 2. create-new-feature-branch.sh and create-new-feature.sh used the bash 4+ ${word^^} uppercase parameter expansion, which errors as a "bad substitution" on bash 3.2 and caused short uppercase acronyms (e.g. "GO") to be dropped from derived branch names. Replaced with a portable `tr '[:lower:]' '[:upper:]'` pipeline. Verified the full test suite passes under bash 3.2.57 and shellcheck (--severity=error) is clean. Assisted-by: GitHub Copilot (model: Claude Opus 4.8, autonomous) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent bbf9c3c commit fdaaa98

3 files changed

Lines changed: 13 additions & 5 deletions

File tree

extensions/agent-context/scripts/bash/update-agent-context.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ case "$(uname -s 2>/dev/null || true)" in
5959
esac
6060

6161
# Parse extension config once; emit context files as JSON, followed by marker strings.
62+
#
63+
# NOTE (bash 3.2 / macOS portability): the embedded Python heredocs below run
64+
# inside $(...) command substitution. bash 3.2 (the system /bin/bash on macOS)
65+
# mis-parses a single-quote/apostrophe in a heredoc body nested in $(...),
66+
# failing with "unexpected EOF while looking for matching `''". Keep these
67+
# $(...)-nested heredoc bodies free of apostrophes (use double quotes in Python
68+
# string literals and avoid contractions in comments).
6269
if ! _raw_opts="$("$_python" - "$EXT_CONFIG" "$_case_insensitive_context_files" "$PROJECT_ROOT" <<'PY'
6370
import json
6471
import sys
@@ -115,7 +122,8 @@ if not context_files:
115122
if not context_files:
116123
# Self-seed: the agent-context extension owns its lifecycle, so when its
117124
# own config declares no target it derives one from the active integration
118-
# recorded in init-options.json, using the extension's OWN bundled mapping
125+
# recorded in init-options.json, using the OWN bundled mapping of the
126+
# agent-context extension
119127
# (agent-context-defaults.json). This is independent of the Specify CLI by
120128
# design — nothing here imports specify_cli.
121129
project_root = sys.argv[3] if len(sys.argv) > 3 else "."
@@ -144,15 +152,15 @@ if not context_files:
144152
except Exception:
145153
print(
146154
"agent-context: unable to read %s; cannot self-seed the context "
147-
"file. Set 'context_file' in the extension config." % defaults_path,
155+
"file. Set context_file in the extension config." % defaults_path,
148156
file=sys.stderr,
149157
)
150158
mapping = {}
151159
add_context_file(mapping.get(integration_key, "") or "")
152160
if not context_files:
153161
print(
154162
"agent-context: no default context file is known for integration "
155-
"'%s'. Set 'context_file' in the extension config to choose one."
163+
"%s. Set context_file in the extension config to choose one."
156164
% integration_key,
157165
file=sys.stderr,
158166
)

extensions/git/scripts/bash/create-new-feature-branch.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ generate_branch_name() {
288288
if ! echo "$word" | grep -qiE "$stop_words"; then
289289
if [ ${#word} -ge 3 ]; then
290290
meaningful_words+=("$word")
291-
elif echo "$description" | grep -qw -- "${word^^}"; then
291+
elif echo "$description" | grep -qw -- "$(printf '%s' "$word" | tr '[:lower:]' '[:upper:]')"; then
292292
meaningful_words+=("$word")
293293
fi
294294
fi

scripts/bash/create-new-feature.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ generate_branch_name() {
152152
if ! echo "$word" | grep -qiE "$stop_words"; then
153153
if [ ${#word} -ge 3 ]; then
154154
meaningful_words+=("$word")
155-
elif echo "$description" | grep -q "\b${word^^}\b"; then
155+
elif echo "$description" | grep -q "\b$(printf '%s' "$word" | tr '[:lower:]' '[:upper:]')\b"; then
156156
# Keep short words if they appear as uppercase in original (likely acronyms)
157157
meaningful_words+=("$word")
158158
fi

0 commit comments

Comments
 (0)