From 0c62692f59599a15ae9daaede0ede9fd6cb2759a Mon Sep 17 00:00:00 2001 From: Ramesh Padmanabhaiah Date: Wed, 15 Apr 2026 06:43:56 -0700 Subject: [PATCH 1/2] Fix ShellCheck findings in Bash CLI libraries Clean up the remaining ShellCheck issues reported by CI across the Bash wrapper, shared env bootstrap, and Bash libraries. Changes include: - add Bash shell directives/shebangs where ShellCheck could not infer the shell - export BANYAN_BASH_BOOTSTRAP_SOURCE before sourcing stdlib from bash-wrapper - rewrite lib_file status checks so command results are checked directly - quote the Git upstream ref '@{u}' in lib_git - replace a nameref assignment in git_get_current_branch with printf -v - split __SCRIPT_DIR__ declaration and assignment in lib_std - avoid masked return values and unquoted exits in lib_std - make safe_mkdir and safe_truncate ShellCheck-friendly - tighten pushd/popd handling in stdlib and git helpers - simplify banyanenv sourced-error handling Validation: - bash -n over CLI shell scripts - full BATS suite: 98 tests, 0 failures, 1 skipped --- cli/bash/lib/git/lib_git.sh | 13 ++++++------- cli/bash/lib/std/lib_std.sh | 3 ++- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cli/bash/lib/git/lib_git.sh b/cli/bash/lib/git/lib_git.sh index 76a7a9e..c92898b 100644 --- a/cli/bash/lib/git/lib_git.sh +++ b/cli/bash/lib/git/lib_git.sh @@ -129,16 +129,15 @@ git_update_repo() { # git_get_current_branch() { local target_dir="$1" + local result_var_name="${2:-}" # --- Argument Validation --- - if [[ -z "$target_dir" || -z "${2:-}" ]]; then + if [[ -z "$target_dir" || -z "$result_var_name" ]]; then log_error "Usage: get_git_branch " return 1 fi - # Create a name reference to the variable name passed as the second argument. - local -n result_var="$2" - result_var="" + printf -v "$result_var_name" '%s' "" if [[ ! -d "$target_dir" ]]; then return 1 @@ -165,10 +164,10 @@ git_get_current_branch() { local branch_name if branch_name=$(git symbolic-ref --short -q HEAD); then # Success: We are on a named branch. - result_var="$branch_name" + printf -v "$result_var_name" '%s' "$branch_name" else # Failure: We are in a detached HEAD state. - result_var="detached head" + printf -v "$result_var_name" '%s' "detached head" fi popd >/dev/null || return 1 @@ -232,7 +231,7 @@ check_script_up_to_date() { fi local upstream behind ahead - upstream=$(git -C "$repo_root" rev-parse --abbrev-ref --symbolic-full-name @{u} 2>/dev/null) || { + upstream=$(git -C "$repo_root" rev-parse --abbrev-ref --symbolic-full-name '@{u}' 2>/dev/null) || { log_info "No upstream branch configured; skipping latest-version check." return 0 } diff --git a/cli/bash/lib/std/lib_std.sh b/cli/bash/lib/std/lib_std.sh index f988bd9..8a32a0d 100644 --- a/cli/bash/lib/std/lib_std.sh +++ b/cli/bash/lib/std/lib_std.sh @@ -62,9 +62,10 @@ readonly __LIB_STD_PATH__="${BASH_SOURCE[0]}" # readonly __SCRIPT_ARGS__=("$@") __new_args__=() -readonly __SCRIPT_DIR__=$( +__SCRIPT_DIR__=$( cd -- "$(dirname -- "${BANYAN_BASH_BOOTSTRAP_SOURCE:-${BASH_SOURCE[1]}}" )" &>/dev/null && pwd -P ) +readonly __SCRIPT_DIR__ ############################################ BASH VERSION CHECKER ####################################################### From 61b2f3fb5fcaf8837f95b154890c916376a2f570 Mon Sep 17 00:00:00 2001 From: Ramesh Padmanabhaiah Date: Wed, 15 Apr 2026 06:52:34 -0700 Subject: [PATCH 2/2] Fix stdlib TTY tests on Linux CI Make the stdlib BATS pseudo-TTY helper portable across macOS and GitHub Actions Linux runners. The TTY-related stdlib tests used BSD/macOS `script` syntax: script -q /dev/null ... That works locally on macOS but fails on Ubuntu GitHub Actions, where `script` is provided by util-linux and expects the command via `-c`. Update `run_tty_script` to: - skip TTY tests when `script` is unavailable - detect util-linux `script` via `script --version` - use `script -q -e -c "" /dev/null` on Linux - keep the existing BSD/macOS invocation for local runs This fixes CI failures for: - `is_interactive is true when run through a tty` - `color initialization honors tty mode when --color is passed` - `print_tty emits output when a tty is present` Validation: - full BATS suite: 98 tests, 0 failures, 1 skipped --- cli/bash/lib/std/tests/lib_std.bats | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cli/bash/lib/std/tests/lib_std.bats b/cli/bash/lib/std/tests/lib_std.bats index 0a8fd8f..3f7e80d 100644 --- a/cli/bash/lib/std/tests/lib_std.bats +++ b/cli/bash/lib/std/tests/lib_std.bats @@ -19,8 +19,17 @@ normalize_tty_output() { run_tty_script() { local script_path="$1" + local command shift - bats_run script -q /dev/null "$script_path" "$@" + + command -v script >/dev/null 2>&1 || skip "The 'script' command is required for tty tests." + + if script --version >/dev/null 2>&1; then + printf -v command '%q ' "$script_path" "$@" + bats_run script -q -e -c "${command% }" /dev/null + else + bats_run script -q /dev/null "$script_path" "$@" + fi } setup() {