Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add support for combining pathspec objects via addition operator #43

Merged
merged 1 commit into from
Nov 7, 2020
Merged

Add support for combining pathspec objects via addition operator #43

merged 1 commit into from
Nov 7, 2020

Conversation

nhhollander
Copy link
Contributor

This change allows for a set of rules to be expanded using the + and += operators.

I wrote these changes for a project of mine which collects patterns from multiple places and needs to combine them into a single PathSpec object, but for structural reasons can't practically combine the rules into a single list and pass to PathSpec.from_lines.

I also added and verified a couple of test cases for these new operators.

Example usage of + operator:

# Load first spec from a string array
spec1 = pathspec.PathSpec.from_lines('gitwildmatch', [
    'plans_for_world_domination.txt',
    'secret_family_recipe.txt'
])
# Load second spec from a file
fh = open('patterns.txt','r')
spec2 = pathspec.PathSpec.from_lines('gitwildmatch', fh)
# Combine the specs 
combined_spec = spec1 + spec2

Example usage of the += operator:

# Load first spec from a string array
spec = pathspec.PathSpec.from_lines('gitwildmatch', [
    'plans_for_world_domination.txt',
    'secret_family_recipe.txt'
])
# Load second spec from a file
fh = open('patterns.txt','r')
spec += pathspec.PathSpec.from_lines('gitwildmatch', fh)

@cpburnz cpburnz merged commit f1399b1 into cpburnz:master Nov 7, 2020
@cpburnz
Copy link
Owner

cpburnz commented Nov 7, 2020

The code and tests look good. Thanks for submitting the addition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants