Skip to content

Added shouldIgnoreFileURL:error: convenience wrapper #545

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

Merged
merged 3 commits into from
Jan 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions ObjectiveGit/GTRepository+Status.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@ extern NSString *const GTRepositoryStatusOptionsPathSpecArrayKey;
/// Returns YES if the file should be ignored; NO otherwise.
- (BOOL)shouldFileBeIgnored:(NSURL *)fileURL success:(nullable BOOL *)success error:(NSError **)error;

/// An enum for use with shouldIgnoreFileURL:error: below
typedef NS_ENUM(NSInteger, GTFileIgnoreState) {
GTFileIgnoreStateIgnoreCheckFailed = -1,
GTFileIgnoreStateShouldNotIgnore = 0,
GTFileIgnoreStateShouldIgnore = 1
};

/// Convenience wrapper for shouldFileBeIgnored:success:error:
- (GTFileIgnoreState)shouldIgnoreFileURL:(NSURL *)fileURL error:(NSError **)error;

@end

NS_ASSUME_NONNULL_END
9 changes: 9 additions & 0 deletions ObjectiveGit/GTRepository+Status.m
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,13 @@ - (BOOL)shouldFileBeIgnored:(NSURL *)fileURL success:(BOOL *)success error:(NSEr
return (ignoreState == 1 ? YES : NO);
}

- (GTFileIgnoreState)shouldIgnoreFileURL:(NSURL *)fileURL error:(NSError **)error {
BOOL success = NO;
BOOL ignore = [self shouldFileBeIgnored:fileURL success:&success error:error];
if (success) {
return (ignore ? GTFileIgnoreStateShouldIgnore : GTFileIgnoreStateShouldNotIgnore);
}
return GTFileIgnoreStateIgnoreCheckFailed;
}

@end
18 changes: 18 additions & 0 deletions ObjectiveGitTests/GTRepository+StatusSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,24 @@
expect(@(enumerationSuccessful)).to(beTruthy());
expect(err).to(beNil());
});

it(@"should report file should be ignored", ^{
__block NSError *err = nil;
NSURL *fileURL = [repository.fileURL URLByAppendingPathComponent:@".DS_Store"];
BOOL success = NO;
BOOL shouldIgnore = [repository shouldFileBeIgnored:fileURL success:&success error:&err];
expect(@(success)).to(beTrue());
expect(@(shouldIgnore)).to(beTrue());
expect(err).to(beNil());
});

it(@"should report file should be ignored (convenience wrapper)", ^{
__block NSError *err = nil;
NSURL *fileURL = [repository.fileURL URLByAppendingPathComponent:@".DS_Store"];
GTFileIgnoreState ignore = [repository shouldIgnoreFileURL:fileURL error:&err];
expect(@(ignore)).to(equal(@(GTFileIgnoreStateShouldIgnore)));
expect(err).to(beNil());
});
});

afterEach(^{
Expand Down