Clone this repo:
  1. 7391f21 Merge pull request #19 from waigani/17-replace-juju-testing by Nathan Leiby · 9 months ago master
  2. 5209429 use stretcher/testify instead of juju/testing by Nathan Leiby · 9 months ago 17-replace-juju-testing
  3. 79c8f4e Merge pull request #16 from nakabonne/public-diffRange by Nathan Leiby · 10 months ago
  4. 3eca51b Make diffRange public by Ryo Nakao · 10 months ago
  5. 1f7065f Merge pull request #15 from isacikgoz/add_doc_and_go_mod by Nathan Leiby · 1 year, 1 month ago

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.