Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6585335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:39:00+00:00 2026-05-25T16:39:00+00:00

I am writing a pre-commit hook for Git that runs pyflakes and checks for

  • 0

I am writing a pre-commit hook for Git that runs pyflakes and checks for tabs and trailing spaces in the modified files (code on Github). I would like to make it possible to override the hook by asking for user confirmation as follows:

answer = raw_input('Commit anyway? [N/y] ')
if answer.strip()[0].lower() == 'y':
    print >> sys.stderr, 'Committing anyway.'
    sys.exit(0)
else:
    print >> sys.stderr, 'Commit aborted.'
    sys.exit(1)

This code produces an error:

Commit anyway? [N/y] Traceback (most recent call last):
  File ".git/hooks/pre-commit", line 59, in ?
    main()
  File ".git/hooks/pre-commit", line 20, in main
    answer = raw_input('Commit anyway? [N/y] ')
EOFError: EOF when reading a line

Is it even possible to use raw_input() or a similar function in Git hooks and if yes, what am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T16:39:01+00:00Added an answer on May 25, 2026 at 4:39 pm

    You could use:

    sys.stdin = open('/dev/tty')
    answer = raw_input('Commit anyway? [N/y] ')
    if answer.strip().lower().startswith('y'):
        ...
    

    git commit calls python .git/hooks/pre-commit:

    % ps axu
    ...
    unutbu   21801  0.0  0.1   6348  1520 pts/1    S+   17:44   0:00 git commit -am line 5a
    unutbu   21802  0.1  0.2   5708  2944 pts/1    S+   17:44   0:00 python .git/hooks/pre-commit
    

    Looking inside /proc/21802/fd (on this linux box) shows the state of the file descriptors for the process with PID 21802 (the pre-commit process):

      /proc/21802/fd:
      lrwx------ 1 unutbu unutbu 64 2011-09-15 17:45 0 -> /dev/null
      lrwx------ 1 unutbu unutbu 64 2011-09-15 17:45 1 -> /dev/pts/1
      lrwx------ 1 unutbu unutbu 64 2011-09-15 17:45 2 -> /dev/pts/1
      lr-x------ 1 unutbu unutbu 64 2011-09-15 17:45 3 -> /dev/tty
      lr-x------ 1 unutbu unutbu 64 2011-09-15 17:45 5 -> /dev/null
    

    Thus, pre-commit was spawned with sys.stdin pointing at /dev/null.
    sys.stdin = open('/dev/tty') redirects sys.stdin to an open filehandle from which raw_input can read.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a pre-commit hook, or better, I'm editing the hook that comes standard
I'm trying to figure out how to write a pre-commit hook for Git that
I'm writing a pre-commit hook, and would like to do a check on the
I am writing a pre-commit hook. I want to run php -l against all
I'm writing a pre-commit hook in C# and I know I have to return
I am writing some code that is intended to operate with a pre-bundled version
I am writing a pre-commit hook where I would like to enforce some rule
I'm writing code where I retrieve XML from a web api, then parse that
I'm writing a Drupal module that deals with creating new nodes from CSV files.
I'm writing a small Scala app that does the following: 1) Read XML/XHTML files

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.