Merge pull request #15 from isacikgoz/add_doc_and_go_mod

Add doc and go mod
tree: 7a24c8c6d4fd3aa9075b7c69c5609f63d85dd661
  1. .gitignore
  2. diffparser.go
  3. diffparser_test.go
  4. example.diff
  5. go.mod
  6. go.sum
  7. Gopkg.lock
  8. Gopkg.toml
  9. LICENSE.md
  10. README.md
README.md

DiffParser

GoDoc

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.