Skip to content

Instantly share code, notes, and snippets.

@defagos
Created December 2, 2014 10:59
Embed
What would you like to do?
git commit hook ensuring the correct branch URL is set for Travis badges found in README files. Install both as post-commit and post-merge hooks
#!/bin/sh
# Repository settings
REPOSITORY_NAME="YourRepositoryName"
README_FILE_NAME="README.markdown"
# Update a Travis badge URL found in the README to keep it in sync with the branch name
# Badge example:
# [![Build Status](https://img.shields.io/travis/$USER_NAME/$REPOSITORY_NAME/master.svg?style=flat)](https://travis-ci.org/$USER_NAME/$REPOSITORY_NAME)
branch_name=`git symbolic-ref --short HEAD`
sed -E -i "" "s|(^.*https://img.shields.io/travis.*/$REPOSITORY_NAME/).*(\.svg.*$)|\1$branch_name\2|g" "$README_FILE_NAME"
git add "$README_FILE_NAME"
git commit -m "Update Travis badge for branch $branch_name"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment