+2
-2
.github/workflows/go.yml
+2
-2
.github/workflows/go.yml
+38
-37
.golangci.yml
+38
-37
.golangci.yml
···
1
run:
2
tests: false
3
4
linters:
5
-
disable-all: true
6
enable:
7
- errcheck
8
-
- gofmt
9
-
- goimports
10
- govet
11
- ineffassign
12
- misspell
13
- revive
14
-
- typecheck
15
- unconvert
16
- unused
17
18
-
issues:
19
-
exclude-use-default: false
20
-
21
-
linters-settings:
22
-
errcheck:
23
-
exclude-functions:
24
-
- (*github.com/bluekeyes/go-gitdiff/gitdiff.formatter).Write
25
-
- (*github.com/bluekeyes/go-gitdiff/gitdiff.formatter).WriteString
26
-
- (*github.com/bluekeyes/go-gitdiff/gitdiff.formatter).WriteByte
27
-
- fmt.Fprintf(*github.com/bluekeyes/go-gitdiff/gitdiff.formatter)
28
-
goimports:
29
-
local-prefixes: github.com/bluekeyes/go-gitdiff
30
-
revive:
31
-
rules:
32
-
# enable all rules from golint
33
-
- name: context-keys-type
34
-
- name: time-naming
35
-
- name: var-declaration
36
-
- name: unexported-return
37
-
- name: errorf
38
-
- name: blank-imports
39
-
- name: context-as-argument
40
-
- name: dot-imports
41
-
- name: error-return
42
-
- name: error-strings
43
-
- name: error-naming
44
-
- name: exported
45
-
- name: increment-decrement
46
-
- name: var-naming
47
-
- name: package-comments
48
-
- name: range
49
-
- name: receiver-naming
50
-
- name: indent-error-flow
···
1
+
version: "2"
2
+
3
run:
4
tests: false
5
6
linters:
7
+
default: none
8
enable:
9
- errcheck
10
- govet
11
- ineffassign
12
- misspell
13
- revive
14
- unconvert
15
- unused
16
+
settings:
17
+
errcheck:
18
+
exclude-functions:
19
+
- (*github.com/bluekeyes/go-gitdiff/gitdiff.formatter).Write
20
+
- (*github.com/bluekeyes/go-gitdiff/gitdiff.formatter).WriteString
21
+
- (*github.com/bluekeyes/go-gitdiff/gitdiff.formatter).WriteByte
22
+
- fmt.Fprintf(*github.com/bluekeyes/go-gitdiff/gitdiff.formatter)
23
+
revive:
24
+
rules:
25
+
- name: context-keys-type
26
+
- name: time-naming
27
+
- name: var-declaration
28
+
- name: unexported-return
29
+
- name: errorf
30
+
- name: blank-imports
31
+
- name: context-as-argument
32
+
- name: dot-imports
33
+
- name: error-return
34
+
- name: error-strings
35
+
- name: error-naming
36
+
- name: exported
37
+
- name: increment-decrement
38
+
- name: var-naming
39
+
- name: package-comments
40
+
- name: range
41
+
- name: receiver-naming
42
+
- name: indent-error-flow
43
44
+
formatters:
45
+
enable:
46
+
- gofmt
47
+
- goimports
48
+
settings:
49
+
goimports:
50
+
local-prefixes:
51
+
- github.com/bluekeyes/go-gitdiff
+1
-1
README.md
+1
-1
README.md
···
4
5
A Go library for parsing and applying patches generated by `git diff`, `git
6
show`, and `git format-patch`. It can also parse and apply unified diffs
7
-
generated by the standard `diff` tool.
8
9
It supports standard line-oriented text patches and Git binary patches, and
10
aims to parse anything accepted by the `git apply` command.
···
4
5
A Go library for parsing and applying patches generated by `git diff`, `git
6
show`, and `git format-patch`. It can also parse and apply unified diffs
7
+
generated by the standard GNU `diff` tool.
8
9
It supports standard line-oriented text patches and Git binary patches, and
10
aims to parse anything accepted by the `git apply` command.
+1
gitdiff/apply_test.go
+1
gitdiff/apply_test.go
···
22
"changeStart": {Files: getApplyFiles("text_fragment_change_start")},
23
"changeMiddle": {Files: getApplyFiles("text_fragment_change_middle")},
24
"changeEnd": {Files: getApplyFiles("text_fragment_change_end")},
25
"changeExact": {Files: getApplyFiles("text_fragment_change_exact")},
26
"changeSingleNoEOL": {Files: getApplyFiles("text_fragment_change_single_noeol")},
27
···
22
"changeStart": {Files: getApplyFiles("text_fragment_change_start")},
23
"changeMiddle": {Files: getApplyFiles("text_fragment_change_middle")},
24
"changeEnd": {Files: getApplyFiles("text_fragment_change_end")},
25
+
"changeEndEOL": {Files: getApplyFiles("text_fragment_change_end_eol")},
26
"changeExact": {Files: getApplyFiles("text_fragment_change_exact")},
27
"changeSingleNoEOL": {Files: getApplyFiles("text_fragment_change_single_noeol")},
28
+11
-4
gitdiff/binary.go
+11
-4
gitdiff/binary.go
···
50
}
51
52
func (p *parser) ParseBinaryMarker() (isBinary bool, hasData bool, err error) {
53
-
switch p.Line(0) {
54
-
case "GIT binary patch\n":
55
hasData = true
56
-
case "Binary files differ\n":
57
-
case "Files differ\n":
58
default:
59
return false, false, nil
60
}
···
63
return false, false, err
64
}
65
return true, hasData, nil
66
}
67
68
func (p *parser) ParseBinaryFragmentHeader() (*BinaryFragment, error) {
···
50
}
51
52
func (p *parser) ParseBinaryMarker() (isBinary bool, hasData bool, err error) {
53
+
line := p.Line(0)
54
+
switch {
55
+
case line == "GIT binary patch\n":
56
hasData = true
57
+
case isBinaryNoDataMarker(line):
58
default:
59
return false, false, nil
60
}
···
63
return false, false, err
64
}
65
return true, hasData, nil
66
+
}
67
+
68
+
func isBinaryNoDataMarker(line string) bool {
69
+
if strings.HasSuffix(line, " differ\n") {
70
+
return strings.HasPrefix(line, "Binary files ") || strings.HasPrefix(line, "Files ")
71
+
}
72
+
return false
73
}
74
75
func (p *parser) ParseBinaryFragmentHeader() (*BinaryFragment, error) {
+10
gitdiff/binary_test.go
+10
gitdiff/binary_test.go
···
25
IsBinary: true,
26
HasData: false,
27
},
28
+
"binaryFileNoPatchPaths": {
29
+
Input: "Binary files a/foo.bin and b/foo.bin differ\n",
30
+
IsBinary: true,
31
+
HasData: false,
32
+
},
33
+
"fileNoPatch": {
34
+
Input: "Files differ\n",
35
+
IsBinary: true,
36
+
HasData: false,
37
+
},
38
"textFile": {
39
Input: "@@ -10,14 +22,31 @@\n",
40
IsBinary: false,
+5
-1
gitdiff/format.go
+5
-1
gitdiff/format.go
···
169
170
if f.IsBinary {
171
if f.BinaryFragment == nil {
172
+
fm.WriteString("Binary files ")
173
+
fm.WriteQuotedName("a/" + aName)
174
+
fm.WriteString(" and ")
175
+
fm.WriteQuotedName("b/" + bName)
176
+
fm.WriteString(" differ\n")
177
} else {
178
fm.WriteString("GIT binary patch\n")
179
fm.FormatBinaryFragment(f.BinaryFragment)
+1
gitdiff/format_roundtrip_test.go
+1
gitdiff/format_roundtrip_test.go
+13
gitdiff/patch_header.go
+13
gitdiff/patch_header.go
···
52
// line, that line will be removed and everything after it will be
53
// placed in BodyAppendix.
54
BodyAppendix string
55
}
56
57
// Message returns the commit message for the header. The message consists of
···
237
break
238
}
239
240
switch {
241
case strings.HasPrefix(line, authorPrefix):
242
u, err := ParsePatchIdentity(line[len(authorPrefix):])
···
361
}
362
363
h := &PatchHeader{}
364
365
if strings.HasPrefix(mailLine, mailHeaderPrefix) {
366
mailLine = strings.TrimPrefix(mailLine, mailHeaderPrefix)
···
52
// line, that line will be removed and everything after it will be
53
// placed in BodyAppendix.
54
BodyAppendix string
55
+
56
+
// All headers completely unparsed
57
+
RawHeaders map[string][]string
58
}
59
60
// Message returns the commit message for the header. The message consists of
···
240
break
241
}
242
243
+
items := strings.SplitN(line, ":", 2)
244
+
245
+
// we have "key: value"
246
+
if len(items) == 2 {
247
+
key := items[0]
248
+
val := items[1]
249
+
h.RawHeaders[key] = append(h.RawHeaders[key], val)
250
+
}
251
+
252
switch {
253
case strings.HasPrefix(line, authorPrefix):
254
u, err := ParsePatchIdentity(line[len(authorPrefix):])
···
373
}
374
375
h := &PatchHeader{}
376
+
h.RawHeaders = msg.Header
377
378
if strings.HasPrefix(mailLine, mailHeaderPrefix) {
379
mailLine = strings.TrimPrefix(mailLine, mailHeaderPrefix)
+10
gitdiff/testdata/apply/text_fragment_change_end_eol.patch
+10
gitdiff/testdata/apply/text_fragment_change_end_eol.patch
···
···
1
+
diff --git a/gitdiff/testdata/apply/text_fragment_remove_last_eol.src b/gitdiff/testdata/apply/text_fragment_remove_last_eol.src
2
+
index a92d664..8cf2f17 100644
3
+
--- a/gitdiff/testdata/apply/text_fragment_remove_last_eol.src
4
+
+++ b/gitdiff/testdata/apply/text_fragment_remove_last_eol.src
5
+
@@ -1,3 +1,3 @@
6
+
line 1
7
+
line 2
8
+
-line 3
9
+
+line 3
10
+
\ No newline at end of file