Git pre-commit hook not running on windows

前端 未结 9 990
盖世英雄少女心
盖世英雄少女心 2021-01-31 08:15

I\'m just starting to look into Git hooks, but I can\'t seem to get them to run.

I set up a local repository, so there is now a \'.git\' directory in my project folder.

9条回答
  •  忘了有多久
    2021-01-31 08:41

    If it helps anyone: I was getting following error:

    error: cannot spawn .git/hooks/pre-commit: No error
    

    Turned out that in my pre-commit file I did not have 'newline' character after last exit command:

    #!/bin/sh
    # From gist at https://gist.github.com/chadmaughan/5889802
    
    # stash any unstaged changes
    git stash -q --keep-index
    
    # run the tests with the gradle wrapper
    ./gradlew test --daemon
    
    # store the last exit code in a variable
    RESULT=$?
    
    # unstash the unstashed changes
    git stash pop -q
    
    # return the './gradlew test' exit code
    exit $RESULT
    # << must have a newline after above command >> 
    

    I was running gradle project on windows and gradle commands in cmder shell and cmd

提交回复
热议问题