我正在研究交互式的预提交Git Hook,以确保在提交之前已满足一组特定条件(例如,更新存储库中的特定文件)。我一直基于清单here创建清单。我的钩子具有相同的实现,但具有不同的问题文本。目前,它可以在Git Bash中完美运行。
但是,对于整个团队的实现,我需要使它在IntelliJ中运行,因为大多数开发人员都在IDE中使用Git功能。使用上面链接的示例挂钩,我的提交因以下错误而失败:
0 files committed, 1 file failed to commit: COMMIT TEST MESSAGE Would you like to play a game? .git/hooks/pre-commit: line 6: /dev/tty: No such device or address
如果可能的话,我希望在IntelliJ中包含完整的交互。如果无法做到这一点,我将开始研究IntelliJ插件开发,以在组织限制内实现此目标。
为方便起见,上面链接的Git钩子粘贴在下面。
#!/bin/sh
echo "Would you like to play a game?"
# Read user input, assign stdin to keyboard
exec < /dev/tty
while read -p "Have you double checked that only relevant files were added? (Y/n) " yn; do
case $yn in
[Yy] ) break;;
[Nn] ) echo "Please ensure the right files were added!"; exit 1;;
* ) echo "Please answer y (yes) or n (no):" && continue;
esac
done
while read -p "Has the documentation been updated? (Y/n) " yn; do
case $yn in
[Yy] ) break;;
[Nn] ) echo "Please add or update the docs!"; exit 1;;
* ) echo "Please answer y (yes) or n (no):" && continue;
esac
done
while read -p "Do you know which issue or PR numbers to reference? (Y/n) " yn; do
case $yn in
[Yy] ) break;;
[Nn] ) echo "Better go check those tracking numbers!"; exit 1;;
* ) echo "Please answer y (yes) or n (no):" && continue;
esac
done
exec <&-
答案 0 :(得分:0)
这是不可能的,IDE不是终端,也没有提供您可以交互使用的tty。您需要使您的钩子显示GUI提示符,或者以其他方式实现所需的内容。
有些插件已经实现了预提交挂钩,例如https://plugins.jetbrains.com/plugin/9278-pre-commit-hook-plugin