1

I set up Git's post-receive hook. I would like to run a specific program (for deployment) if the commit message contains a specific word. For an example let's say [publish].

I'm having difficulties finding out how can I capture the commit message in bash and I'm bad with bash.

Pseudocode for post-receive:

#!/bin/bash

if [[ "$commit_message" == *"[publish]"* ]]
    then
        echo "Publishing.."
fi
Badr Hari
  • 8,114
  • 18
  • 67
  • 100
  • @Inian That is my problem. Git generates the commit message, but I don't know how to read it from bash. I'm missing $commit_message variable. – Badr Hari Jan 10 '17 at 11:55
  • The `post-receive` hook doesn't receive the commit messages directly. Instead, it gets lines of the form `old-hash new-hash ref-name`. You have to read these lines, filter for the desired ref-name (e.g. refs/master), then generate the commit messages with e.g. `git log` and filter these messages. In your case, this would be easier if you had a branch called e.g. `deploy` that you only push to if you want to redeploy. Then the filtering is a lot simpler. – Beat Bolli Jan 10 '17 at 12:00

0 Answers0