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
2 changes: 1 addition & 1 deletion tests/bats/openemr-cmd/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 13 additions & 5 deletions utilities/openemr-cmd/openemr-cmd
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ set -euo pipefail
#################################################################################################

# Increment the version when modify script
VERSION="1.0.39"
VERSION="1.0.40"

# ============================================================================
# WORKTREE STATE MANAGEMENT
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down