Domanda

I have this pre-commit hook in .git/hooks/pre-commit

#!/bin/bash
for file in `git diff --name-only`
do
  if [[ $file =~ /pom\.xml$ ]]; then
    exec < /dev/tty
    read -p "Committing $file is often a mistake; are you sure you want to do that? (Y/[N]): " ans
    exec <&-
    if [[ $ans =~ ^[Yy]$ ]]; then
      echo proceeding rashly with commit...
    else
      echo aborting commit, O prudent one.
      exit 1
    fi
  fi
done

When I use github for mac (GUI client) to commit, it shows this error:

.git/hooks/pre-commit: line 5: /dev/tty: Device not configured
aborting commit, O prudent one.
 (1)

It works on command line. But I hope to get the GUI client to work. Any ideas? Thanks!

È stato utile?

Soluzione

Your gui client does not provide a tty or any other way of getting input from the user during hooks. So this is not possible. I see two solutions to this problem:

  • Let the commit pass and output a warning. Getting back to the previous state is as simple as git reset HEAD^.
  • Use a git config option to either toggle the check or configure a list of valid pom files.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top