【发布时间】:2022-01-07 08:45:32
【问题描述】:
我正在为 .git/hooks/commit-msg 创建一个 commit-msg,当我在此行询问用户 input() 时出现 EOF 错误
response = input("Are you sure you want to commit? [y/N]: ")
如果有人能帮我找出问题所在!
#!/usr/bin/python
import sys
import re
def main():
# open file to read every lines
with open(sys.argv[1], "r") as fp:
lines = fp.readlines()
for idx, line in enumerate(lines):
if line.strip() == "# ------------------------ >8 ------------------------":
break
if line[0] == "#":
continue
# warning message
if (re.search('#[0-9]+$', line) is None):
print("Warning: add issue number related to this commit.")
# ask user to confirm until valid response
try:
while True:
response = input("Are you sure you want to commit? [y/N]: ")
if (response == 'y'):
sys.exit(0)
elif (response == 'N'):
sys.exit(1)
except EOFError as e:
print(e)
# successful commit
print("Success: Perfect commit!")
sys.exit(0)
if __name__ == "__main__":
main()
【问题讨论】:
标签: python git input commit eof