Skip to content

Commit 4a9ef96

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents f021ff4 + 1a00686 commit 4a9ef96

File tree

5 files changed

+53
-5
lines changed

5 files changed

+53
-5
lines changed

ObjectiveGit/GTIndex.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ NS_ASSUME_NONNULL_BEGIN
107107
/// Returns a new GTIndexEntry, or nil if an error occurred.
108108
- (nullable GTIndexEntry *)entryAtIndex:(NSUInteger)index;
109109

110-
/// Get the entry with the given path.
111-
- (GTIndexEntry *)entryWithPath:(NSString *)path;
110+
/// Get the entry with the given path, or nil if an error occurred.
111+
- (nullable GTIndexEntry *)entryWithPath:(NSString *)path;
112112

113113
/// Get the entry with the given name.
114114
///

ObjectiveGit/GTRepository+Pull.m

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#import "GTRepository+RemoteOperations.h"
1818
#import "GTTree.h"
1919
#import "NSError+Git.h"
20+
#import "GTIndexEntry.h"
2021
#import "git2/errors.h"
2122

2223
@implementation GTRepository (Pull)
@@ -106,7 +107,17 @@ - (BOOL)pullBranch:(GTBranch *)branch fromRemote:(GTRemote *)remote withOptions:
106107

107108
// Check for conflict
108109
if (index.hasConflicts) {
109-
if (error != NULL) *error = [NSError git_errorFor:GIT_ECONFLICT description:@"Merge conflict, pull aborted"];
110+
NSMutableArray <NSString *>*files = [NSMutableArray array];
111+
[index enumerateConflictedFilesWithError:error usingBlock:^(GTIndexEntry * _Nonnull ancestor, GTIndexEntry * _Nonnull ours, GTIndexEntry * _Nonnull theirs, BOOL * _Nonnull stop) {
112+
[files addObject:ours.path];
113+
}];
114+
if (error != NULL) {
115+
if (files.count > 0) {
116+
*error = [NSError git_errorFor:GIT_ECONFLICT description:@"Merge conflict in files: %@. Pull aborted.", [files componentsJoinedByString:@", "]];
117+
} else {
118+
*error = [NSError git_errorFor:GIT_ECONFLICT description:@"Merge conflict, pull aborted"];
119+
}
120+
}
110121
return NO;
111122
}
112123

ObjectiveGit/GTRepository+Status.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,23 @@ extern NSString *const GTRepositoryStatusOptionsPathSpecArrayKey;
126126

127127
/// Tests the ignore rules to see if the file should be considered as ignored.
128128
///
129-
/// fileURL - A string path relative to the working copy. Must not be nil.
129+
/// fileURL - A local file URL for a file in the repository. Must not be nil.
130130
/// success - If not NULL, will be set to indicate success or fail.
131131
/// error - If not nil, set to any error that occurs.
132132
///
133133
/// Returns YES if the file should be ignored; NO otherwise.
134134
- (BOOL)shouldFileBeIgnored:(NSURL *)fileURL success:(nullable BOOL *)success error:(NSError **)error;
135135

136+
/// An enum for use with shouldIgnoreFileURL:error: below
137+
typedef NS_ENUM(NSInteger, GTFileIgnoreState) {
138+
GTFileIgnoreStateIgnoreCheckFailed = -1,
139+
GTFileIgnoreStateShouldNotIgnore = 0,
140+
GTFileIgnoreStateShouldIgnore = 1
141+
};
142+
143+
/// Convenience wrapper for shouldFileBeIgnored:success:error:
144+
- (GTFileIgnoreState)shouldIgnoreFileURL:(NSURL *)fileURL error:(NSError **)error;
145+
136146
@end
137147

138148
NS_ASSUME_NONNULL_END

ObjectiveGit/GTRepository+Status.m

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,16 @@ - (BOOL)shouldFileBeIgnored:(NSURL *)fileURL success:(BOOL *)success error:(NSEr
122122
}
123123

124124
if (success != NULL) *success = YES;
125-
return (ignoreState == 0 ? YES : NO);
125+
return (ignoreState == 1 ? YES : NO);
126+
}
127+
128+
- (GTFileIgnoreState)shouldIgnoreFileURL:(NSURL *)fileURL error:(NSError **)error {
129+
BOOL success = NO;
130+
BOOL ignore = [self shouldFileBeIgnored:fileURL success:&success error:error];
131+
if (success) {
132+
return (ignore ? GTFileIgnoreStateShouldIgnore : GTFileIgnoreStateShouldNotIgnore);
133+
}
134+
return GTFileIgnoreStateIgnoreCheckFailed;
126135
}
127136

128137
@end

ObjectiveGitTests/GTRepository+StatusSpec.m

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,24 @@
105105
expect(@(enumerationSuccessful)).to(beTruthy());
106106
expect(err).to(beNil());
107107
});
108+
109+
it(@"should report file should be ignored", ^{
110+
__block NSError *err = nil;
111+
NSURL *fileURL = [repository.fileURL URLByAppendingPathComponent:@".DS_Store"];
112+
BOOL success = NO;
113+
BOOL shouldIgnore = [repository shouldFileBeIgnored:fileURL success:&success error:&err];
114+
expect(@(success)).to(beTrue());
115+
expect(@(shouldIgnore)).to(beTrue());
116+
expect(err).to(beNil());
117+
});
118+
119+
it(@"should report file should be ignored (convenience wrapper)", ^{
120+
__block NSError *err = nil;
121+
NSURL *fileURL = [repository.fileURL URLByAppendingPathComponent:@".DS_Store"];
122+
GTFileIgnoreState ignore = [repository shouldIgnoreFileURL:fileURL error:&err];
123+
expect(@(ignore)).to(equal(@(GTFileIgnoreStateShouldIgnore)));
124+
expect(err).to(beNil());
125+
});
108126
});
109127

110128
afterEach(^{

0 commit comments

Comments
 (0)