Pergunta

I have googled this for an hour now and have yet to find a solution. Is there a way to write a GIT hook that will put the git message from a commit into a SQL Server database on postreceive? What I'd like to do is store a table in my database with all my commits, and much like bitbuckets issue tracker, I would like to close issues in another table if the commit message is something like "close issue #2".

Foi útil?

Solução

If you have a script which knows how to update your sql server database, then it is a matter of writing a post-receive hook which collect the log message for each received commit.

You can take an idea in:

  • "git post-receive hook that grabs commit messages and posts back to URL".
    Extract:

     for revision in `git rev-parse --not $other_branches | git rev-list --stdin $revspec`; do
       # I don't know if you need to url-escape the content
       # Also you may want to transmit the data in a POST request,
       wget "http://server.com/logthis.asp?msg=$(git log $revision~1..$revision)"
     done
    
  • campfire post-receive hook.
    Extract:

    text = `#{GIT} log --all --since='#{revtime}' --reverse`
    
  • "fogbugz-git-integration", which is close to what you are looking for, as it parses the commit message, looking for certain keywords.
    Extract:

    git log $oldrev..$newrev --pretty=format:~~CommitSubject:%s%n~~CommitHash:%H%n~~EOR%n | while read logentry;
      do
        # Parse out the commit subject
        if [ "${logentry:0:15}" == "~~CommitSubject" ]; then
           ...
    
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top