Skip to content

Commit

Permalink
Merge pull request #550 from libgit2/add-merge-conflicted-files-to-er…
Browse files Browse the repository at this point in the history
…ror-info

Add merge conflicted files to user info
  • Loading branch information
joshaber committed Feb 3, 2016
2 parents bc11b50 + 72f149f commit d2e3eb7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
3 changes: 3 additions & 0 deletions ObjectiveGit/GTRepository+Pull.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

NS_ASSUME_NONNULL_BEGIN

/// UserInfo key for conflicted files when pulling fails with a merge conflict
extern NSString * const GTPullMergeConflictedFiles;

/// An enum describing the result of the merge analysis.
/// See `git_merge_analysis_t`.
typedef NS_OPTIONS(NSInteger, GTMergeAnalysis) {
Expand Down
9 changes: 4 additions & 5 deletions ObjectiveGit/GTRepository+Pull.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#import "GTIndexEntry.h"
#import "git2/errors.h"

NSString * const GTPullMergeConflictedFiles = @"GTPullMergeConflictedFiles";

@implementation GTRepository (Pull)

#pragma mark - Pull
Expand Down Expand Up @@ -112,11 +114,8 @@ - (BOOL)pullBranch:(GTBranch *)branch fromRemote:(GTRemote *)remote withOptions:
[files addObject:ours.path];
}];
if (error != NULL) {
if (files.count > 0) {
*error = [NSError git_errorFor:GIT_ECONFLICT description:@"Merge conflict in files: %@. Pull aborted.", [files componentsJoinedByString:@", "]];
} else {
*error = [NSError git_errorFor:GIT_ECONFLICT description:@"Merge conflict, pull aborted"];
}
NSDictionary *userInfo = @{GTPullMergeConflictedFiles: files};
*error = [NSError git_errorFor:GIT_ECONFLICT description:@"Merge conflict, Pull aborted." userInfo:userInfo failureReason:nil];
}
return NO;
}
Expand Down
4 changes: 3 additions & 1 deletion ObjectiveGitTests/GTRepository+PullSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,9 @@
transferProgressed = YES;
}];
expect(@(result)).to(beFalsy());
expect(error).toNot(beNil());
expect(error.domain).to(equal(@"GTGitErrorDomain"));
expect(error.userInfo[GTPullMergeConflictedFiles]).to(equal(@[@"test.txt"]));
expect(error.localizedDescription).to(equal(@"Merge conflict, Pull aborted."));
expect(@(transferProgressed)).to(beTruthy());
});

Expand Down

0 comments on commit d2e3eb7

Please sign in to comment.