Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions cli/bash/lib/git/lib_git.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <directory> <result_variable_name>"
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
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion cli/bash/lib/std/lib_std.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 #######################################################

Expand Down
11 changes: 10 additions & 1 deletion cli/bash/lib/std/tests/lib_std.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Loading