Merge pull request #19 from waigani/17-replace-juju-testing

use stretcher/testify instead of juju/testing
tree: 063d725ac04614dd291e2ae786401f21582e60a4
  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.