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

Create a merge commit when pulling/merging changes where all conflicts can be resolved automatically #639

Open
ralfebert opened this issue Oct 12, 2017 · 3 comments

Comments

@ralfebert
Copy link

ralfebert commented Oct 12, 2017

Given: A local branch and remote branch, both with commits. When merging those, all conflicts can be resolved automatically, for example because different files were changed locally and remote.

When such a situation is merged via mergeBranchIntoCurrentBranch (for example as part of pullBranch) in this situation, a merge conflict error will be thrown:
https://github.com/libgit2/objective-git/blob/master/ObjectiveGit/GTRepository+Merging.m#L135

But then the conflicts are written to the index and this index might not have any conflicts because all conflicts were resolved automatically.

In this case, shouldn't the merge commit be created and the operation return without an error?

I tried to solve this, by instead of always returning with an error here: https://github.com/libgit2/objective-git/blob/master/ObjectiveGit/GTRepository+Merging.m#L148
I check if there are actually any remaining conflicts in the index that was written, and if not, I carry on creating the merge commit:

index = [self indexWithError:nil];
if (index.hasConflicts) {
	return NO;
} else {
	*error = nil;
}

This seems to work, not sure if it's the correct solution that covers all cases that can happen in this situation...

@pietbrauer
Copy link
Member

Thanks for opening this. I think the best way to discuss this solution would be if you open a Pull Request so we can discuss it there.

@ralfebert
Copy link
Author

Thanks for your feedback - I'll try to write a test case that shows the scenario and open a pull request for that in the next few days.
One thing that would help me with that: While merging, the index seems to be in a special state (the cmdline git prompt shows this as "MERGING", you can leave it via git merge --abort). I tried to find functions relating to this state (querying, finishing, aborting) in libgit2 as well but couldn't find anything. Any hints?

@jeffreybergier
Copy link

@ralfebert - (BOOL)cleanupStateWithError:(NSError * _Nullable __autoreleasing *)error; will clean up the mid-merge state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants