Clone this repo:

Branches

  1. 6c001f4 Merge pull request #11 from ragurney/AddGoDocBadge by Nathan Leiby · 9 days ago master
  2. 62f355f Add godoc badge by Ryan Gurney · 9 days ago
  3. 8ef6bf9 Merge pull request #10 from ledongthuc/patch-1 by Nathan Leiby · 6 months ago
  4. 8c25e6b Correct Go get command in document by Thuc Le · 6 months ago
  5. 503023b Merge pull request #9 from nathanleiby/master by Nathan Leiby · 10 months 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.