Skip to content

Commit d2e3eb7

Browse files
committed
Merge pull request #550 from libgit2/add-merge-conflicted-files-to-error-info
Add merge conflicted files to user info
2 parents bc11b50 + 72f149f commit d2e3eb7

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

ObjectiveGit/GTRepository+Pull.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
NS_ASSUME_NONNULL_BEGIN
1313

14+
/// UserInfo key for conflicted files when pulling fails with a merge conflict
15+
extern NSString * const GTPullMergeConflictedFiles;
16+
1417
/// An enum describing the result of the merge analysis.
1518
/// See `git_merge_analysis_t`.
1619
typedef NS_OPTIONS(NSInteger, GTMergeAnalysis) {

ObjectiveGit/GTRepository+Pull.m

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#import "GTIndexEntry.h"
2121
#import "git2/errors.h"
2222

23+
NSString * const GTPullMergeConflictedFiles = @"GTPullMergeConflictedFiles";
24+
2325
@implementation GTRepository (Pull)
2426

2527
#pragma mark - Pull
@@ -112,11 +114,8 @@ - (BOOL)pullBranch:(GTBranch *)branch fromRemote:(GTRemote *)remote withOptions:
112114
[files addObject:ours.path];
113115
}];
114116
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-
}
117+
NSDictionary *userInfo = @{GTPullMergeConflictedFiles: files};
118+
*error = [NSError git_errorFor:GIT_ECONFLICT description:@"Merge conflict, Pull aborted." userInfo:userInfo failureReason:nil];
120119
}
121120
return NO;
122121
}

ObjectiveGitTests/GTRepository+PullSpec.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,9 @@
257257
transferProgressed = YES;
258258
}];
259259
expect(@(result)).to(beFalsy());
260-
expect(error).toNot(beNil());
260+
expect(error.domain).to(equal(@"GTGitErrorDomain"));
261+
expect(error.userInfo[GTPullMergeConflictedFiles]).to(equal(@[@"test.txt"]));
262+
expect(error.localizedDescription).to(equal(@"Merge conflict, Pull aborted."));
261263
expect(@(transferProgressed)).to(beTruthy());
262264
});
263265

0 commit comments

Comments
 (0)