+14
-4
README.md
+14
-4
README.md
···
12
12
```golang
13
13
patch, err := os.Open("changes.patch")
14
14
if err != nil {
15
-
log.Fatalf(err)
15
+
log.Fatal(err)
16
16
}
17
17
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
18
20
files, preamble, err := gitdiff.Parse(patch)
19
21
if err != nil {
20
-
log.Fatalf(err)
22
+
log.Fatal(err)
21
23
}
22
24
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
+
}
25
35
```
26
36
27
37
## Development Status