Skip to content

Instantly share code, notes, and snippets.

@lepffm
Last active October 25, 2017 12:52
Show Gist options
  • Save lepffm/759a3eb64646e7231939c3c43ee3ca7c to your computer and use it in GitHub Desktop.
Save lepffm/759a3eb64646e7231939c3c43ee3ca7c to your computer and use it in GitHub Desktop.
git pre-push hook script for windows
@echo off
@rem init script for git pre-hook ( run findbugs )
@rem writer xxx@xxx.com
@rem check git hook available ( for eclipse )
set CYG_FILE=cygpath.exe
set HOOK_FILE=".git\hooks\pre-push"
@for %%i in (%CYG_FILE%) do @if NOT "%%~$PATH:i"=="" GOTO WRITE_HOOK
@rem check exist sh.exe from windows PATH
set GIT_FILE=sh.exe
set FOUND=""
@for %%i in (%GIT_FILE%) do @if NOT "%%~$PATH:i"=="" set FOUND=%%~dp$PATH:i\%CYG_FILE%
if %FOUND% =="" (
goto ERR
) ELSE (
IF NOT EXIST %FOUND% (
echo. > %FOUND%
echo [GIT HOOK MAKE DUMMY] create dummy %FOUND% file
)
goto WRITE_HOOK
)
@rem generate pre-post hook script
:WRITE_HOOK
(echo #!/bin/sh^
# to skip the tests, run with the --no-verify argument^
# i.e. - $ 'git push --no-verify'^
./gradlew findbugsMain -q -a --daemon --offline^
exit $?) > %HOOK_FILE%
echo [GIT HOOK MAKE Finished] see %HOOK_FILE%
goto END
:ERR
echo [GIT HOOK FAIL] please add PATH sh.exe directory or install cygwin
:END
timeout /T 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment