Reputation: 25366
The project I normally work on gave me the following error today when I try to commit in a new branch:
Traceback (most recent call last):
File ".git/hooks/pre-commit", line 86, in <module>
clang_format(f)
File ".git/hooks/pre-commit", line 41, in clang_format
action = raw_input('{} does not conform to clang-format rules. '
NameError: name 'raw_input' is not defined
Any idea how I can fix this? At least just get my codes commit. Thanks!
Upvotes: 0
Views: 4630
Reputation: 487725
As several people mentioned in comments, it's clear that what is happening here is that a Python-2.x script is being interpreted by a Python-3.x interpreter.
Systems with both flavors of Python installed will sometimes use the name python2
to invoke the Python 2.x interpreter and python3
to invoke the Python 3.y interpreter. (The value of x
and y
here may vary, though no one should be using anything earlier than Python 2.7 these days, and it's a good idea to move to Python 3 soon.)
Converting a Python 2 script to Python 3 is usually pretty easy, but if you have both interpreters installed, and your script itself simply reads:
#! /usr/bin/env python
... script ...
the quickest way to make it use Python 2, if that's still on your system under the name python2
, is to change the first line to read:
#! /usr/bin/env python2
The first line may vary somewhat but the general idea is that #!
is followed by the full path name of the interpreter, then any argument for that interpreter. Using /usr/bin/env
as the interpreter allows further path-searching, so that you can then have it find python
, python2
, python3
, python3.6
, python3.7
, etc., as appropriate.
As YSC answered, from the Git side, you can just skip the entire pre-commit script.
Upvotes: 1
Reputation: 40060
You can temporarily disable the pre-commit hook to secure your changes before trying to understand what's going on on your system.
Either commit with the --no-verify
flag or disable the hook if you need to do multiple commits.
git commit --no-verify
At the root of your git project, do:
chmod -x .git/hooks/pre-commit
This disables the hook calling the vexing python script and let you commit whatever you want without any check. Beware though, no check is performed.
Upvotes: 5