Refined-github: Fix merge conflict with both changes

Created on 13 Dec 2016  ·  14Comments  ·  Source: sindresorhus/refined-github

Issuehunt badges

We can now resolve merge conflicts in the GitHub UI. Often with merge conflicts, I want to include both the conflicts as it's usually just two list items being placed at the end. Would be nice to have a button that just removed the merge conflict markers.

screen shot 2016-12-13 at 00 33 35

Above, I would have like to preserve both the items. The red characters are the markers I would like removed.

farnabaz earned $60.00 by resolving this issue!

Rewarded on Issuehunt enhancement help wanted

Most helpful comment

Ok, I found a way to do this, but there are some problems and questions:

  • Could I add CodeMirror as develop dependency? because github use CodeMirror and features writes in Typescript.
  • I have to access CodeMirror object inside window, is this ok to do this?
// @ts-ignore
const CodeMirror = window.CodeMirror;
  • We can't access CodeMirror instance inside extension scope, so I forced to embed code inside the page.
const script = document.createElement("script");
script.text = `(${embeddedInit.toString()})();`;
document.documentElement.appendChild(script);

Because of this issue we can't use select-dom to select elements, I used document.querySelector

  • I've create new page detection called isConflict
export const isConflict = (): boolean => /^pull\/\d+\/conflicts/.test(getRepoPath());
  • I can't find any accurate way to listen for editor ready event, for now I've create 2 second timeout for that
function init() {
    setTimeout(() => {
    }, 2000);
}
  • I have no idea how to handle multiple files yet, I haven't test this
  • Most important, my code is dirty 😅 😅

Here is quick demo

Screen Shot 2019-03-24 at 9 47 59 PM

All 14 comments

👍 I would like to have options for choose left, choose right, choose both (left first), choose both (right first) similar to other merge tools. When you click one of these buttons, it would edit appropriately and remove the markers in all cases. What do you think?

P.S. Ideally, we would remember what the initial state was and the buttons would remain active after choosing an action and would allow you to click on the buttons again if you've changed your mind.

Instead of multiple buttons a drop-down similar to the Watch/Unwatch one could be added.

👍 to both ideas.

I would like to attempt this. Any tips for getting started?

@jorgegonzalez I'd start with installing the extension from source, looking into the code and then discuss the UI and UX here first before development and then start with something small and share a branch/PR here to get feedback.

I was thinking of implementing this the way VSCode does, adding a line above each conflict with the options to keep the current or incoming change, or both.

https://code.visualstudio.com/docs/editor/versioncontrol#_merge-conflicts

image

@jorgegonzalez Yeah, that would be a good way to do it.

@issuehunt has funded $60.00 to this issue.


I would like to attempt this.

Ok, I found a way to do this, but there are some problems and questions:

  • Could I add CodeMirror as develop dependency? because github use CodeMirror and features writes in Typescript.
  • I have to access CodeMirror object inside window, is this ok to do this?
// @ts-ignore
const CodeMirror = window.CodeMirror;
  • We can't access CodeMirror instance inside extension scope, so I forced to embed code inside the page.
const script = document.createElement("script");
script.text = `(${embeddedInit.toString()})();`;
document.documentElement.appendChild(script);

Because of this issue we can't use select-dom to select elements, I used document.querySelector

  • I've create new page detection called isConflict
export const isConflict = (): boolean => /^pull\/\d+\/conflicts/.test(getRepoPath());
  • I can't find any accurate way to listen for editor ready event, for now I've create 2 second timeout for that
function init() {
    setTimeout(() => {
    }, 2000);
}
  • I have no idea how to handle multiple files yet, I haven't test this
  • Most important, my code is dirty 😅 😅

Here is quick demo

Screen Shot 2019-03-24 at 9 47 59 PM

Develop dependency is fine, it doesn’t get bundled. Perhaps however there’s a lighter @types/codemirror package we can rely on

Injecting an unsafe script is probably the only way. You can use JSX to generate the script tag.

When I tried to do this, the injected “buttons” were removed by CodeMirror when I made any changes to the content. Does your method preserve them without having to regenerate them?

Thanks for checking in!

Thank you @bfred-it for the quick response
Could you tell me how to generate script tag with JSX?

When I tried to do this, the injected “buttons” were removed by CodeMirror when I made any changes to the content. Does your method preserve them without having to regenerate them?

I use CodeMirror widgets to generate actions and CodeMirror adds these actions for us.

Could you tell me how to generate script tag with JSX?

document.head.append(<script>{`(${embeddedInit.toString()})()`}</script>);

@sindresorhus has rewarded $54.00 to @farnabaz. See it on IssueHunt

  • :moneybag: Total deposit: $60.00
  • :tada: Repository reward(0%): $0.00
  • :wrench: Service fee(10%): $6.00
Was this page helpful?
0 / 5 - 0 ratings