fix(common.sh): use tty open test instead of -r for no-TTY detection

macOS /dev/tty passes -r check even when unusable in non-TTY sessions;
replace with `true < /dev/tty` probe so confirm_destructive and
confirm_exact_match correctly detect missing TTY and emit the expected
error message instead of crashing with "Device not configured".
This commit is contained in:
timmy
2026-04-21 13:16:12 +08:00
parent faee15bc78
commit 0aad9c9c55

View File

@@ -158,7 +158,7 @@ confirm_destructive() {
if [[ "${GITEA_YES:-0}" == "1" ]]; then if [[ "${GITEA_YES:-0}" == "1" ]]; then
return 0 return 0
fi fi
if [[ ! -r /dev/tty ]]; then if ! { true < /dev/tty; } 2>/dev/null; then
log_err "需要確認但無 TTY請加 -y / --yes 或設定 GITEA_YES=1" log_err "需要確認但無 TTY請加 -y / --yes 或設定 GITEA_YES=1"
exit 1 exit 1
fi fi
@@ -178,7 +178,7 @@ confirm_exact_match() {
if [[ "${GITEA_YES:-0}" == "1" ]]; then if [[ "${GITEA_YES:-0}" == "1" ]]; then
return 0 return 0
fi fi
if [[ ! -r /dev/tty ]]; then if ! { true < /dev/tty; } 2>/dev/null; then
log_err "需要確認但無 TTY請加 -y / --yes 或設定 GITEA_YES=1" log_err "需要確認但無 TTY請加 -y / --yes 或設定 GITEA_YES=1"
exit 1 exit 1
fi fi