2

I have a git hook that does some work in a loop till the user input is y/Y (other than n/N).

This works fine for all (commits, merges, amends, etc). Except for rebase, I get

.git-hooks/commit-msg: line xx: /dev/tty: No such device or address

error when I reword/edit a merge commit.

Example: If I rebase -i head~4 -p and reword all commits (that include merge commits) then I get this error on the merge commits.

hook:

#!/bin/sh

# git hook

work() {
    echo "working..."
}

user_input() {
    while true; do
        work "$@"
        echo -e -n "done?"
        read -p '' ans
        case $ans in
            [nN] )
                ;;
            * )
                break ;;
        esac        
    done
}

exec < /dev/tty
user_input "$@"
exec <&-
hIpPy
  • 4,649
  • 6
  • 51
  • 65

1 Answers1

0

It's been a while since this question was posted, but I still wanted to give a feedback in case someone else has the same problem.

I managed to get around this issue with the following check:

# check if a rebase is taking place
# https://stackoverflow.com/questions/3921409/how-to-know-if-there-is-a-git-rebase-in-progress
if [ -d "./.git/rebase-merge" ] || [ -d "./.git/rebase-apply" ]; then
  exit
else
  # allow to use bash prompt in hook
  # https://stackoverflow.com/questions/48640615/bash-confirmation-wont-wait-for-user-input
  exec < /dev/tty
fi

Have fun!

SebastianRV
  • 25
  • 1
  • 7