A tool for developer to parse output of git diff command.
- diff: A parser that parse output of git diff command to struct diff.
package main
import (
"github.com/lower-coder/go-git-diff/diff"
)
const diffText = `diff --git a/file1 b/file1
index 504d2a1..50ccec3 100644
--- a/file1
+++ b/file1
@@ -1,4 +1,4 @@
+add a line
some
lines
-in
file1`
func main() {
d := diff.NewDiff()
d.Parse(diffText)
}
/*
{
"files": [
{
"mode": 2,
"input": {
"source": "a/file1",
"target": "b/file1"
},
"metas": [
{
"meta_type": "index",
"content": "504d2a1..50ccec3 100644"
}
],
"legends": [
{
"mark": "---",
"content": "a/file1"
},
{
"mark": "+++",
"content": "b/file1"
}
],
"chunks": [
{
"source_range": {
"start": 1,
"length": 4,
"lines": [
{
"mode": 1,
"number": 1,
"content": "some"
},
{
"mode": 1,
"number": 2,
"content": "lines"
},
{
"mode": 3,
"number": 3,
"content": "in"
},
{
"mode": 1,
"number": 4,
"content": "file1"
}
]
},
"target_range": {
"start": 1,
"length": 4,
"lines": [
{
"mode": 2,
"number": 1,
"content": "add a line"
},
{
"mode": 1,
"number": 2,
"content": "some"
},
{
"mode": 1,
"number": 3,
"content": "lines"
},
{
"mode": 1,
"number": 4,
"content": "file1"
}
]
}
}
]
}
]
}
*/