Sylvain
Sylvain

Reputation: 19259

How to use `hg cat` from an empty working directory?

I have a repo located at x:/projects/repo1. The working directory has been emptied using hg update null. I want to extract the latest version of some files from there to a local directory.

I tried this:

x:\projects\repo1> hg cat -o c:\sql\%s scripts\*.sql -r tip

I get this error:

scripts\*.sql: No such file in rev 14f07c26178b

The same command works fine if the working directory is not empty. Is there a good reason why this does not work? Or do you know another way of extract some files from there to a local directory?

Upvotes: 5

Views: 1720

Answers (3)

Ry4an Brase
Ry4an Brase

Reputation: 78340

The hg cat command is for single files. If you want multiple files use the hg archive command, which makes zipfiles or directories full of files. Here's your command:

x:\projects\repo1> hg archive --include scripts\*.sql -r tip c:\sql

Upvotes: 5

Niall C.
Niall C.

Reputation: 10918

This answer is to your comment on Andrey's answer:

hg manifest takes a --rev argument that you can use to see the list of all files in your repository:

hg manifest --rev tip

To get the list of files matching a pattern at the tip, use:

hg stat --all --include *.sql --rev tip --no-status
hg stat -A -I *.sql --rev tip -n                    # using abbreviations.

From there you could redirect the output to a file and edit each line into a hg cat command like in your original question. It appears (to me, at least, having done some experimentation) that hg cat uses the contents of the working directory -- rather than the contents of the repository at the revision specified -- for glob-matching, so once you know the exact name of the file, you can hg cat it at any revision.

Upvotes: 2

Andrey Vlasovskikh
Andrey Vlasovskikh

Reputation: 16848

It seems that hg cat doesn't support wildcard symbols in paths. So you should use the full file name:

hg cat -r tip scripts/foo.sql

When your working copy is up to date with the tip revision, your shell does wildcard substitution for you.

The hg manifest command also might be helpful for getting tracked file listings.

Upvotes: 2

Related Questions