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 merge conflicted files to user info #550

Merged
merged 3 commits into from
Feb 3, 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
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation please 😬


/// 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";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should expose this from the header too, so users don't have to know the string literal.


@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