Presentation for Triangle Drupal User's Group on March 17, 2010. Includes discussion of why version control is a good idea, how to deal with special Drupal issues (updating modules, core) and how to set up your file structure.
5. Why am I getting a white screen of death?
• Version control lets you see what the most recent code change was on your
site.
6. Can I get rid of that white screen of death?
• Version control lets you roll back to a previous version.
7. My client decided that they prefer a way earlier
version of my module
• Version control lets you roll back a specific file to any point in time (when it
was under version control).
8. I really want to use this new module but I'm afraid
it's going to destroy my site.
• Using version control, you can maintain multiple versions of your code. For
example, you can create a sandbox (“trunk”) just for testing out experimental
modules.
9. My co-worker and I are editing the same page.
What if we overwrite one another?
• Version control lets you merge changes when conflicts arise.
10. Why the heck did I make this change last year?
• Version control lets you record log messages over time so that you can
communicate with your old self.
11. Who was the last person to touch this module?
• Version control lets to see the last person who edited a file.
12. I want to quickly deploy my code on a new server.
• Version control makes it easy to quickly grab a repository and put in on your
local computer or a new server.
13. I'm sick of copying files from my computer to the
server.
• Using “hooks” you can set up you server to automatically reflect a new
change to your site made on your local computer.
14. What Does Version Control Look Like In Practice?
• Example: Association for the Advancement of Sustainability in Higher
Education
• Version Control System: Subversion
15. How is AASHE’s repository set up?
• Trunk: the latest, least stable version of our code
• Branch: the working version of code, very similar to live code
• Tags: each new version of the site is tagged
16. What does this look like when we are coding?
• If we are testing out new modules or major upgrades, we work in trunk first.
• Commits to trunk show up at dev.aashe.org
• If we are fixing bugs or updating code, we work in the current branch first.
• Commits to the current branch show up at stage.aashe.org
• We never touch the releases, we just create a new one when the branch code
is tested.
• We have a release script for making a new release.
17. What does the release script do?
• Creates the next tag.
svn copy file://$path/www/branches/branch-3.0/ file://$path/www/releases/release-$release -m "$commit"
• Creates an export of the branch repository.
svn export --force file://$path/www/releases/release-$release /var/www/aashe.org/releases/release-$release
• Creates a symlink from the public folder to the new release.
rm /var/www/aashe.org/public
ln -s /var/www/aashe.org/releases/release-$release /var/www/aashe.org/public
• Creates symlinks to the file directories (explanation to follow)
18. What are some version control hurdles specific to
Drupal?
19. Updating Modules
• We use drush to update Drupal modules locally, then commit to the staging
site (unless it’s Views or CCK, then trunk)
• drush is a command line shell and Unix scripting interface for Drupal, a
veritable Swiss Army knife designed to make life easier for those of us who
spend some of our working hours hacking away at the command prompt.
drush up mymodulename
20. Updating Core
• We download the version of Drupal we are using from Drupal.org and the
latest version, unzip them, and create a patch file using the diff command
wget http://ftp.drupal.org/files/projects/drupal-6.16.tar.gz
tar -xzf drupal-6.16.tar.gz
wget http://ftp.drupal.org/files/projects/drupal-6.15.tar.gz
tar -xzf drupal-6.15.tar.gz
diff -Naur drupal-6.15 drupal-6.16 > drupal-current-to-drupal-latest.patch
• Next, we test to see if there are any conflicts by doing a dry run from the root
Drupal directory
patch -p1 --dry-run < drupal-current-to-drupal-latest.patch
• Last, we apply the patch file for real from the root directory
patch -p1 < drupal-current-to-drupal-latest.patch
21. Preventing Files From Being Accidentally Deleted
or Versioned
• We store our files at the same level as our public directory and create a
symlink to it
• Our release script rebuilds these symlinks each time there is a new release
ln -s /var/www/aashe.org/files /var/www/aashe.org/public/files
ln -s /var/www/aashe.org/documents /var/www/aashe.org/public/documents
22. Next Steps
• Pick your favorite version control system
• Research your version control system of choice
• If you don’t want to mess with the command-line, look for a GUI tool like
TortiseSVN, Versions, SvnX, or a code editor like Eclipse, Textmate
• Decide on your repository structure
• Start writing versioned code