1.0.0 • Published 5 years ago

conflict-diff-parser v1.0.0

Weekly downloads
11
License
MIT
Repository
github
Last release
5 years ago

Javascript parser for git diff conflict

Based on kuychaco/what-the-diff

Installation

conflict-diff-parser is available via npm

npm install conflict-diff-parser

Or with Yarn

yarn add conflict-diff-parser

Usage

const { parse } = require('conflict-diff-parser');

const diff = `diff --cc test_merge
index 2e54b0b,cdc021b..0000000
--- a/test_merge
+++ b/test_merge
@@@ -1,2 -1,2 +1,6 @@@
++<<<<<<< HEAD
+This line will chganed cause of typo
++=======
+ This line will be changed because of the typo
++>>>>>>> test_merge`

parse(diff)

// returns

{
  old_file_name: 'a/test_merge',
  new_file_name: 'b/test_merge',
  filePath: 'test_merge',
  status: 'unmerged',
  header: {
    ourStartLine: 1,
    ourLineCount: 2,
    theirStartLine: 1,
    theirLineCount: 6,
    baseStartLine: 1,
    baseLineCount: 2,
    heading: '',
  },
  hunks: [
    {
      header: '++<<<<<<< HEAD',
      ours: [
        'This line will chganed cause of typo',
      ],
      separator: '++=======',
      theirs: [
        'This line will be changed because of the typo',
      ],
      footer: '++>>>>>>> test_merge',
    },
  ],
}

Works only for when there is a conflict, else will throw an error