Skip to content
Ruby API for Mercurial DVCS.
Find file
Pull request Compare This branch is 40 commits behind isabanin:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



Ruby API for Mercurial DVCS. Uses command line interface to communicate with Mercurial repositories.


Please refer to YARD documentation here:

Github doesn't support some YARd-specific syntax so this README can look broken.


gem install mercurial-ruby


Tested with Mercurial versions 1.9, 1.9.1 and 2.1; Ruby version 1.8.7.


There are several settings you can configure. Do it like this:

Mercurial.configure do |conf|
  conf.hg_binary_path = "/usr/bin/hg"

See {Mercurial::Configuration Configuration} class for details.


All actions are performed through {Mercurial::Repository Repository} object. So before you can start doing anything you need to initialize one. Either by creating a new repository:

repository = Mercurial::Repository.create("/path/to/new_repository")

or opening an existing one:

repository ="/path/to/existing_repository")

Now feel free to invoke various methods to get changesets, branches, nodes, etc:

repository.commits.by_hash_ids('291a498f04e9', '63f70b2314ed')

See Features section below for a full list of entities and their methods.


Mercurial Entities

  • {Mercurial::Repository Repository}

  • {Mercurial::ConfigFile .hgrc} — hooks and various settings

  • {Mercurial::Commit Commits}

  • {Mercurial::Node Nodes} — files and directories

  • {Mercurial::Branch Branches}

  • {Mercurial::Tag Tags}

  • {Mercurial::Diff Diffs}

  • {Mercurial::Blame Blame}

  • {Mercurial::Manifest Manifest}

  • {Mercurial::FileIndex File Index}

Custom Commands

You can use {Mercurial::Shell Shell} class to execute custom shell commands that weren't added to the gem as first-class citizens yet.

Built-in Caching

There's a simple caching mechanism built into the gem. If you pass Rails CacheStore compatible caching store to the Configuration block, mercurial-ruby will cache output of all hg commands it's executing. Then if you execute same method again and it will run the same command, the gem will return the output from cache.

Here's how you configure it:

Mercurial.configure do |conf|
  conf.cache_store = Rails.cache

The gem is using a single method of the CacheStore called fetch. Cache expires automatically when repository's mtime changes, and it's your job to update it.

Built-in Timeouts

You can provide a timeout for pretty much any command you are running. Do it like this:

repository.commits.all(:timeout => 5)

Contributing to mercurial-ruby

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet

  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it

  • Fork the project

  • Start a feature/bugfix branch

  • Commit and push until you are happy with your contribution

  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.

  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.


Copyright © 2012 Ilya Sabanin. See LICENSE.txt for further details.

Something went wrong with that request. Please try again.