IntelliJ 中的交互式预提交挂钩
Interactive Pre-Commit Hook in IntelliJ
我正在开发一个交互式预提交 Git 挂钩,以确保在提交之前满足一组特定的条件(例如,更新存储库中的特定文件)。我的清单一直基于示例 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 <&-
不可能,IDE不是终端,不提供任何可以交互使用的 tty。您需要让您挂钩显示 GUI 提示,或者以不同的方式实现您想要的。
有些插件已经实现了预提交挂钩,例如https://plugins.jetbrains.com/plugin/9278-pre-commit-hook-plugin
我正在开发一个交互式预提交 Git 挂钩,以确保在提交之前满足一组特定的条件(例如,更新存储库中的特定文件)。我的清单一直基于示例 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 <&-
不可能,IDE不是终端,不提供任何可以交互使用的 tty。您需要让您挂钩显示 GUI 提示,或者以不同的方式实现您想要的。
有些插件已经实现了预提交挂钩,例如https://plugins.jetbrains.com/plugin/9278-pre-commit-hook-plugin