[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mercurial
Subject:    Re: hg reattach
From:       Greg Ward <greg () gerg ! ca>
Date:       2013-02-08 22:31:04
Message-ID: 20130208223104.GC2703 () gerg ! ca
[Download RAW message or body]

On 08 February 2013, Jason Sachs said:
> 
> Suppose that I have a source tree X in a Mercurial repository. Also
> suppose, for whatever reason, that I receive a source tree X2 that I
> know was derived from the source tree X. (Maybe I'm working with a
> curmudgeon who doesn't like source control, or a consultant that I
> can't allow to see past history for legal reasons, but I need their
> help in fixing bugs.)
> 
> Is there a way to "reattach" my repository "underneath" source tree X2?
> 
> What I would do manually is:
> 1. rename the root directory of source tree X2 as some temporary
> directory X2-tmp
> 2. "hg clone -U" the mercurial repository into the path where X2 used
> to be, so it's just the .hg directory
> 3. move the contents of the renamed X2-tmp back into X2

Here's a slightly more clever way to do this. Assuming X and X2 are
siblings, and X is clean and updated to the head of the appropriate
branch:

  cp -al X/.hg X2
  cd X2
  hg addremove --similarity 75
  hg commit
  hg push ../X

The key to this trick is that copying .hg copies both the repository
store (.hg/store) and the dirstate. dirstate is where Mercurial
records the parents of the working dir, so hg {diff,addremove,commit}
just automatically do the right thing.

The other trick is addremove with rename detection. Nothing clever
about that, just using the tool to its maximum.

("cp -al" is a GNU-ism; works on Linux, but not OS X or BSD. It's just
a performance trick: hardlink rather than copy, which is safe because
Mercurial does copy-on-write under .hg.)

If you're particularly brave or foolhardy, you could

  mv X/.hg X2

or

  cd X2
  ln -s ../X/.hg .

but both of those give you less room to escape if the addremove or
commit go horribly wrong. Safer to copy.

Oh yeah to answer your question: I'm not aware of anyone having
automated this. I do it often enough to remember, but infrequently
enough that I haven't bothered writing the script. ;-)

       Greg
-- 
Greg Ward                            http://www.gerg.ca
<greg@gerg.ca>                       @gergdotca
_______________________________________________
Mercurial mailing list
Mercurial@selenic.com
http://selenic.com/mailman/listinfo/mercurial
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic