我有一个git钩子,它在循环中执行一些work,直到用户输入是y/Y (n/N除外)。
这对所有人(提交、合并、修正等)都很好。除了重新基地,我得到
.git-hooks/commit-msg: line xx: /dev/tty: No such device or address当我重述/编辑合并提交时出错。
示例:如果我rebase -i head~4 -p和reword所有提交(包括合并提交),那么我在合并提交时会得到这个错误。
钩子:
#!/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 <&-发布于 2020-01-21 09:31:00
这个问题发布已经有一段时间了,但我还是想给别人一个反馈,以防其他人也有同样的问题。
通过以下检查,我设法解决了这个问题:
# 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玩得开心!
https://stackoverflow.com/questions/45207397
复制相似问题