Thursday, February 21, 2008

VC cloning into an existing directory

Mercurial won't let me clone into an existing directory.

This is a problem when trying to put (only) a subset of files under version control. For example, an Oracle installation includes an enormous directory structure. A few of its files really, really ought to be under version control (init.ora, tnsnames.ora, etc.); most shouldn't. I need an hg repository in the root of the Oracle software installation. Then, when I set up Oracle on a new machine, I need to clone that repository into the new machine's Oracle root... even though the new machine's Oracle root already exists and is chock-full of files.

$ hg clone src target
abort: destination 'target' already exists

I'm surprised that there's no --overwrite flag for hg clone, or anything like it, saying "go ahead and clone into that directory even though it already exists." Perhaps it's simply because VC programmers are software developers, used to working with a clean slate rather than configuring an existing directory structure? Anyway, I made up a script workaround.

hg clone $1 $1_clone_temp
cp -r $1_clone_temp/* $2/
rm -r $1_clone_temp

Or, in Windows,

hg clone %1 %1_clone_temp
xcopy /e /s /h /g /y %1_clone_temp %2
rmdir /s /q %1_clone_temp

Thanks to the Linuxchix irc channel for helping me figure out the syntax.

No comments: