Skip to content

Instantly share code, notes, and snippets.

@ilyakatz
Last active February 22, 2023 14:51

Revisions

  1. Ilya Katz revised this gist Jan 25, 2013. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion pre-commit
    Original file line number Diff line number Diff line change
    @@ -11,6 +11,7 @@ then
    exit 1
    fi

    .git/hooks/pre-commit-debugger
    .git/hooks/pre-commit-trailing-spaces
    .git/hooks/pre-commit-images
    .git/hooks/pre-commit-pair
    .git/hooks/pre-commit-pair
  2. Ilya Katz revised this gist Jan 25, 2013. 1 changed file with 17 additions and 0 deletions.
    17 changes: 17 additions & 0 deletions pre-commit-debugger
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    #!/bin/sh

    # http://mark-story.com/posts/view/using-git-commit-hooks-to-prevent-stupid-mistakes
    if git-rev-parse --verify HEAD >/dev/null 2>&1; then
    against=HEAD
    else
    against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
    fi

    for FILE in `git diff-index --check --name-status $against -- | cut -c3-` ; do
    # Check if the file contains 'debugger'
    if [ "grep 'debugger' $FILE" ]
    then
    echo $FILE ' contains debugger!'
    exit 1
    fi
    done
  3. Ilya Katz revised this gist Jan 25, 2013. 5 changed files with 12 additions and 5 deletions.
    8 changes: 7 additions & 1 deletion pre-commit
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,16 @@
    #!/bin/bash -l

    # A git hook script to find and fix trailing whitespace
    # in your commits. Bypass it with the --no-verify option
    # to git-commit
    #

    .git/hooks/pre-commit-master-no-no
    if [[ $? == 1 ]]
    then
    exit 1
    fi

    .git/hooks/pre-commit-trailing-spaces
    .git/hooks/pre-commit-images
    .git/hooks/pre-commit-images
    .git/hooks/pre-commit-pair
    2 changes: 0 additions & 2 deletions pre-commit-images
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,5 @@
    #!/bin/bash -l

    source ./.rvmrc

    echo "Optimizing images"

    # Find image files and optimize them
    2 changes: 1 addition & 1 deletion pre-commit-master-no-no
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    #!/bin/bash -l
    #!/bin/bash

    #Hook to verify that comments are not done to the master branch accidentally
    #Need to check the status and exit the hook if this script exits with a non-zero code
    3 changes: 3 additions & 0 deletions pre-commit-pair
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    #!/bin/bash

    echo `git about |grep "git user"`
    2 changes: 1 addition & 1 deletion pre-commit-trailing-spaces
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    #!/bin/bash -l
    #!/bin/bash

    echo "Remove trailing spaces"
    if git-rev-parse --verify HEAD >/dev/null 2>&1 ; then
  4. Ilya Katz revised this gist Jan 24, 2013. 1 changed file with 0 additions and 5 deletions.
    5 changes: 0 additions & 5 deletions pre-commit
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,5 @@
    #!/bin/bash -l

    # A git hook script to find and fix trailing whitespace
    # in your commits. Bypass it with the --no-verify option
    # to git-commit
    #

    .git/hooks/pre-commit-master-no-no
    if [[ $? == 1 ]]
    then
  5. Ilya Katz revised this gist Jan 24, 2013. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions pre-commit
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,5 @@
    #!/bin/bash -l

    source ./.rvmrc

    # A git hook script to find and fix trailing whitespace
    # in your commits. Bypass it with the --no-verify option
    # to git-commit
  6. Ilya Katz revised this gist Jan 24, 2013. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion pre-commit
    Original file line number Diff line number Diff line change
    @@ -11,4 +11,7 @@ source ./.rvmrc
    if [[ $? == 1 ]]
    then
    exit 1
    fi
    fi

    .git/hooks/pre-commit-trailing-spaces
    .git/hooks/pre-commit-images
  7. Ilya Katz revised this gist Jan 24, 2013. 2 changed files with 30 additions and 0 deletions.
    12 changes: 12 additions & 0 deletions pre-commit-images
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    #!/bin/bash -l

    source ./.rvmrc

    echo "Optimizing images"

    # Find image files and optimize them
    for FILE in `exec git diff --cached --name-status | grep ".png$" | awk '$1 != "R" { print $2 }'`; do
    echo "Optimizing $FILE"
    bundle exec smusher $FILE
    git add "$FILE"
    done
    18 changes: 18 additions & 0 deletions pre-commit-trailing-spaces
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    #!/bin/bash -l

    echo "Remove trailing spaces"
    if git-rev-parse --verify HEAD >/dev/null 2>&1 ; then
    against=HEAD
    else
    # Initial commit: diff against an empty tree object
    against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
    fi

    echo $against
    # Find files with trailing whitespace
    for FILE in `exec git diff-index --check $against -- | sed '/^[+-]/d' | (sed -r 's/:[0-9]+:.*//' > /dev/null 2>&1 || sed -E 's/:[0-9]+:.*//') | uniq` ; do
    # Fix them!
    echo $FILE
    (sed -i 's/[[:space:]]*$//' "$FILE" > /dev/null 2>&1 || sed -i '' -E 's/[[:space:]]*$//' "$FILE")
    git add "$FILE"
    done
  8. Ilya Katz revised this gist Jan 24, 2013. 1 changed file with 25 additions and 0 deletions.
    25 changes: 25 additions & 0 deletions pre-commit-master-no-no
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    #!/bin/bash -l

    #Hook to verify that comments are not done to the master branch accidentally
    #Need to check the status and exit the hook if this script exits with a non-zero code
    #.git/hooks/pre-commit-master-no-no
    #if [[ $? == 1 ]]
    #then
    # exit 1
    #fi

    if [[ `git symbolic-ref HEAD` == "refs/heads/master" ]]
    then
    if [[ ! -f /tmp/master_commit ]]
    then
    echo "*************************"
    echo "CANNOT COMMIT TO MASTER!"
    echo "To override this behavior"
    echo "touch /tmp/master_commit"
    echo "*************************"
    exit 1
    else
    echo "Removing /tmp/master_commit"
    rm /tmp/master_commit
    fi
    fi
  9. Ilya Katz created this gist Jan 24, 2013.
    14 changes: 14 additions & 0 deletions pre-commit
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    #!/bin/bash -l

    source ./.rvmrc

    # A git hook script to find and fix trailing whitespace
    # in your commits. Bypass it with the --no-verify option
    # to git-commit
    #

    .git/hooks/pre-commit-master-no-no
    if [[ $? == 1 ]]
    then
    exit 1
    fi