Skip to content

Instantly share code, notes, and snippets.

@defagos
Created December 2, 2014 10:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save defagos/267d3b8b30604fac541f to your computer and use it in GitHub Desktop.
Save defagos/267d3b8b30604fac541f to your computer and use it in GitHub Desktop.
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