Skip to content

Instantly share code, notes, and snippets.

@mueschm
Created October 1, 2013 15:32
Show Gist options
  • Save mueschm/6780322 to your computer and use it in GitHub Desktop.
Save mueschm/6780322 to your computer and use it in GitHub Desktop.
Load branches of git repo into seperate folders of website
contains() {
string="$1"
substring="$2"
if test "${string#*$substring}" != "$string"
then
return 0
else
return 1
fi
}
updateBranch() {
fullBranch="$1"
branchName=${fullBranch:15}
echo "Found branch $branchName. Attempting to update."
echo git checkout -b $branchName origin/$branchName
git checkout $branchName
update=`git pull origin $branchName`
numrowsupdate=`echo -e "$branches" | wc -l`
lastlineupdate=`echo -e "$update" | head -$numrowsupdate | tail -1`
if contains "$lastlineupdate" "up-to-date" && [ -d "/var/www/html/$branchName" ]
then
return
fi
echo "Updating branch $branchName on website"
rm -rf /var/www/hhtml/$branchName
echo /var/www/html/$branchName
mkdir /var/www/html/$branchName
cp -r ./* /var/www/html/$branchName
}
while [ 1 ]; do
git fetch origin
branches=`git branch -a`
numrows=`echo -e "$branches" | wc -l`
for i in `seq 2 $numrows`; do
branch=`echo -e "$branches" | head -$i | tail -1`
contains $branch "remotes/origin/" && updateBranch $branch
done
sleep 30
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment