Best way to check if a file matches an ignore pattern

John Arbash Meinel john at arbash-meinel.com
Sun Sep 7 15:27:40 BST 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Nicholas Allen wrote:
> Sorry, I was not clear enough - I meant from the command line. I need it
> for my Eclipse plugin (which is written in Java) so I need some way to
> detect this by invoking bzr commands...
> 
> Nick
> 
> Mark Hammond wrote:
>>> How can I check if a file matches an ignore pattern?
>> Use the tree.is_ignored() method.
> 
>> Cheers,
> 
>> Mark
> 
> 
> 

echo > ~/.bazaar/plugins/is_ignored.py <<EOF
from bzrlib import commands, workingtree

class cmd_is_ignored(commands.Command):
    """Check to see if a path would be ignored."""

    takes_args = ['filename']

    def run(self, filename):
      try:
        tree, relpath = \
           workingtree.WorkingTree.open_containing(filename)
      except (errors.NoWorkingTree, errors.NotBranchError):
	  # Either a branch without a working tree, or no branch at all
          # That can't really be considered ignored
          return 30
      if tree.path2id(relpath) is not None:
        # Versioned files are never ignored
        return 20
      if tree.is_ignored(relpath):
        return 0
      return 10

commands.register_command(cmd_is_ignored)
EOF

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkjD5NsACgkQJdeBCYSNAANWiQCg0NO0Bvbwq6D+gTrUHLoTpVfU
VVgAoMgtzVbgVzhlKKdnJDesSck66naw
=BGoi
-----END PGP SIGNATURE-----



More information about the bazaar mailing list