Question

To implement github like fork/pull request function in my project, the auto-merge feature need to detect conflict between source/target repository every time while viewing the pull request.

One solution comes to me is to analyze the 'git request-pull' output. Is there any easier method to detect the conflict?

Was it helpful?

Solution 4

Finally I wrote my own function to detect conflict.

It is quite simple, just fetch all diff lines, and compare if there is same modifications.

OTHER TIPS

I have deleted my previous answer, I didn't understand the question ...

Now here's the shiny new answer:

git merge --ff-only <branch>

If there are no conflicts, it will do a merge. With a conflict, it gives you a message: Not possible to fast-forward. The console return code (echo $?) is 128 in this situation.

We've created a git-conflict-detector that check the latest pushed commit vs all existing branches.

It's a simple single script that is initiated by GitHub WebHook URL and even know to sent an HiChat notification when conflict is detected.

We based our solution on analyzing the git merge --ff-only <branch> output as you can see here

We've open source it so all can enjoy, learn and contribute.

As far as I know, you can't find out if a merge would produce conflicts until you actually merge these branches.

This was already pointed out in: How to test a merge without actually merging first.

So, to answer your question, if you need to implement this kind of feature, you should most likely try to merge your source/target and rollback the merging action (using git reset --hard).

I never used git request-pull, but looking at the output, I don't see any information which could help you resolve your problem. You could probably get the same result using git diff, git wtf, git remote show <name>.

References:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top