/usr/bin/env: ‘python\r’: No such file or directory
已完成
I'm working to learn Django. I've been working through a Django cookbook. My code was working fine until I started layering in changes to manage different environment deployment. It looks like the git pre-commit file is causing a error whenever I try to commit a change, stating
"/usr/bin/env: ‘python\r’: No such file or directory"
If I hide the pre-commit file the commit succeeds. I've been banging my head against this for some time now (Google, phone-a-friend, etc.)
Thanks
Jamie
Here's my pre-commit file.
#!/usr/bin/env python
from subprocess import check_output, CalledProcessError
import os
from datetime import datetime
def root():
''' returns the absolute path of the repository root '''
try:
base = check_output(['git', 'rev-parse', '--show-toplevel'])
except CalledProcessError:
raise IOError('Current working directory is not a git repository')
return base.decode('utf-8').strip()
def abspath(relpath):
''' returns the absolute path for a path given relative to the root of
the git repository
'''
return os.path.join(root(), relpath)
def add_to_git(file_path):
''' adds a file to git '''
try:
base = check_output(['git', 'add', file_path])
except CalledProcessError:
raise IOError('Current working directory is not a git repository')
return base.decode('utf-8').strip()
def main():
file_path = abspath("myproject/settings/last-update.txt")
with open(file_path, 'w') as f:
f.write(datetime.now().strftime("%Y%m%d%H%M%S"))
add_to_git(file_path)
if __name__ == '__main__':
main()
.git/hooks/pre-commit (END)
请先登录再写评论。
OK, I figured out the problem. It was the line endings. As soon as i ran DOS2UNIX on the pre-commit file, the commits started working again. :-)
Consider this a marker on the navigation chart next to a cluster of shipwrecks.
Jamie
I'm glad that you figured this out.
Thank you for posting the solution :)