How to detect conflict between two git repositories.
Asked Answered
C

5

7

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?

Coastland answered 24/4, 2012 at 2:58 Comment(2)
What is being asked here? Are you implementing a merge tool? Or a diff-viewing tool? Or simply curious what git push is going to do?Mockheroic
In github, a non-conflict pull request can be merged just by click a button on web. Since the source/target repository could keep on committing, a detection of conflict is a must in this process. I'm asking a easier way to detect the conflict.Coastland
C
-1

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.

Coastland answered 20/6, 2012 at 7:41 Comment(1)
It would be great to post it here for future referenceStandby
P
3

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.

Popele answered 24/4, 2012 at 7:13 Comment(1)
This is not relevant much to the question, but is good while merging after fetch.Pianoforte
M
1

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.

Malena answered 5/11, 2013 at 1:7 Comment(0)
S
0

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:

Santanasantayana answered 24/4, 2012 at 11:34 Comment(0)
L
0

For the record, there is git merge-tree that can tell you on cmdline if two commits aka. branches aka. pull requests conflict without touching index or working tree:

$> git merge-tree 9e451918b3bb56f857c6f6df5d527092c02b2b3a  b246935
60633013298d0dc97cde3738a378228b24e2b065
100644 88c2893ef8df18fd38034deab08cfee24dfb26fe 2       file1
100644 257cc5642cb1a054f08cc83f2d943e56fd3ebe99 3       file1

Auto-merging file1
CONFLICT (add/add): Merge conflict in file1

Of course you have to have both fetched.

The Github API seems not be too responsive on this question. A PR can tell if it has merge conflicts with base branch. Also two commits can be compared, but that tells you only the diff or patch, but not if it has a conflict. There seems to be no API to evaluate if two pulls or branches or commits would conflict, although Github certainly has all required information in its db. I didn't try, but I assume that when you get the patch infos from github you can run patch --dry-run to see if this conflicts.

Languish answered 12/4, 2023 at 12:0 Comment(0)
C
-1

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.

Coastland answered 20/6, 2012 at 7:41 Comment(1)
It would be great to post it here for future referenceStandby

© 2022 - 2024 — McMap. All rights reserved.