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 ####################################################### 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() {