Is there a way to execute shell script within git log pretty format?

Viewed 304

I have a bash function that gives me some relevant info based on a commit id. The usage would be

$ commit_info <commit-hash>
> Commit Hash: 074cda8
> Info: Some text

I want this info to show up when doing a git log. Ideally something like:

git log origin/master^..HEAD --graph --pretty=format:'commit: %C, Author: %an, commit info: <commit_info %h>

would then show the commit info for each commit within the git log.

2 Answers

A bash 1-liner could pull it off

git log --pretty=%h blahblah | while read rev; do
    commit_info $rev
done

Or if your script handles reading multiple revisions at once:

git log --pretty=%h blahblah | xargs commit_info

Do it the other way around — run through commits, execute the shell function, then format output:

git rev-list origin/master^..HEAD |
    while read sha1; do
        git --no-pager show -s \
            --pretty="commit: %H, Author: %an, commit info: `commit_info $sha1`" $sha1
    done
Related