Skip to content

Instantly share code, notes, and snippets.

@bingdian
Forked from xbx/gist:1533842
Created December 11, 2015 03:45
Show Gist options
  • Select an option

  • Save bingdian/ca67d7e18d09b76b29ec to your computer and use it in GitHub Desktop.

Select an option

Save bingdian/ca67d7e18d09b76b29ec to your computer and use it in GitHub Desktop.

Revisions

  1. @xbx xbx revised this gist Dec 30, 2011. 1 changed file with 11 additions and 3 deletions.
    14 changes: 11 additions & 3 deletions gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -67,8 +67,11 @@ fi
    JSHINT_BIN=/usr/bin/jshint
    for FILE in `git diff-index --name-only ${against} -- | egrep *.js`; do

    # with jsc:
    ${JSHINT_BIN} ${REPO}/${FILE}
    if test -f ${REPO}/${FILE}; then
    ${JSHINT_BIN} ${REPO}/${FILE}
    else
    continue
    fi

    # could similarly wrap Rhino or Node...

    @@ -83,7 +86,12 @@ done
    CSSLINT_BIN=/usr/bin/csslint
    for FILE in `git diff-index --name-only ${against} -- | egrep *.css`; do

    ${CSSLINT_BIN} ${REPO}/${FILE}
    if test -f ${REPO}/${FILE}; then
    ${CSSLINT_BIN} ${REPO}/${FILE}
    else
    continue
    fi


    # could similarly wrap Rhino or Node...

  2. @xbx xbx revised this gist Dec 30, 2011. 1 changed file with 20 additions and 12 deletions.
    32 changes: 20 additions & 12 deletions gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,11 @@
    #!/bin/sh
    #
    # An hook script to verify what is about to be committed.
    # An example hook script to verify what is about to be committed.
    # Called by "git commit" with no arguments. The hook should
    # exit with non-zero status after issuing an appropriate message if
    # it wants to stop the commit.
    #
    # To enable this hook, save it as .git/hooks/pre-commit
    # To enable this hook, rename this file to "pre-commit".

    if git rev-parse --verify HEAD >/dev/null 2>&1
    then
    @@ -46,17 +46,23 @@ fi
    ## Common
    EXIT_CODE=0
    REPO=$(pwd)

    #
    # Checking trailing whitespaces and indent
    #

    git diff --cached --check --color=always
    EXIT_STATUS=$?
    ## Checking trailing whitespaces and indent
    if [[ $EXIT_STATUS -ne 0 ]]; then
    EXIT_CODE=$((${EXIT_CODE} + $EXIT_STATUS))
    fi


    ## Begin JsHint hook
    #
    # Begin JsHint hook
    # A pre-commit hook for git to lint JavaScript files with jshint
    # @see https://github.com/jshint/jshint/
    #

    JSHINT_BIN=/usr/bin/jshint
    for FILE in `git diff-index --name-only ${against} -- | egrep *.js`; do
    @@ -68,15 +74,13 @@ for FILE in `git diff-index --name-only ${against} -- | egrep *.js`; do

    EXIT_CODE=$((${EXIT_CODE} + $?))
    done
    # End JsHint hook

    ## End JsHint hook

    #
    # Begin CssLint hook
    #

    ## Begin CssLint hook
    CSSLINT_BIN=/usr/bin/csslint


    ## End CssLint hook
    for FILE in `git diff-index --name-only ${against} -- | egrep *.css`; do

    ${CSSLINT_BIN} ${REPO}/${FILE}
    @@ -85,11 +89,15 @@ for FILE in `git diff-index --name-only ${against} -- | egrep *.css`; do

    EXIT_CODE=$((${EXIT_CODE} + $?))
    done
    # End CssLint hook

    #
    # Common
    #

    ## Common
    if [[ ${EXIT_CODE} -ne 0 ]]; then
    echo ""
    echo "Problems were found"
    echo "Commit aborted."
    exit ${EXIT_CODE}
    fi
    fi
  3. @xbx xbx revised this gist Dec 29, 2011. 1 changed file with 11 additions and 7 deletions.
    18 changes: 11 additions & 7 deletions gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,11 @@
    #!/bin/sh
    #
    # An example hook script to verify what is about to be committed.
    # An hook script to verify what is about to be committed.
    # Called by "git commit" with no arguments. The hook should
    # exit with non-zero status after issuing an appropriate message if
    # it wants to stop the commit.
    #
    # To enable this hook, rename this file to "pre-commit".
    # To enable this hook, save it as .git/hooks/pre-commit

    if git rev-parse --verify HEAD >/dev/null 2>&1
    then
    @@ -45,12 +45,19 @@ fi

    ## Common
    EXIT_CODE=0
    REPO=$(pwd)
    git diff --cached --check --color=always
    EXIT_STATUS=$?
    ## Checking trailing whitespaces and indent
    if [[ $EXIT_STATUS -ne 0 ]]; then
    EXIT_CODE=$((${EXIT_CODE} + $EXIT_STATUS))
    fi


    ## Begin JsHint hook
    # A pre-commit hook for git to lint JavaScript files with jshint
    # @see https://github.com/jshint/jshint/

    REPO=$(pwd)
    JSHINT_BIN=/usr/bin/jshint
    for FILE in `git diff-index --name-only ${against} -- | egrep *.js`; do

    @@ -66,7 +73,6 @@ done


    ## Begin CssLint hook
    REPO=$(pwd)
    CSSLINT_BIN=/usr/bin/csslint


    @@ -86,6 +92,4 @@ if [[ ${EXIT_CODE} -ne 0 ]]; then
    echo "Problems were found"
    echo "Commit aborted."
    exit ${EXIT_CODE}
    fi

    exec git diff-index --check --cached $against --
    fi
  4. @xbx xbx revised this gist Dec 29, 2011. 1 changed file with 26 additions and 6 deletions.
    32 changes: 26 additions & 6 deletions gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -43,29 +43,49 @@ then
    exit 1
    fi

    ## Common
    EXIT_CODE=0

    ## Begin JsHint hook
    # A pre-commit hook for git to lint JavaScript files with jshint
    # @see https://github.com/jshint/jshint/

    REPO=$(pwd)
    JSHINT_BIN=/usr/bin/jshint
    EXIT_CODE=0
    for FILE in `git diff-index --name-only ${against} -- | egrep *.js`; do

    # with jsc:
    ${JSHINT_BIN} ${REPO}/${FILE}

    # could similarly wrap Rhino or Node...

    exit $((${EXIT_CODE} + $?))
    EXIT_CODE=$((${EXIT_CODE} + $?))
    done

    ## End JsHint hook


    ## Begin CssLint hook
    REPO=$(pwd)
    CSSLINT_BIN=/usr/bin/csslint


    ## End CssLint hook
    for FILE in `git diff-index --name-only ${against} -- | egrep *.css`; do

    ${CSSLINT_BIN} ${REPO}/${FILE}

    # could similarly wrap Rhino or Node...

    EXIT_CODE=$((${EXIT_CODE} + $?))
    done

    ## Common
    if [[ ${EXIT_CODE} -ne 0 ]]; then
    echo ""
    echo "JSHint detected syntax problems."
    echo "Problems were found"
    echo "Commit aborted."
    exit ${EXIT_CODE}
    fi

    ## End JsHint hook

    exec git diff-index --check --cached $against --
    exec git diff-index --check --cached $against --
  5. @xbx xbx revised this gist Dec 29, 2011. 2 changed files with 71 additions and 33 deletions.
    33 changes: 0 additions & 33 deletions gistfile1.bash
    Original file line number Diff line number Diff line change
    @@ -1,33 +0,0 @@
    #!/bin/sh
    # A pre-commit hook for git to lint JavaScript files with jshint
    # @see https://github.com/jshint/jshint/

    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

    REPO=$(pwd)
    JSHINT_HOME=${HOME}/src/jshint
    EXIT_CODE=0
    for FILE in `git diff-index --name-only ${against} -- | egrep *.js`; do
    cd ${JSHINT_HOME}

    # with jsc:
    env/ddc-jsc.sh ${REPO}/${FILE}

    # could similarly wrap Rhino or Node...

    EXIT_CODE=$((${EXIT_CODE} + $?))
    done

    if [[ ${EXIT_CODE} -ne 0 ]]; then
    echo ""
    echo "JSHint detected syntax problems."
    echo "Commit aborted."
    fi

    exit $((${EXIT_CODE}))
    71 changes: 71 additions & 0 deletions gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,71 @@
    #!/bin/sh
    #
    # An example hook script to verify what is about to be committed.
    # Called by "git commit" with no arguments. The hook should
    # exit with non-zero status after issuing an appropriate message if
    # it wants to stop the commit.
    #
    # To enable this hook, rename this file to "pre-commit".

    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

    # If you want to allow non-ascii filenames set this variable to true.
    allownonascii=$(git config hooks.allownonascii)

    # Cross platform projects tend to avoid non-ascii filenames; prevent
    # them from being added to the repository. We exploit the fact that the
    # printable range starts at the space character and ends with tilde.
    if [ "$allownonascii" != "true" ] &&
    # Note that the use of brackets around a tr range is ok here, (it's
    # even required, for portability to Solaris 10's /usr/bin/tr), since
    # the square bracket bytes happen to fall in the designated range.
    test "$(git diff --cached --name-only --diff-filter=A -z $against |
    LC_ALL=C tr -d '[ -~]\0')"
    then
    echo "Error: Attempt to add a non-ascii file name."
    echo
    echo "This can cause problems if you want to work"
    echo "with people on other platforms."
    echo
    echo "To be portable it is advisable to rename the file ..."
    echo
    echo "If you know what you are doing you can disable this"
    echo "check using:"
    echo
    echo " git config hooks.allownonascii true"
    echo
    exit 1
    fi

    ## Begin JsHint hook
    # A pre-commit hook for git to lint JavaScript files with jshint
    # @see https://github.com/jshint/jshint/

    REPO=$(pwd)
    JSHINT_BIN=/usr/bin/jshint
    EXIT_CODE=0
    for FILE in `git diff-index --name-only ${against} -- | egrep *.js`; do

    # with jsc:
    ${JSHINT_BIN} ${REPO}/${FILE}

    # could similarly wrap Rhino or Node...

    exit $((${EXIT_CODE} + $?))
    done

    if [[ ${EXIT_CODE} -ne 0 ]]; then
    echo ""
    echo "JSHint detected syntax problems."
    echo "Commit aborted."
    fi

    ## End JsHint hook

    exec git diff-index --check --cached $against --
  6. @founddrama founddrama revised this gist Jun 15, 2011. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions gistfile1.bash
    Original file line number Diff line number Diff line change
    @@ -19,8 +19,7 @@ for FILE in `git diff-index --name-only ${against} -- | egrep *.js`; do
    # with jsc:
    env/ddc-jsc.sh ${REPO}/${FILE}

    # with rhino:
    # env/ddc-rhino.sh ${REPO}/${FILE}
    # could similarly wrap Rhino or Node...

    EXIT_CODE=$((${EXIT_CODE} + $?))
    done
  7. @founddrama founddrama revised this gist Jun 8, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.bash
    Original file line number Diff line number Diff line change
    @@ -27,7 +27,7 @@ done

    if [[ ${EXIT_CODE} -ne 0 ]]; then
    echo ""
    echo "JSHint detected syntax problems with ${EXIT_CODE} file(s)."
    echo "JSHint detected syntax problems."
    echo "Commit aborted."
    fi

  8. @founddrama founddrama revised this gist Jun 8, 2011. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion gistfile1.bash
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    #!/bin/sh
    # A pre-commit hook to lint JS files w/ jshint
    # A pre-commit hook for git to lint JavaScript files with jshint
    # @see https://github.com/jshint/jshint/

    if git rev-parse --verify HEAD >/dev/null 2>&1
    then
  9. @founddrama founddrama created this gist Jun 8, 2011.
    33 changes: 33 additions & 0 deletions gistfile1.bash
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    #!/bin/sh
    # A pre-commit hook to lint JS files w/ jshint

    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

    REPO=$(pwd)
    JSHINT_HOME=${HOME}/src/jshint
    EXIT_CODE=0
    for FILE in `git diff-index --name-only ${against} -- | egrep *.js`; do
    cd ${JSHINT_HOME}

    # with jsc:
    env/ddc-jsc.sh ${REPO}/${FILE}

    # with rhino:
    # env/ddc-rhino.sh ${REPO}/${FILE}

    EXIT_CODE=$((${EXIT_CODE} + $?))
    done

    if [[ ${EXIT_CODE} -ne 0 ]]; then
    echo ""
    echo "JSHint detected syntax problems with ${EXIT_CODE} file(s)."
    echo "Commit aborted."
    fi

    exit $((${EXIT_CODE}))