0

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!

7
  • 2
    This is a Python error. Nothing specific to C++ or git. Commented Jan 29, 2019 at 8:27
  • How do I get my code (in the c++ project) commit? Commented Jan 29, 2019 at 8:30
  • Well. I suggest you ask yourself if you recently has a Python 2 installation on your system switched out for Python 3. That would explain the Python error. Commented Jan 29, 2019 at 8:33
  • I didn't use Python 2 in my system at all ... Commented Jan 29, 2019 at 8:33
  • 2
    Someone sure did. raw_input is Python 2, and renamed to simply input in Python 3. Things don't just randomly break like that, someone changed the hook or your system. You need to figure out which it was, we can't do that for you. Commented Jan 29, 2019 at 8:35

2 Answers 2

5

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.

By-passing the hook for a commit

git commit --no-verify

By-passing the hook for all the commits to come

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.