首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在git钩子中错误地输入“没有这样的设备或地址”

在git钩子中错误地输入“没有这样的设备或地址”
EN

Stack Overflow用户
提问于 2017-07-20 06:56:38
回答 1查看 1.1K关注 0票数 2

我有一个git钩子,它在循环中执行一些work,直到用户输入是y/Y (n/N除外)。

这对所有人(提交、合并、修正等)都很好。除了重新基地,我得到

代码语言:javascript
复制
.git-hooks/commit-msg: line xx: /dev/tty: No such device or address

当我重述/编辑合并提交时出错。

示例:如果我rebase -i head~4 -p和reword所有提交(包括合并提交),那么我在合并提交时会得到这个错误。

钩子:

代码语言:javascript
复制
#!/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 <&-
EN

回答 1

Stack Overflow用户

发布于 2020-01-21 09:31:00

这个问题发布已经有一段时间了,但我还是想给别人一个反馈,以防其他人也有同样的问题。

通过以下检查,我设法解决了这个问题:

代码语言:javascript
复制
# 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

玩得开心!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45207397

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档