This commit is contained in:
Bishoy Ehab
2025-10-17 14:31:54 +03:00
parent d809c2e789
commit 809c8806d0
+9 -1
View File
@@ -111,7 +111,8 @@ safe_read() {
local input_value="" local input_value=""
echo -n "$prompt" echo -n "$prompt"
if read -r input_value </dev/tty 2>/dev/null || read -r input_value 2>/dev/null; then # Try to read from tty only if it's an interactive session
if [[ -t 0 ]] && read -r input_value </dev/tty 2>/dev/null || read -r input_value 2>/dev/null; then
# Use printf instead of eval for security # Use printf instead of eval for security
printf -v "$varname" '%s' "$input_value" printf -v "$varname" '%s' "$input_value"
return 0 return 0
@@ -706,11 +707,18 @@ if ! git diff --quiet || ! git diff --cached --quiet; then
git status --short git status --short
echo echo
response="n"
# The 'check' variable is set to false when --skip-notice is used, which we use to detect non-interactive mode.
if [[ "$check" == false ]]; then
log_info "Non-interactive mode detected, automatically stashing changes."
response="y"
else
if ! safe_read "Do you want to continue? This will stash your changes. (y/N): " response "N"; then if ! safe_read "Do you want to continue? This will stash your changes. (y/N): " response "N"; then
echo echo
log_error "Failed to read input. Aborting." log_error "Failed to read input. Aborting."
exit 1 exit 1
fi fi
fi
if [[ ! "$response" =~ ^[Yy]$ ]]; then if [[ ! "$response" =~ ^[Yy]$ ]]; then
die "Aborted by user" die "Aborted by user"