Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add equality method to PathSpec #13

Merged
merged 2 commits into from
Apr 5, 2017
Merged

Conversation

ghickman
Copy link
Contributor

This adds the __eq__ method so you can compare two PathSpec instances for equality.

Personally I want this to see if a PathSpec instance has been instantiated with a default gitignore but I'm sure it would be useful to others too :)

Tests equality of this ``PathSpec`` with ``other`` based on the
regexs contained in their ``patterns``.
"""
paired_patterns = zip(self.patterns, other.patterns)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might need to use zip_longest() here to avoid equality when one is a "prefix" of the other.

This catches the case where one PathSpac's patterns are a subset of another which would cause a false positive when comparing them.
@cpburnz
Copy link
Owner

cpburnz commented Mar 28, 2017

Thanks, I'll look over this tonight.

@cpburnz cpburnz merged commit 78ad596 into cpburnz:master Apr 5, 2017
@ghickman ghickman deleted the patch-1 branch April 5, 2017 05:51
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants