bzr ignore pattern not limited to branch root (as expected)

Bug #57637 reported by Ricardo Kirkner
2
Affects Status Importance Assigned to Milestone
Bazaar
Fix Released
Medium
Unassigned

Bug Description

I tried to put my home directory under bzr control. The problem appeared when versioning the dotfiles (.*)

In order to keep things clean, I made a directory named .dotfiles

I wanted to move all dotfiles to this directory, so I could keep my home directory uncluttered.

I issued

bzr ignore "./.*"

on my home directory. This went fine (I mean, the . files got all ignored). Then I manually added the .dotfiles directory using

bzr add .dotfiles

I got the message "ignore 23 file(s)." meaning that all the .* files inside this directory got ignored because of the ignore pattern.

However, according to bzr help ignore, by specifing ./ prefix, this should not have happened.

In order to reproduce this bug, just create a .dotfiles directory with files named .myfile1, .myfile2, etc, and issue bzr ignore "./.*" in .dotfiles parent's directory.

Revision history for this message
John A Meinel (jameinel) wrote :

The bug doesn't seem related to dotfiles specifically. I was able to reproduce the problem as:

$ bzr ignore './f*'
$ mkdir foo
$ touch foo/bar
$ bzr add foo
added foo
ignored 1 file(s).
If you wish to add some of these files, please add them by name.

Also, this test fails:
=== modified file 'bzrlib/tests/workingtree_implementations/test_is_ignored.py'
--- bzrlib/tests/workingtree_implementations/test_is_ignored.py 2006-07-21 04:02:14 +0000
+++ bzrlib/tests/workingtree_implementations/test_is_ignored.py 2006-08-25 01:16:27 +0000
@@ -77,6 +77,13 @@
         self.assertEqual(None, tree.is_ignored(' xx'))
         self.assertEqual(None, tree.is_ignored('subdir/xx '))

+ def test_dotfile(self):
+ tree = self.make_branch_and_tree('tree')
+ self.build_tree_contents([('tree/.bzrignore', './f*\n')])
+ self.assertEqual('./f*', tree.is_ignored('foo'))
+ self.assertEqual(None, tree.is_ignored('foo/bar'))
+ self.assertEqual(None, tree.is_ignored('foo/.bar'))
+
     def test_global_ignored(self):
         tree = self.make_branch_and_tree('.')

The second one matches.

So it seems our converter from globs to regex isn't probably ignoring the directory in the match.

It seems that because the pattern matches the parent directory, then all the files underneath that directory default to being ignored, even if the parent itself is versioned.

This stems from the fact that we use 'fnmatch.translate()' which translates '*' => '.*' rather than '[^/]*' or something like that.

So I would guess that we have had this bug for a long time, but never had someone who wanted to add files in a directory that would otherwise be ignored.

I certainly have versioned files that would have been ignored, and you can still use 'bzr add .dotfiles/*' to version all of the direct files. Or if you are using zsh, you cand do 'bzr add .dotfiles/**/*'

Changed in bzr:
importance: Untriaged → Medium
status: Unconfirmed → Confirmed
Revision history for this message
John A Meinel (jameinel) wrote :

On the mailing list, we decided the best fix would be just to use a custom glob => regex converter, rather than using fnmatch.translate(). There have been a couple proposals over time, so we should look into using them.

John A Meinel (jameinel)
Changed in bzr:
assignee: nobody → warthog618
Kent Gibson (warthog618)
Changed in bzr:
status: Confirmed → In Progress
Kent Gibson (warthog618)
Changed in bzr:
status: In Progress → Fix Committed
Aaron Bentley (abentley)
Changed in bzr:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.