我正在开发一个交互式的Git预提交钩子,以确保在提交之前满足一定的标准(例如更新存储库中的特定文件)。我的清单基于此处的示例。我的钩子具有相同的实现,但问题文本不同。目前,在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 <&-