Git and mercurial abort: revision cannot be pushed

I’ve been migrating some repositories from Mercurial to Git; as part of this migration process some users want to keep using Mercurial locally until they have time to learn git.

First install the hg-git tools; for example on Ubuntu:

sudo aptitude install python-setuptools python-dev
sudo easy_install hg-git

Make sure the following is in your ~/.hgrc:

[extensions]
hgext.bookmarks =
hggit = 

Then, in your existing mercurial repository, add a new remote that points to the git repository. For example for a BitBucket repository:

cd <mercurial repository>
cat .hg/hgrc
[paths]
# the original hg repository
default = https://username@abcde.org/foo/barhg
# the git version (on BitBucket in this case)
bbgit   = git+ssh://git@bitbucket.org:foo/bar.git

Then you can go an hg push bbgit to push from your local hg repository to the remote git repository.

mercurial abort: revision cannot be pushed

You may get the error mercurial abort: revision cannot be pushed since it doesn’t have a ref when pushing from hg to git, or you might notice that your hg work isn’t being pushed. The solution here is to reset the hg bookmark for git’s master branch:

hg book -f -r tip master
hg push bbgit

If you find yourself doing this regularly, this small shell function (in your ~/.bashrc) will help:

hggitpush () {
   # $1 is hg remote name in hgrc for repo
   # $2 is branch (defaults to master)
   hg book -f -r tip ${2:-master}
   hg push $1
}

Then from your shell you can run commands like:

hggitpush bbgit dev
hggitpush foogit      # defaults to pushing to master


SaltStack Essential Reading

A list of ‘Essential Reading’ for SaltStack. A collection of useful links, mostly for myself but possibly helpful to others. How Do I Use Salt States,  States tutorial and Pillar Walkthrough – the tutorials Highstate data structure definitions and  Understanding YAML – helpful for understanding […] more…

Setup Arduino on Debian

Some notes on setting up Arduino on Debian. Add yourself to the required groups – dialout and tty. Confirm the port /dev/ttyUSB0 is being used by Arduino – tail messages then plug in the Arduino. Logout and login (or run a login shell). Confirm permissions. […] more…

Split() function for Microsoft MSSQL

Microsoft MSSQL doesn’t have a split() function (like in Ruby, Perl), so here’s one I wrote. It’s different from the other MSSQL split() functions out there on the intertubes in that it accepts a @pos parameter that specifies which split item to return – easier […] more…

MySQL SUBSTRING_INDEX function on Microsoft MSSQL

I’m porting some code from MySQL to Microsoft MSSQL, and unfortunately MSSQL doesn’t have a SUBSTRING_INDEX function. Here’s a version I quickly implemented, called “my_substring_index”. Limitations: only accepts strings up to 255 chars long only works with varchars – we speak ASCII here… more…

Microsoft SQL 2012 SSIS Create Catalog Password

Creating an SSIS Catalogue on Microsoft SQL 2012 seems to have an interface bug – you need to both “enable CLR” and provide an “encryption password”, but the options are mutually exclusive ie when I tried to type in a password, the interface locks the […] more…

Change default editor in Debian

How to change the default editor in Debian (for root), as I keep forgetting: sudo update-alternatives –config editor My ~/.zshrc takes care of this for my personal account, but it’s nice to change root’s settings so a better editor (than nano) comes up when editing […] more…

Next Page »