diff --git a/tests/bats/openemr-cmd/helpers.bash b/tests/bats/openemr-cmd/helpers.bash index 945cfde1..3b094bb5 100644 --- a/tests/bats/openemr-cmd/helpers.bash +++ b/tests/bats/openemr-cmd/helpers.bash @@ -62,7 +62,7 @@ STUB # If the script is restructured, bump this constant — the test # 'OC_SCRIPT_FUNCS_END points at end of function defs' in helpers_pure.bats # will fail loudly when it drifts. -OC_SCRIPT_FUNCS_END=1460 +OC_SCRIPT_FUNCS_END=1467 # Source ONLY the function definitions of openemr-cmd into the current shell. # Caller is responsible for setting OPENEMR_ROOT (and WT_STATE_FILE / others diff --git a/utilities/openemr-cmd/openemr-cmd b/utilities/openemr-cmd/openemr-cmd index 9350ea23..0ce52d5f 100755 --- a/utilities/openemr-cmd/openemr-cmd +++ b/utilities/openemr-cmd/openemr-cmd @@ -18,7 +18,7 @@ set -euo pipefail ################################################################################################# # Increment the version when modify script -VERSION="1.0.39" +VERSION="1.0.40" # ============================================================================ # WORKTREE STATE MANAGEMENT @@ -150,9 +150,15 @@ wt_validate_dir() { wt_die "Worktree path '${dir_real}' is not within expected parent '${worktree_parent_real}'" fi - # 3. Ensure it is a registered git worktree of OPENEMR_ROOT - if ! git -C "${OPENEMR_ROOT}" worktree list --porcelain 2>/dev/null \ - | grep -Fqx "worktree ${dir_real}"; then + # 3. Ensure it is a registered git worktree of OPENEMR_ROOT. + # Capture the listing first rather than piping into grep: under pipefail, + # 'grep -q' exits on first match and SIGPIPEs git mid-write, which git + # reports as failure (141) once its output exceeds the pipe buffer (many + # worktrees). A herestring avoids the pipe entirely. + local worktrees + worktrees=$(git -C "${OPENEMR_ROOT}" worktree list --porcelain 2>/dev/null) \ + || wt_die "Cannot list git worktrees of '${OPENEMR_ROOT}'" + if ! grep -Fqx "worktree ${dir_real}" <<< "${worktrees}"; then wt_die "Path '${dir_real}' is not a registered git worktree of '${OPENEMR_ROOT}'" fi } @@ -171,7 +177,9 @@ wt_validate_dir_safe() { return 1 fi - if ! git -C "${OPENEMR_ROOT}" worktree list --porcelain 2>/dev/null | grep -Fqx "worktree ${dir_real}"; then + local worktrees + worktrees=$(git -C "${OPENEMR_ROOT}" worktree list --porcelain 2>/dev/null) || return 1 + if ! grep -Fqx "worktree ${dir_real}" <<< "${worktrees}"; then return 1 fi }