News for hackers. Stuff that matters.
Re:Yipit Django Blog: Why You Need a Git Pre-Commit Hook by notaddicted on Wednesday November 16, 2011 @03:52PM (#3245011)
This is what I use with django+south to prevent forgetting to commit migrations:

  MIGRATIONS_DIRECTORIES="$(find -type d -iname migrations)"
  UNTRACKED_MIGRATIONS="$(git ls-files --exclude-standard --others -- $MIGRATIONS_DIRECTORIES | egrep '(.*)[.]py$')"
  
  if test -z "$UNTRACKED_MIGRATIONS"; then
      # If there are no untracked .py files in the migrations directory, do nothing, allow commit.
      true;
  else
      # If there are untracked files in the migrations directory print a warning message.
      echo "Warning -- Untracked files in the migrations directory"
      echo 'The commit may be forced with "git commit --no-verify"'
      echo 
      echo "$UNTRACKED_MIGRATIONS"
      exit 1
  fi

There are no comments on this comment yet.