[RFC] remove/copy enhancements

Jordan Breeding jordan.breeding at mac.com
Thu Sep 15 14:25:57 CDT 2005

On Thursday, September 15, 2005, at 12:54PM, Bryan O'Sullivan <bos at serpentine.com> wrote:

>On Thu, 2005-09-15 at 12:30 -0500, Jordan Breeding wrote:
>> The problem I see is that `hg cp -p <dir> <new_name>` fails,
>Works for me:
>~/hg/hg/hg-work $ ls newdir
>ls: newdir: No such file or directory
>~/hg/hg/hg-work $ hg cp -p doc newdir
>copying doc/Makefile to newdir/doc/Makefile
>copying doc/README to newdir/doc/README
>copying doc/hg.1.txt to newdir/doc/hg.1.txt
>copying doc/hgmerge.1.txt to newdir/doc/hgmerge.1.txt
>copying doc/hgrc.5.txt to newdir/doc/hgrc.5.txt
>>  `mkdir <new_name>; hg cp -p <dir> <new_name>` works but I end up with
>> <new_name>/<dir>.
>If that's not the behaviour you want, then don't use -p.
>> 50 jbb at cloves /tmp/jbb_test > hg cp -p three ten
>> abort: with --parents, destination must be a directory
>You appear to be getting completely different errors from me.  This
>works for me, for example.  Can you instrument the code a bit, and look
>into what's happening?
>	<b

I will just make a quick list of what I have found:

1) if I have a directory structure with only one file in it


then I get the error "with --parents, destination must be a directory", which seems to come from the check in mercurial/commands.py:733 through 737

2) I understand how `hg cp` is working now an I had originally though it would operate much more like the `cp` command in UNIX/Linux/OS X/etc.

for two example directory structures:



  (seven, and three are files)



  (seven, eight, nine, and three are files)

real cp would do something like:

`cp three ten`: warn that three is skipped because it is a directory
`cp -R three ten`: end up with:
`cp -R three one ten`: error, ten doesn't exist

with hg you get something like the following (with the letter to the left being the starting tree):

(a) `hg cp three ten`: end up with:
  ten (a copy of three/four/seven)
(a) `hg cp -p three ten`: error message "destination must be directory"
(a) `mkdir ten; hg cp -p three ten`: end up with:
(a) `hg cp three one ten`: end up with:
(a) `hg cp -p three one ten`: end up with:

(b) `hp cp three ten`: end up with:
(b) `hg cp -p three ten`: end up with:

So, it seems that if there are multiple files involved hg acts one way, if it is a single file, it behaves another.  Regular `cp` will only differ in behavior based on the way it was called, and not how many files it ends up needing to handle, regular `cp` also will not ever create a directory as a container, it will either make an exact copy of a tree/file with just the base renamed (dir one to dir two, file one to file two), or it will complain that you have specified multiple files/directories/both on the command line and that the specified destination directory doesn't exist.

I think it would be nice if `hg <command>` behaved like its `<command>` counterpart as much as possible.  Would any of this be made simpler if hg started tracking very basic information for directories (name, version, contents as of that version)?


More information about the Mercurial mailing list