Skip to content

Commit c2d5a17

Browse files
Fix TTY detection using /dev/tty instead of stdin fd
[ -t 0 ] checks whether stdin (fd 0) is a terminal, but git redirects stdin to /dev/null for all hooks — so the check was always false, causing the non-interactive warning to appear even in a normal terminal session. The correct check is to attempt to open /dev/tty (the controlling terminal). A terminal session always has an accessible /dev/tty even when stdin is redirected; a GUI Git client has no controlling terminal at all, so the open fails. This reliably distinguishes the two environments.
1 parent c165f75 commit c2d5a17

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

post-checkout

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,10 @@ log_info "Found $FOUND_SPEC, synchronizing tools..."
129129

130130
# Check if Luca is installed and version is correct, install/update if not
131131
if ! is_luca_installed || ! is_luca_version_correct; then
132-
if [ ! -t 0 ]; then
133-
# No TTY — sudo cannot prompt for a password (e.g. GUI Git client).
132+
if ! { true < /dev/tty; } 2>/dev/null; then
133+
# No controlling terminal — sudo cannot prompt for a password (e.g. GUI Git client).
134+
# Git always redirects stdin to /dev/null for hooks, so [ -t 0 ] is always false;
135+
# opening /dev/tty is the reliable way to test for an accessible terminal session.
134136
# Skip the self-update and fall through to luca install below.
135137
if ! is_luca_installed; then
136138
log_warning "Non-interactive environment detected (e.g. GUI Git client). Luca is not installed — skipping automatic installation. Please run the setup from a terminal."

0 commit comments

Comments
 (0)