Question

Using Mercurial, how can I bundle all changesets not known to be in another repository, including secret changesets?

I know bundle's --base option happens to include secret changesets, but I don't want the --base behavior. (And it seems unusually weird that secret changesets are always included with --base but are never included without it. Shouldn't there be a separate option?)

FYI, I commonly want to make a backup of all changesets which are only in my local repo before attempting a potentially dangerous history rewrite.

Was it helpful?

Solution

You are correct that hg bundle will normally exclude secret changesets. This is because it's just running the equivalent of hg outgoing and bundling these changesets.

So some work-arounds:

  • If you know that you have at least one draft or public outgoing changeset as an ancestor of your secret changesets, then you can use

    $ hg bundle --base "parents(outgoing())"
    

    to get what you want. The outgoing() revset will pick the missing draft and public changesets and parents(outgoing() will be suitable bases. Since you use --base you get all descendants (public, draft, and secret) from these bases.

  • You could temporarily make your secret changesets draft, bundle, and then mark them secret again:

    $ secret=$(hg log --template "{rev} " -r "secret()"); \
      hg phase -d $secret; \
      hg bundle out.hg; \
      hg phase -f -s $secret
    

    (I use Zsh and there I had to use ${=secret} instead of $secret because Zsh doesn't do word splitting on parameter expansion by default.)

    It's important to chain the commands with ; instead of && since you'll want to reset the phases regardless of what happens in the hg bundle call — passing wrong parameters to hg bundle should not mean that you lose all the information about the secret changesets. Note also that since secret changesets only have secret descendants, there's no information loss with this technique.

    You can turn this into a shell alias:

    [alias]
    bundle-all = !secret=$(hg log --template "{rev} " -r "secret()");
                 hg phase -d $secret;
                 hg bundle $@;
                 hg phase -f -s $secret
    

    The $@ is expanded by Mercurial before the alias is invoked and this lets you insert the necessary arguments for hg bundle.

Note that phase information cannot be stored in bundles — the bundle format has not been changed to accommodate it.

OTHER TIPS

If you know there is at least one public changeset, you can use this:

hg bundle -r "not public()" --base public()

OTOH, that won't work if there are no public changesets, use this instead:

hg bundle -r "not public()" --base null

The problem with Martin's answer is that it relies on outgoing, which in turn relies on a direct connection to the push repo. If you don't always have an internet connection to that repo, these methods work well for me. It's also somewhat simpler than the phase dance.

One test for whether there are any public changesets is to capture the output of:

hg log -r public() -l 1 --template "{rev}"

and test its length, or the presence of [0-9].

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top