8

I'm starting to use Git to manage Joomla site builds, and I'm looking for some best practice guidance. As it stands:

  • Use WHM to provision a new account. I've written a post-install hook to automatically download Joomla from Github and place it in the relevant public_html directory, as well as create the database and DB user
  • Manually install Joomla via the web interface (though currently looking for a way to automate this as well)
  • Setup a bare repo above public_html - this is where users push and pull from. We'll call this origin
  • Setup a standard repo in public_html
  • Add a Joomla-specific .gitignore
  • Specify the bare repo as our remote (git remote add origin ../repo.git)
  • Perform git add ., then git commit -m"Initial J! Commit", then git push origin master to get the default install in our bare repo
  • Add a post-receive hook to the bare repo to automatically pull changes into the repo in public_html (as the bare repo is where developers will push local changes to)
  • Add a post-update hook to the repo in public_html in case anyone makes changes on the server... though they shouldn't

I'm not too worried about databases at the moment. My main issue now is dealing with Joomla file additions / changes. Obviously as I install templates and extensions certain files are going to be added and removed. Similarly Joomla updates will cause changes.

What is the best way to deal with these on-server changes? I was thinking of writing a small plugin that runs onAfterRender or similar that uses PHPGit to perform git add ., git commit git push origin master. Then, in my local copy, I can just do a pull and everything comes through. Or is there a better way?

4

I don't understand why you set up the bare / public structure;

I only use the public_html as the root of the repo, with a very complete .gitignore (which needs to be updated after each new Joomla! update, with git status you find the new files and add them so they don't get versioned).

Developers push to development branches; in the end when a release is approved it's rebased against the master, tested and pushed to production.

I don't use hooks but have a couple of scripts that dump the relevant database parts I wish to share, but leave it to the user to run the import scripts if they want; this way if someone is working on a new extension, they will keep their configuration until they're ready to share.

If you use less / sass you might want to run the compile in the post-commit-hooks to ensure the compression flags are always on on the server.

-- update: .gitignore --

I cannot share my .gitignore here as it's subject to change with every Joomla! update. First of all, ensure your eclipse .project .settings etc and other files you wish to exclude are in a master .gitignore along with configuration.php and .htaccess. My master .gitignore looks like this for a site with nasty components that write changes to their own folders instead of cache and tmp; plus it uses sass:

*/.sass-cache
/components/com_sobipro/var/cache/*
/components/com_djclassifieds/images/*
/components/com_sobipro/tmp/*
/components/com_sobipro/var/*
/log
/._db.sql
/logs
/stats
/components/com_sobipro/tmp/edit/*
/.buildpath
/.project
/.settings
/.htaccess
/images/icons/*
/images/photos/*
/images/sobipro/*
/images/classifieds/*
/administrator/cache/*
/tmp/*
/configuration.php
/index.php
/joomla.xml
*.txt

so I start off by copying it ( from the web root):

cp /home/_core/.gitignore .

Then explode the update pack (the full update package) and there run

find | sed "s/^\.//"  >> /home/yoursitefolder/public_html/.gitignore

WARNING do not run the find on the live site, just on the update package!

Do run a couple of tests and see with git status what will be added each time before you finalize the procedure and write bash scripts for it: this is what I'm using but it is not guaranteed that it will fit your requirements 100%

  • Thanks for your answer - would you be willing to make public your .gitignore? Currently I'm the only developer and I'm fairly new to Git so I was following some web dev workflow guidance online to get me where I am, leading to the bare / public structure. – codinghands Oct 13 '14 at 8:35
  • No I won't paste it here; I just added directions for creating it – Riccardo Zorn Oct 13 '14 at 12:54
  • Hi Riccardo - thank you, I already have a fairly complete .gitignore, just wanted to see any differences. – codinghands Oct 13 '14 at 13:52
  • You can ignore folders globally, example: to ignore cache folders everywhere, just add cache/ to your .gitignore – jackJoe Mar 19 '15 at 18:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.