If you have two aliases, @site1.dev and @site2.dev (both named "dev" in their respective files site1.aliases.drushrc.php and site2.aliases.drushrc.php), then any usage of the alias @dev is the merged results of the fields of the unrelated aliases.

This, as you might imagine, can produce phenomenally bad results. The attached patch insures that in these instances, an arbitrary alias of the correct name is returned. All tests still pass.

Comments

greg.1.anderson’s picture

Status: Needs review » Needs work

Removing #hidden was dubious. I'm going to work on this some more.

greg.1.anderson’s picture

Status: Needs work » Needs review
Issue tags: +Needs change record

Here is a patch with better handling of multiple matches than before. If you attempt to use '@dev' when multiple aliases files contain aliases that match that name, you will now get an "ambiguous result" warning followed by a "no alias matched" error. This avoids the rather large problem that can be caused by the current technique of merging unrelated alias records together.

If you wish to operate on multiple aliases, the 'all' groupname can be used; e.g.: drush @all.dev status will display status for all '@dev' aliases. It is also possible to leave off the group name from the alias if drush can infer which group is intended by way of the other aliases used in the same command; e.g.: drush sql-sync @site.live @dev will prefer @site.dev if it can be found.

All tests pass; if the code looks good, I'll update up the docs and add a change notification.

moshe weitzman’s picture

Missing patch.

I'm not too fond of more magic in site alias system like "drush sql-sync @site.live @dev will prefer @site.dev if it can be found.". I think this complicates an already difficult system.

greg.1.anderson’s picture

StatusFileSize
new23.39 KB

Here is the missing patch. I could remove the feature mentioned in #3 if desired, but it is important to replace the current record-merging behavior with something more reasonable. Hopefully most of this patch will be acceptable.

greg.1.anderson’s picture

Status: Needs review » Needs work

I had an idea to make this feature more explicit that would only take a little bit of code to implement.

"@related." === the same group as another alias in use:

drush @site.dev site-alias @related.live === drush site-alias @site.live

drush rsync @site.dev @related.live === drush rsync @site.dev @site.live

To shorten typing this, "@." === "@related.":

drush rsync @site.dev @.live === drush rsync @site.dev @site.live

The main use of this, though, is not the nominal usefulness of reducing typing on the cli, but to make scripts and shell aliases more flexible. For example:

$options['shell-aliases']['pull-data'] = '!drush sql-sync @related.live {{@target}} && drush rsync @related.live:%files {{@target}}:%files'

Usage:

drush @site.dev pull-data

With just a touch more work, {{@target}} could probably become @self. With a few useful examples in drush topic docs-shell-aliases, it wouldn't be too hard for folks to create customized workflows the pull from live or stage or wherever is appropriate for their dev environment.

If this looks good, I'll roll a new patch.

greg.1.anderson’s picture

Status: Needs work » Needs review
StatusFileSize
new23.51 KB

Here is a patch that supports the constructs described #5; it is nearly the same as #4.

moshe weitzman’s picture

Status: Needs review » Needs work

For me, this @related magic is too much. I would personally redefine pull-data on each site that I worked on. I propose that we just fix the bug at hand for now.

greg.1.anderson’s picture

StatusFileSize
new18.53 KB

Here is a fix for multiple match handling that does not add any well-known-groupname magic. All tests pass.

greg.1.anderson’s picture

Status: Needs work » Needs review
moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

Thanks.

greg.1.anderson’s picture

Committed.

greg.1.anderson’s picture

Status: Reviewed & tested by the community » Fixed

Forgot to set status.

Status: Fixed » Closed (fixed)

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

moshe weitzman’s picture