8000 Merging with a custom merge driver · Issue #656 · libgit2/objective-git · GitHub
[go: up one dir, main page]

Skip to content

Merging with a custom merge driver #656

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

Closed
jonsongoffwhite opened this issue May 13, 2018 · 6 comments
Closed

Merging with a custom merge driver #656

jonsongoffwhite opened this issue May 13, 2018 · 6 comments

Comments

@jonsongoffwhite
Copy link
jonsongoffwhite commented May 13, 2018

There is a merge driver present in my repository, which is set up in config and attributes, and it works correctly via the command line, however when merging using repo.mergeBranch()
(- (BOOL)mergeBranchIntoCurrentBranch:(GTBranch *)fromBranch withError:(NSError **)error;),
the merge driver doesn't seem to be used.

Am I missing something, or is this something that's not implemented?

Thanks!

@tiennou
Copy link
Contributor
tiennou commented May 13, 2018

AFAIK there's no automatic support in libgit2, so you'll have to grab the interesting parts of git2/sys/merge.h to make it work.

@jonsongoffwhite
Copy link
Author

@tiennou thanks for the reply!

I'm afraid I'm not well versed with libgit2, could you give me any pointers as to where to start?

@tiennou
Copy link
Contributor
tiennou commented May 16, 2018

You might be able to get more help from StackOverflow (as in, most of the developers follow the libgit2 tag).

Note that I've never used that part of the code too, so YMMV.

You'll need to declare your own static git_merge_driver my_driver struct somewhere, with its apply member pointing to your own git_merge_driver_apply_fn-style function, and register that using git_merge_driver_register (mind your threading), using your "attribute" name as the registration name.

Your apply function should now get called when merging files with the attribute you want (I think this is automatic, but I sincerely don't know), so for now return GIT_EPASSTHROUGH so the normal "text" driver does. Make sure this works.

Then, it should be just a matter of using the apply function parameters, most notably the git_merge_source, which has all the mergy requirements (eg. ours/theirs, see git_index_entry). You should be able to extract the relevant command to execute from the repo config, and perform a fork/exec dance or something.

HTH!

@jonsongoffwhite
Copy link
Author

Thanks, that definitely helped!

What do you mean by my "attribute" name?

@tiennou
Copy link
Contributor
tiennou commented May 17, 2018

Not sure, actually 😆. I was under the impression you would have to declare a .gitattributes pattern for which files should be merged with a custom driver, but the docs explicitely say it's unrelated to attributes.

Well, I'm confused now. It seems you have to add a merge=driver_name attribute to a pattern in .gitattributes so the Thing Happens.

@tiennou
Copy link
Contributor
tiennou commented Sep 27, 2018

Closing because AFAIK it's not really an issue. Feel free to reopen though !

@tiennou tiennou closed this as completed Sep 27, 2018
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

2 participants
0