modulepackage
0.0.0-20190828052634-7391f219313d
Repository: https://github.com/waigani/diffparser.git
Documentation: pkg.go.dev
# README
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.
# Functions
Parse takes a diff, such as produced by "git diff", and parses it into a Diff struct.
# Constants
ADDED if the line is added (shown green in diff).
DELETED if the file is deleted.
MODIFIED if the file is modified.
NEW if the file is created and there is no diff.
REMOVED if the line is deleted (shown red in diff).
UNCHANGED if the line is unchanged (not colored in diff).
# Type aliases
DiffLineMode tells the line if added, removed or unchanged.
FileMode represents the file status in a diff.