Skip to content

Instantly share code, notes, and snippets.

@lightningdb
Created April 6, 2012 23:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lightningdb/2324137 to your computer and use it in GitHub Desktop.
Save lightningdb/2324137 to your computer and use it in GitHub Desktop.
Publish documentation to directory reflecting tag or branch in gh-pages branch
#!/bin/sh
# get current branch and tag
branch=`git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3`;
tag=`git describe --tags`;
# if current tag has annotations showing number of commits since tagging, then use current branch
destination="$tag"
if [[ "$tag" == *-* ]]
then
echo "extra commits since last tag!";
destination="$branch"
fi
# source and destination will be same, separate variables for clarity
src_tag_or_branch=$destination
echo "destination: $destination"
# then git checkout gh-pages and go to top level dir
git checkout gh-pages && cd $(git rev-parse --show-toplevel)
# then mkdir for current branch or tag
mkdir -p $destination
# then copy doc files to current branch under a directory for current tag/branch
git archive --format=tar --prefix=$destination/ $src_tag_or_branch:docs | tar -xf -
# then commit new docs with message
git add .
git commit -m "updated docs from $src_tag_or_branch for $destination"
# return to original branch
git checkout $branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment