Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

executable file 46 lines (36 sloc) 1.302 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
#!/bin/bash
# determine the project root
output="branches"
index_page="$output/index.html"

function log {
  echo "[branches preview] $1"
}

# Make the output directory if it doesnt exist
mkdir -p "$output"

branches=$(git ls-remote --heads origin | cut -f2 -s | sed 's@refs/heads/@@')

log "fetching to get new branches"
git fetch origin

echo "<html><head><title>jQm Branches Preview</title></head><body>" > "$index_page"
echo "<h1>jQuery Mobile Branches Live Previews</h1><hr />" >> "$index_page"
echo "<span class='date'>Updated: $(date)</span>" >> "$index_page"
echo "<ul>" >> "$index_page"
# Loop through the array to export each branch
for branch in $branches; do
  # skip master
  if [ $branch = "master" ]; then
    continue
  fi

  # TODO shell escape the $branch value it safe for executing
  log "archiving ref $branch"
  git archive -o "$output/$branch.tar" "origin/$branch"
  mkdir -p "$output/$branch"

  log "untarring $branch.tar into $output/$branch/"
  tar -C "$output/$branch" -xf "$output/$branch.tar"

  # Manipulate the commit message
  # TODO add commit and description
  echo "<li>Branch: <a href='$branch/index.html'>$branch</a></li>" >> "$index_page"
done

# close out the list
echo "</ul>" >> "$index_page"

# close out the index file
echo "</body></html>" >> "$index_page"
Something went wrong with that request. Please try again.