
git diff --name-only --diff-filter=[AMCR] $2 $3  #!/bin/sh ex=0 okResult="OK" originalPath='/git/test.git/' #   git printf "---- 'Sql checker' hook ----" listOfFiles=$(git diff --name-only --diff-filter=[AMCR] $2 $3) #   for changedFile in $listOfFiles do printf "checking:$changedFile" fullFilePath="$3:$changedFile" git-show $fullFilePath >tmp_sql result=$($originalPath/hooks/check-sql tmp_sql) #  if [ "$result" != $okResult ] then res=${result//|/\\n } printf " $res\n" #  ex=1 else printf "ok!\n" fi done printf "---- Done ----" exit $ex  #!/bin/sh soap-template $1 tmp_soap wget -qO- --post-file=tmp_soap --header="Content-type: text/xml; charset=utf-8" 127.0.0.1/check-sql.asmx | gawk -v re="<CheckFileResult.*>(.*)/CheckFileResult>" '{match($0,re,RMATCH); print RMATCH[1]}'  #!/bin/sh encodedFile=$(base64 $1) echo '<?xml version="1.0" encoding="utf-8"?>' >$2 echo '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSc ma" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' >> $2 echo ' <soap:Body>' >>$2 echo ' <CheckFile xmlns="http://tempuri.org/">' >>$2 echo " <base64>$encodedFile</base64>" >>$2 echo ' </CheckFile>' >>$2 echo ' </soap:Body>' >>$2 echo '</soap:Envelope>' >>$2  [WebMethod] public string CheckFile(string base64) { var errors = new List<SqlCheckError>(); string result = OkResult; try { //  sql- string sqlScript = Encoding.Default.GetString(Convert.FromBase64String(base64)); //    ISqlCheck var containerProvider = new SqlCheckUnityProvider(); //    var checker = new SqlCheckProcess(containerProvider); errors.AddRange(checker.CheckSql(sqlScript)); } catch (Exception e) { Log(e); // return OkResult; //      ,       . } //  ( )     git-hook if (errors.Count > 0) { result = string.Join("|", errors.Select(error => string.Format("{1}: {0}", error.Message, error.Type))); } return result; }  public interface ISqlCheck { bool CheckSql(string sqlCode); SqlCheckError GetError(string sqlCode); }  $ git push origin master Counting objects: 7, done. Delta compression using up to 8 threads. Compressing objects: 100% (3/3), done. Writing objects: 100% (4/4), 347 bytes, done. Total 4 (delta 2), reused 0 (delta 0) remote: remote: ---- 'Sql checker' hook ---- remote: remote: checking: test/create_sp.sql remote: Error: Missed 'GO' statement after stored procedure. remote: remote: ---- Done ---- remote: remote: error: hook declined to update refs/heads/master To ssh://user@git.local/git/test.git ! [remote rejected] master -> master (hook declined) error: failed to push some refs to 'ssh://user@git.local/git/test.git' Source: https://habr.com/ru/post/205888/
All Articles