Created
December 2, 2014 10:59
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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: | |
# [](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