Capistrano, Mercurial and Password Prompts

So I’m using Mercurial for version control on a Ruby on Rails project, along with Capistrano for automating deployment and running remote tasks. These are great tools and I’m finding that they work well together with the Mercurial SCM module by Matthew Elder introduced in Cap 2.0.

I came across one problem though: my repository is hosted over HTTP because I don’t want to give everyone access to a shell account for SSH, and the hg SCM module didn’t support prompting for passwords (whether you’re using HTTP authentication or SSH without a public key). This effectively meant that if you wanted Cap to deploy from a repo served in either of these ways, you’d need to put your password in plain text in your Cap recipes.

I don’t like the idea of that, so I created a patch to fix it, along with another minor point or two that I found, and added some unit tests. You can get more details and take a look at the patch on the ticket I submitted. It’s been committed, so if you’re using Capistrano from SVN, you’re set, just svn up.

If you’ve installed Cap from a gem and want a quick fix, you can replace mercurial.rb in your installation with the one attached to this post. On my system, it lives at this directory path:

/usr/local/lib/ruby/gems/1.8/gems/capistrano-2.1.0/lib/capistrano/recipes/deploy/scm/

This will probably work with Cap 2.0, though I’ve only tried with 2.1. The Mercurial module hasn’t changed much.

I should note that on my systems I’ve had to set the option for requesting pseudo-ttys in my recipes, or else Mercurial tries to run non-interactively and password prompting won’t work. If you have that problem, use this:

default_run_options[:pty] = true

If anyone comes up with a nice way to load the new stuff as a monkeypatch in a project, I’d love to hear about it. I’ve been unsuccessful at trying to hook it in through recipes or the Capfile, and it’d be nice to have some way of doing that while waiting for the next gem release. I’d rather not ask my team to check out Capistrano from SVN or run around modifying their installation if I can avoid it.

Update:
And, in short order, Cap 2.2.0 has been released. The fix below is rolled in, so just gem install capistrano and you can forget about the rest!

AttachmentSize
mercurial.rb4.57 KB