Correct Go get command in document
1 file changed
tree: 1410e637e6ef88ec5a80015dd9ec0d3c0e0d518a
  1. .gitignore
  2. diffparser.go
  3. diffparser_test.go
  4. example.diff
  5. glide.lock
  6. glide.yaml
  7. LICENSE.md
  8. README.md
README.md

DiffParser

DiffParser is a Golang package which parse's a git diff.

Install

go get github.com/waigani/diffparser

Usage Example

package main

import (
	"fmt"
	"github.com/waigani/diffparser"
)

// error handling left out for brevity
func main() {
	byt, _ := ioutil.ReadFile("example.diff")
	diff, _ := diffparser.Parse(string(byt))

	// You now have a slice of files from the diff,
	file := diff.Files[0]

	// diff hunks in the file,
	hunk := file.Hunks[0]

	// new and old ranges in the hunk
	newRange := hunk.NewRange

	// and lines in the ranges.
	line := newRange.Lines[0]
}

More Examples

See diffparser_test.go for further examples.