Can't get .bzrignore file to ignore all files in a directory

Asked by Peter Kasbergen

I would like to have Bazaar ignore the complete /cache directory in the working tree. I have added ./cache/* to the .bzrignore file, but the output of bzr ignored is:

cache/index.html ./cache/*

It seems the only file Bazaar is ignoring is the index.html file in the /cache directory. There are many more directories below /cache, but none of these are ignored, including the files in them. What am I doing wrong?

Question information

Language:
English Edit question
Status:
Solved
For:
Bazaar Edit question
Assignee:
No assignee Edit question
Solved by:
Peter Kasbergen
Solved:
Last query:
Last reply:
Revision history for this message
John A Meinel (jameinel) said :
#1

* just ignores everything in that directory. Also, if things are versioned they will continue to be versioned (so you may need to do 'bzr rm --keep' cache/* to unversion them).

If you want to version some directories, but not all, then you may want to use "**" instead of just "*", as it will match across directories, instead of just within a given directory. (It might be cache/**/*, I'm not positive)

Revision history for this message
Peter Kasbergen (peter-kasbergen) said :
#2

Thanks for the quick reply, but your commands did not work at all. I found another strange thing though. I tried removing several individual files, and afterwards, these files DID show up when running 'bzr ignored':

cache/csv/index.html cache/**/*
cache/custom_fields/custom_fields_def.php cache/**/*
cache/index.html cache/**/*

Removing files should not have any effect on ignored files, should it?

Some more technical info, just in case: Running Bazaar 1.0 on Windows.

Revision history for this message
xVaultX (incircle) said :
#3

Put yourself in the parent directory and type
bzr ignore <dirname>

then check the .bzrignore file and you will see that the case of ignoring a directory is handled like this \bin\ or bin\ if I remember it well.

in your case it should be ./cache/ I think.

Revision history for this message
Peter Kasbergen (peter-kasbergen) said :
#4

Sorry, I tried this as well, but no change. This is starting to sound like a bug... or?

Does anyone have any more ideas?

Revision history for this message
Peter Kasbergen (peter-kasbergen) said :
#5

Correction, I am running 1.2. Will try upgrading to 1.3 now and see what happens.

Revision history for this message
Peter Kasbergen (peter-kasbergen) said :
#6

Upgrading to 1.3 did not bring any improvement. However, I have now found out that the files are correctly ignored if I create the .bzrignore file BEFORE adding the files in the working tree. If this is normal procedure, it may be an idea to explicitly mention this in the User Guide. My problem is solved for now. Thanks for the help!

Revision history for this message
Martin Pool (mbp) said :
#7

The ignore pattern only applies to non-added (ie unknown) files. Once
a file is added, it remains versioned regardless of whether it matches
an ignore pattern or not. I think the manual is clear about this - if
there is something that makes it unclear could you tell me the
particular bit, or what sentence would have improved it for you?

--
Martin <http://launchpad.net/~mbp/>

Revision history for this message
Peter Kasbergen (peter-kasbergen) said :
#8

Well in my case I do a 'bzr add' before I commit the tree, because I am configuring a production system through a web interface and want to track which files are changed or added in the process (i.e. no 'manual' hacking). So I need the patterns of all the files and directories I want to be ignored to be in the .bzrignore file.

If something exactly like what you just said could be added to paragraph 3.3.3 in the User guide, this would make things clearer for at least the beginning user, I guess:
"Please note that the ignore pattern only applies to non-added (ie unknown) files. Once a file is added, it remains versioned regardless of whether it matches an ignore pattern or not."

Hope this helps make Bazaar even better...

Revision history for this message
Martin Pool (mbp) said :
#9

How about this:

=== modified file 'doc/en/user-guide/controlling_registration.txt'
--- doc/en/user-guide/controlling_registration.txt 2008-01-12 00:20:20 +0000
+++ doc/en/user-guide/controlling_registration.txt 2008-04-10 00:45:43 +0000
@@ -73,10 +73,10 @@
     config.h ./config.h
     configure.in~ *~

-It is OK to have either an ignore pattern match a versioned file, or to
-add an ignored file. Ignore patterns have no effect on versioned files;
-they only determine whether unversioned files are reported as unknown or
-ignored.
+Note that ignore patterns are only matched against non-versioned files,
+and control whether they are treated as "unknown" or "ignored". If a file
+is explicitly added, it remains versioned regardless of whether it matches
+an ignore pattern.

 The ``.bzrignore`` file should normally be versioned, so that new copies
 of the branch see the same patterns::

Revision history for this message
Martin Pool (mbp) said :
#10

This text will be in 1.4. If you see anything else that could be improved Peter please let us know -- specific paragraphs and suggested better text is most helpful. Even if you're not sure what is correct taking a stab helps us see what is unclear.

Revision history for this message
Peter Kasbergen (peter-kasbergen) said :
#11

The proposed change sounds good to me. Maybe it would be just a little clearer if you change it like so:

Note that ignore patterns are only matched against non-versioned files, and control whether they are treated as "unknown" or "ignored".
If a file >>>has already been<<< explicitly added, it remains versioned regardless of whether it matches an ignore pattern.

Revision history for this message
Brade (bradezone) said :
#12

I have to say I was intensely confused by the fact that my ignore patterns did not apply to files already added. To me, that makes no sense. In my case I want to ignore all these .DS_Store files that my OS puts in every directory, and for the life of me I couldn't figure out why my ignore rule was... ignored.
I'm just wondering why there can't at least be a flag for the ignore command that would include files already versioned. it's rather a hassle to go "bzr remove" each file since there could be hundreds of them and the "remove" command cannot be fed a pattern like "ignore" can...

Revision history for this message
Martin Pool (mbp) said :
#13

Brade, you should be able to do something like this on Mac OS:

  find . -name .DS_Store -print0 | xargs -0 bzr rm --keep

Because people do hit this sometimes perhaps there should be a command somewhere that (maybe interactively) either deletes or unversions versioned-but-ignored files.