digout
digout

Reputation: 4252

Using a Git hook to create a commit log and add to the current commit

I'm running this shell script whenever I do a git commit -m "msg" which writes the commit log to a php file. I want it to include the current commit message as well that I am doing at that time.

My shell script:

#!/bin/sh
path="path/to/gitlog.php"
echo "<?php $git_log = array(" > $path
git log --date=iso --pretty=format:'array("%h","%an","%ad","%s"),' >> $path
echo ");" >> $path

The gitlog.php gets saved to my repository, which I will then git push.

I currently have it in 'pre-commit' hook, is there a way to get the committing message within this hook?

My use case

I am the only developer in the project. Time is short! it's for others who are involved in the project to see progress and read the descriptive commit logs without the overhead of me having to double up. The log is output to a dashboard that everyone has access to.

Git is not running on the dashboard server, and files are deployed from a repository hosting company (Beanstalk)

Upvotes: 7

Views: 1311

Answers (2)

Penguin Brian
Penguin Brian

Reputation: 2131

Another option could be to create an appropriate hook that writes the changelog to a file outside your repo, and then pushes the file to somewhere accessible by external users. No need to commit the changelog then, which is the cause of problems.

Upvotes: 1

LeGEC
LeGEC

Reputation: 51820

Given your use case, I would suggest :
move your pre-commit hook on your local machine to the post-checkout hook on the dashboard server (I imagine there is a clone of the repo behind that dashboard site ?)

Upvotes: 0

Related Questions