Reputation: 96264
I have the following on .hgignore
:
syntax: glob
*
and the following on myfiles.txt
:
.zshrc
.zprofile
glob:.less*
glob:.emacs*/**
glob:src*/**
glob:.bash*
.inputrc
.ssh
If I try adding the files in myfiles.txt
to the Mercurial repository using File Name patterns:
hg add listfile:myfiles.txt
or File Sets:
hg add "set: 'listfile:myfiles.txt' "
it doesn't work; Mercurial prints nothing and it doesn't add any files.
However, the two statements above work as soon as I remove *
from .hgignore
, which is odd, since I thought an explicit hg add
should override anything on .hgignore
.
Aside from whether or not the above is expected Mercurial behavior, my goal is to have Mercurial ignore all files except those that I add explicitly from a control file such as myfiles.txt
where I can use glob patterns. Is there a way to do this in Mercurial?
I'm not sure why some of the file patterns work for @smooth reggae. As @Martin said below, he was able to reproduce the behavior above, where file patterns seem to "clash" .hgignore
, as they do for me (i.e. Mercurial respects .hgignore
regardless of the explit hg add
command).
To clarify, I am running Mercurial version 2.0.1 on Linux, and I have tried this on Red Hat and Ubuntu.
Upvotes: 2
Views: 317
Reputation: 2219
@intrpc, I am using TortoiseHg 2.1.3/Mercurial 1.9.2 and I was able to get a similar sample to work: I had a file called .sample
and another file two levels deep foo/bar/Foo.txt
; I had patterns.txt
located a level above. With the same .hgignore
as yours, I ran hg init
and then hg add listfile:..\patterns-for-hg.txt
for two cases:
with the patterns.txt
containing
.sample
glob:foo/**
in this case, hg status
told me that Mercurial had added .sample
to the repository but skipped foo/bar/Foo.txt
with the patterns.txt
containing
.sample
path:foo/bar/Foo.txt
in this case, hg status
told me that Mercurial had added both .sample
and foo/bar/Foo.txt
to the repository
The behaviour in (2) above seems to make sense to me, because, Mercurial will ignore .hgignore
if you invoke hg add
with a full path to the file (this is the "explicit add" you are referring to).
The only explanation I can think of for the behaviour in (1) is that the glob in patterns.txt
is treated like a wildcard and not an exact pattern; hence, hg add
respects .hgignore
and exact paths (.sample
) and nothing else.
These are, of course, guesses; so any response from someone more qualified is more welcome.
Upvotes: 2