Best way to check if a file matches an ignore pattern
Nicholas Allen
nick.allen at onlinehome.de
Sun Sep 7 15:33:28 BST 2008
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Thanks for that! Would that make sense to have as a core Bazaar command?
I think it would be useful for scripting purposes and to ask the user to
install another plugin seems a bit much for this feature. It would
certainly complicate the installation of my plugin.
Cheers,
Nick
John Arbash Meinel wrote:
> 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.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFIw+Y41+i51gqqEGkRAjTCAJ4oUuPb55UfE7zWlxzJ7Dg0cQrDyQCdF8Hf
/Em+hx331FhMaofH0yxXE4U=
=iNxw
-----END PGP SIGNATURE-----
More information about the bazaar
mailing list