views:

71

answers:

2

I have lots of different clones which I work on separately. When I want to update those clones, it can be quite slow to update them from the server. So instead I have a "clean" clone, which I update from the server regularly, and all the other clones clone from the clean clone (hope that makes sense).

But now what I have is a two-step approach. First go to the clean clone and pull, and then go to the real clone i'm working on and pull from the clean clone. Can this be made into 1 step?

Ideally, the "clean" clone would be transparent: when it's pulled from, it would do a pull itself. That way we'd have caching and 1-step. Is there a way to do this?

+2  A: 

Keeping a clean clone locally is very common and a good idea in general. I've always stuck with the two step process you describe, but you could do this with hooks if you wanted.

In your cache repos you'd put soemthing like this in the .hg/hgrc file:

[hooks]
preoutgoing = hg pull

which tells that repo to do a hg pull before it bundles up changes in response to a pull or clone request made on it.

Note that even if the downstream (real clone) repo requests a subset of the changesets using pull -r or clone -r this cache repo will pull down everything. That's likely what you want since your goal is a mirror but the commenter points it's worth pointing out.

Ry4an
You may have been misinformed: `preoutgoing` is *not* limited to network-based pulls. Also, you'll want to limit the `preoutgoing` hook to `pull`-requested changesets, to prevent it from also triggering when you're pushing from the clean clone to upstream.
Piet Delport
Ooh, you're right about preoutgoing -- all the better. I'll update.
Ry4an
Ok, this works.
Paul Biggar
OK, this doesn't work consistently. I believe this is because outgoing only triggers when the downstream repo (my checkout) is missing commits from the upstream repo (my cache). In this case there are 'outgoing' commits to trigger on. Is there a way to make this trigger is all cases where I pull from the cache repo?
Paul Biggar
Hrm, you're right. Try `pre-outgoing` (with the hyphen) which will either hit all the time, or never.
Ry4an
+1  A: 

You can do this using hooks. In your <clean-clone>/.hg/hgrc, add these as a first draft:

[hooks]

# Before a pull from this repository, pull from upstream.
preoutgoing.autopull = [ $HG_SOURCE = 'pull' ] && hg pull

# After a push to this repository, push to upstream.
changegroup.autopush = [ $HG_SOURCE = 'push' ] && hg push

(Note: "autopush" and "autopull" are optional identifiers with no special meaning; you can leave them out if you have no other hooks defined.)

Piet Delport
Does this work on Windows? I tried this, but I get `waiting for lock on repository c:\temp\cache held by 'LVKGamerPC:1308'`. This was during the "clone" part though, and I tried with just `= hg pull`, since the `[...]` parts, those are for Linux or something I guess?
Lasse V. Karlsen