Fake "hg rebase" implementation


After doing two merges in Mercurial when I couldn’t push my changes due to totally unrelated changes in the remote repository, I noticed that mq works great but having a fully automated solution instead of running several commands manually would be desirable. So I whipped up a short script that basically does what “hg rebase” would do:


my $revisions = `hg outgoing --template '{rev}\n'`;
my $first = 0;
my $last = 0;
while ($revisions =~ /^(\d+)$/gm)
  $first = $1 unless $first;
  $last = $1;
die "No outgoing changes\n" unless $first;

system("hg qimport -r $first:$last") && exit(1);
system("hg qpop -a") && exit(1);
system("hg pull") && exit(1);
system("hg update") && exit(1);
system("hg qpush -a") && exit(1);

my $patches = `hg qseries`;
$patches =~ s/\r//g;
$patches = "-r " . join(" -r ", split(/\n/, $patches));
system("hg qdelete $patches") && exit(1);

I saved it as “hgrebase” in the “\mozilla-build\msys\bin” directory so now I only need to type “hgrebase” on the command line. Hope this will be helpful to some (it surely will be to me).

Update: As Pascal points out below, there is already a qrebase extension doing mostly the same thing. And Mercurial 1.1 will have this feature built in anyway. So apparently there are other options.

Categories: ,


  1. Pascal

    Just for your information, Mercurial 1.1 (that will hopefully be released rather soon) will include a real rebase extension (see http://www.selenic.com/mercurial/wiki/index.cgi/RebaseExtension for details)

    Reply from Wladimir Palant:

    Yes, I saw it. I also hope that this one can be used soon – but since I have to work with Mercurial already, it is good to have an intermediate solution.

Commenting has expired for this article.

← Older Newer →