File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -12,16 +12,26 @@ aims to parse anything accepted by the `git apply` command.
1212``` golang
1313patch , err := os.Open (" changes.patch" )
1414if err != nil {
15- log.Fatalf (err)
15+ log.Fatal (err)
1616}
1717
18+ // files is a slice of *gitdiff.File describing the files changed in the patch
19+ // preamble is a string of the content of the patch before the first file
1820files , preamble , err := gitdiff.Parse (patch)
1921if err != nil {
20- log.Fatalf (err)
22+ log.Fatal (err)
2123}
2224
23- // files is a slice of *gitdiff.File describing the files changed in the patch
24- // preamble is a string of the content of the patch before the first file
25+ code , err := os.Open (" code.go" )
26+ if err != nil {
27+ log.Fatal (err)
28+ }
29+
30+ // apply the changes in the patch to a source file
31+ var output bytes.Buffer
32+ if err := gitdiff.NewApplier (code).ApplyFile (&output, files[0 ]); err != nil {
33+ log.Fatal (err)
34+ }
2535```
2636
2737## Development Status
You can’t perform that action at this time.
0 commit comments