Category: Drush

Drush Make: Avoid the Unexpected

There are two things that are no secret and which form the basis for this post:

  1. Using the development versions of Drupal modules is sometimes the best choice.
  2. Using development versions as the project[module_name][version] parameter in a Drush Make file is always a bad choice.

How can we reconcile these two seemingly irreconcilable truths? The answer is actually very straightforward, and it’s even documented in Drush Make’s README.txt file itself1!

I tweeted a link to this pastebin snippet the other day. Keep that open, and let’s take a closer look.

This example comes directly from a Drush Make file I actually use:

; Download the module with Git
projects[webform_userpoints][download][type] = "git"

; Find this revision by clicking View Commits on the project page
; in the lower right-hand column. Click on the most recent commit
; in the branch you were going to use. Copy and paste the full revision
; identifier.
projects[webform_userpoints][download][revision] = "25bfe11d2c6dc6480d0aabc79b1edb54dec06236"

; Tell Drush Make it's a module. This might not be necessary.
projects[webform_userpoints][type] = "module"

; You can erase or change the subdirectory. I like to separate
; my Git-downloaded modules.
projects[webform_userpoints][subdir] = "_custom"

The comments are there for explanatory purposes, of course. They explain the basics, so let’s look at the finer points. First of all, what was my thinking behind doing it this way? To answer that, take a quick look at the Webform Userpoints module and the available releases. I’ll wait.

OK, as you can see, this module only has a development release. However, I’ve also used this technique for modules where the development version had a feature (or even a bug fix) that I needed. The benefit of doing it this way instead of simply specifying the version as “1.x-dev” is that your site will never suddenly stop working after a Drush Make (or Aegir)-based deployment because of the latest development version having different code than you expect (i.e., new code). Git repository revisions are fixed points in time and code. You can rely on them not changing. This is a very good thing.

Finally, I thought I should include a screenshot of where to find the commit identifier. There are a couple places; let’s start with the one I used the first time:

Click the "View commits" link on a project to get here

That’s the View Commits page for Webform Userpoints. It’s accessible through the right sidebar. You usually want the latest one for the development version you need. Click on it, and then click here to skip ahead.

Sometimes, though, especially in actively-developed projects, you’ll find that there are so many commits that it’s impractical to find the revision that way.  In these cases, the Repository Viewer is the answer. To get there, click Repository Viewer on the Drupal.org project page of the module or theme with which you’re dealing, and then under the heads section, find the one that looks like the development version you wanted. This will typically be something like 6.x-1.x. Next to that, you’ll see a few links such as shortlog, log, and tree. Click log, and then click on the title of the latest commit.

With either approach, this type of page is your final destination:

Once you click a specific commit, you wind up on a page like this

The highlighted text is what you want. This will be different for you unless you’re doing this for the same revision of the same module.

Bonus developer method: Clone the repository with Git and check out the branch corresponding to the development version. Run git log and copy the full commit identifier. Stick it in the right place in the Drush Make file. You probably didn’t even need me to write all this if you’re using this method.

1 http://drupalcode.org/project/drush_make.git/blob/086793e8887008a7841a5ef6081f8cf2766347db:/README.txt#l268

How-to: Create Drupal development sites in Quickstart

Yesterday, I felt like reviewing some patches, so I fired up my Quickstart-based virtual machine and set about creating some Drupal development sites. I realized I first had to create Drush Make files to get the proper development versions installed. So I did that. However, I also realized that, despite cloning the code via Git and checking out a particular branch, the Git clone was not actually a Git repository. This is because Drush Make requires the –working-copy switch in order to do this. I’ve posted a workaround on the Quickstart issue queues. This post mostly serves as pointers to a couple things:

Quick Drush Tip – Import database SQL with drush sql-cli (sqlc)

I discovered something awesome today just on a hunch and wanted to share. I’m not the first one to blog about this, but it isn’t widely mentioned on the ‘net, at least not as far as I can see.

Basically, it’s the drush sql-cli command, or drush sqlc for short. If you type just that, you will be logged into a database shell. Did you know, however, that you can actually import a database this way, much in the way you would with mysql database < database_file.sql? Swap out the mysql stuff and drop in drush sqlc < database_file.sql – and it works! It grabs the DB information from your settings.php file, and magic happens! This was an awesome find for me, and it’s going to save me a decent amount of time in the future.

NOTE: This might be MySQL-only. If a PostgreSQL user could chime in and let me know if it works for that or any other DBMSes, I’d appreciate it!