Note that there are some explanatory texts on larger screens.

plurals
  1. POGit for Websites / post-receive / Separation of Test and Production Sites
    primarykey
    data
    text
    <p>I'm using Git to manage my website's source code and deployment, and currently have the test and live sites running on the same box. Following this resource <a href="http://toroid.org/ams/git-website-howto" rel="nofollow noreferrer">http://toroid.org/ams/git-website-howto</a> originally, I came up with the following post-receive hook script to differentiate between pushes to my live site and pushes to my test site:</p> <pre><code>while read ref do #echo "Ref updated:" #echo $ref -- would print something like example at top of file result=`echo $ref | gawk -F' ' '{ print $3 }'` if [ $result != "" ]; then echo "Branch found: " echo $result case $result in refs/heads/master ) git --work-tree=c:/temp/BLAH checkout -f master echo "Updated master" ;; refs/heads/testbranch ) git --work-tree=c:/temp/BLAH2 checkout -f testbranch echo "Updated testbranch" ;; * ) echo "No update known for $result" ;; esac fi done echo "Post-receive updates complete" </code></pre> <p>However, I have doubts that this is actually safe :) I'm by no means a Git expert, but I am guessing that Git probably keeps track of the current checked-out branch head, and this approach probably has the potential to confuse it to no end. </p> <p>So a few questions:</p> <ol> <li><p>IS this safe?</p></li> <li><p>Would a better approach be to have my base repository be the test site repository (with corresponding working directory), and then have that repository push changes to a new live site repository, which has a corresponding working directory to the live site base? This would also allow me to move the production to a different server and keep the deployment chain intact.</p></li> <li><p>Is there something I'm missing? Is there a different, clean way to differentiate between test and production deployments when using Git for managing websites?</p></li> </ol> <p>As an additional note in light of Vi's answer, is there a good way to do this that would handle deletions without mucking with the file system much?</p> <p>Thank you, -Walt</p> <p>PS - The script I came up with for the multiple repos (and am using unless I hear better) is as follows:</p> <pre><code>sitename=`basename \`pwd\`` while read ref do #echo "Ref updated:" #echo $ref -- would print something like example at top of file result=`echo $ref | gawk -F' ' '{ print $3 }'` if [ $result != "" ]; then echo "Branch found: " echo $result case $result in refs/heads/master ) git checkout -q -f master if [ $? -eq 0 ]; then echo "Test Site checked out properly" else echo "Failed to checkout test site!" fi ;; refs/heads/live-site ) git push -q ../Live/$sitename live-site:master if [ $? -eq 0 ]; then echo "Live Site received updates properly" else echo "Failed to push updates to Live Site" fi ;; * ) echo "No update known for $result" ;; esac fi done echo "Post-receive updates complete" </code></pre> <p>And then the repo in ../Live/$sitename (these are "bare" repos with working trees added after init) has the basic post-receive:</p> <pre><code>git checkout -f if [ $? -eq 0 ]; then echo "Live site `basename \`pwd\`` checked out successfully" else echo "Live site failed to checkout" fi </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload