Here's Agaric's workflow (ignore the lack of a link to Drush's path, we have too many Drupal installations to make that practical at the moment):

cd /var/www/drupal-5_3-live/sites/all/modules/
sudo php drush/drush.php -l http://example.com pm install fasttoggle
sudo svn add fasttoggle
sudo svn commit -m "Installed fasttoggle via Drush"

Drush has me expecting to be able to wave my hand in the general direction of the keyboard and get what I want.

So the above is just too much typing!

So the immediate support question is: should I go about scripting it inside Drush, or outside Drush?

Could/should post pm install actions be added to Drush, or is the best approach a Bash script that wraps around Drush (and has a delay before svn add? Hmm.)

Thanks!

benjamin, Agaric Design Collective

Comments

moshe weitzman’s picture

thats my workflow too. i'd like to see this in drush. i'm not sure how best to implement it. maybe a post hook a you suggest. i guess that hook could run for all drush commands, not just pm install.

mlncn’s picture

Assigned: Unassigned » mlncn
Priority: Minor » Normal

It gets more complicated when you update...

As far as I can tell, the only way get your updated module into subversion is to delete the original and svn add the updated version.

Please correct me if I'm wrong, but if this is the case, for people keeping their local checkouts of Drupal modules under SVN:

pm update will need to be followed by a script that sees what has changed, and then runs a script like this (called as drush_update_svn module1 module2 moduel3 etc.).

#!/bin/sh -e
# $Id$

if [ $# -lt 1 ]; then
  echo "Usage: $0 module_directory (optional additional directories)"
  exit 1
fi

# adapted from http://svn.haxx.se/users/archive-2006-07/0774.shtml

for (( i = 1 ; i <= $#; i++ ))
do
  mv $i $i.new
done
svn up
for (( i = 1 ; i <= $#; i++ ))
do
  svn remove $i
done
svn ci -m "delete the old, obsoleted by a drush update"
for (( i = 1 ; i <= $#; i++ ))
do
  mv $i.new $i
  svn add $i
done
svn ci -m "check in the new"

Could/should all this (with the addition, first, of a post hook to Drush) be rolled up into a Drush sub-module?

moshe weitzman’s picture

at a high level, thats what is needed. but i don't think that we need to svn remove files that are staying in the repository. we only need to remove those that are no longer in the directory. similarly, we need to discover newly added files and svn add them. there are some scripts out there for this from which we might learn. for example, see http://piston.rubyforge.org/.

moshe weitzman’s picture

if it gets too complicated, i guess we could only hook into pm install for now and leave pm update for later.

moshe weitzman’s picture

here is a great blog post which details usage of svn_load_dirs.pl. That script ships with svn and really helps handle changes like this. see http://www.burtonini.com/blog/computers/svn-vendor-2005-05-04-13-55

ukdg_phil’s picture

Hi, I've just discovered the wonders of drush & the pm install feature!

Just wondered on the svn setup you guys are using, as I currently use svn:externals to add drupal modules to sites, so theres only one copy of the module code in the svn repos.

I take it doing things the way you show benjamin, each site in your repository has its own copy of the contrib module? Don't see much of an issue with that, seeing how easy drush makes adding & instaling modules now! Just wanted to see how others do things before I start using drush in my daily workflow : )

Thanks,
Phil

moshe weitzman’s picture

I keep each project in separate svn repository and same for Contrib. No svn:externals for me and my clients. Folks who like svn:externals might be interested in the repos at http://svn.advantagelabs.com

ukdg_phil’s picture

Cheers Moche, will try & take a look at that link when I get a spare mo.

Although I'm starting to think I might ditch svn:externals, as it can complicate things alittle, and instead go for a similar setup to you guys.

Back to the original post, when doing an update on a module already in your svn repos, would the workflow go like this?

cd /var/www/drupal-5_3-live/sites/all/modules/
sudo php drush/drush.php -l http://example.com pm update fasttoggle
sudo svn_load_dirs.pl.....
> resolve any conflicts manually? <
sudo svn commit -m "Updated fasttoggle via Drush"

moshe weitzman’s picture

yes, thats the idea. perhaps someone could try this out and see how well it works. then we'll talk about how smart drush should get about this workflow.

moshe weitzman’s picture

A drupal specific tutorial including svn-load-dirs: http://www.davidgrant.ca/maintaining_vendor_sources_with_subversion

owen barton’s picture

Another option, that seems quite a bit simpler (especially if we want to implement in PHP!) is http://gael-varoquaux.info/computers/svnautocommit/#the-autocommit-script - this does what is described above - reading the output of svn stat, and adding/deleting the files as appropriate.

owen barton’s picture

Version: » 5.x-1.x-dev
Assigned: mlncn » Unassigned
Category: support » feature
Status: Active » Needs review
StatusFileSize
new5.77 KB

..and a patch...

I have moved all subversion integration out of the main drush_pm module, and into a drush_pm_svn module (yay!). There is now a hook to suppress backups, and another more general one after the install/update of each project, which should be useful for lots of things. I have added a simple static get/set function to store the output of the last exec (this is somewhat the same style as used by perl, IIRC) - which seemed neater and easier than returning a whole array of the return value plus the output. We need this to parse svn stat output, but it is also handy for presenting more helpful error messages (we should apply this approach to the handler modules too, I think).

Everything else is pretty much self explanatory. I have added lots of error checking and messages. I didn't go for drush_die, since none of these really seem 'fatal' to me, however I am open to suggestions otherwise! This needs testing with the wget handler (I tested quite a lot with cvs though), and perhaps a good read through the documentation and error messages.

moshe weitzman’s picture

Status: Needs review » Needs work

Nice work!

* Need some Doxygen for drush_shell_exec_output_set()
* Personally I find it easier to work with XML output than regexing out info. See `svn stat --xml` for an example. Not a big deal I suppose.
* Does it make sense to implement the backup step as a 'pre' operation of pm update?
* Instead of implementing pre/post hooks that are specific to install and update, why not add these for all commands. Maybe in drush_dispatch(). That function seems to support multiple commands in one drush call but I have never tried that.
* I suspect some implementations will want to pass in subversion credentials in this call. We should document how to do that in the help for the commands and/or in example.drushrc.php
* Some support for DRUSH_SIMULATE mode would be very handy here.

-moshe

owen barton’s picture

StatusFileSize
new9.16 KB

Need some Doxygen for drush_shell_exec_output_set()

Added.

Personally I find it easier to work with XML output than regexing out info. See `svn stat --xml` for an example. Not a big deal I suppose.

I agree here - I think it might be best to add this to the D6 version though, since we have PHP5 and hence SimpleXML, and keep the D5 version PHP4 compatible.

Does it make sense to implement the backup step as a 'pre' operation of pm update?

I thought about that, but we still need some way for other modules to overrule the backups. The only other things I can think of seem more complex or fragile.

Instead of implementing pre/post hooks that are specific to install and update, why not add these for all commands. Maybe in drush_dispatch(). That function seems to support multiple commands in one drush call but I have never tried that.

This is a great idea, and should be easy to implement. However I think this is a different patch because neither of these would really help us here - skip_backup needs to know the source of the module to check for .svn directories and drush_pm_post_update should only be run after a successful install (not just after the completion of the command). Also each of them should be run for each project, not once per command.

I suspect some implementations will want to pass in subversion credentials in this call. We should document how to do that in the help for the commands and/or in example.drushrc.php

I have added these, which I think could be useful (although only occasionally), we need a separate parameter for each command because different svn commands accept different parameters (and throw errors if they get one they don't expect).

Some support for DRUSH_SIMULATE mode would be very handy here.

It already works in simulation mode by not actually running the shell command. Not sure what else we would do in simulation mode - svn has a --dry-run option, but only for merge (which we aren't using).

owen barton’s picture

and a HEAD patch (could use a test)

owen barton’s picture

StatusFileSize
new10.03 KB

and a tweaked D5 patch

owen barton’s picture

Status: Needs work » Needs review
StatusFileSize
new10.03 KB

and a tweaked D5 patch

owen barton’s picture

StatusFileSize
new10.01 KB

Forgot the HEAD patch (end of day...)

moshe weitzman’s picture

Status: Needs review » Fixed

Committed! This was nicely done. Thanks Grugnog2.

I think that svncommit should imply svnsync. This saves typing.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.