Skip to content

apply fails to handle diffs with files without newline or patches that remove newline at end of the file #57

Closed
@fzakaria

Description

@fzakaria

I encountered this issue via aspect-build/rules_lint#487

tl;dr; If a file is missing a newline at the end or the patch removes the newline at the end, go-gitdiff fails applying the patch with the error:

conflict: fragment line does not match src line

I'll push a reproduction example through a failed test, where git succeeds.

> git apply gitdiff/testdata/apply/file_text_modify.patch
> echo $?
0
> go test ./...
--- FAIL: TestApplyFile (0.00s)
    --- FAIL: TestApplyFile/textModify (0.00s)
        apply_test.go:190: unexpected error applying: at 4: fragment 1 at 5: conflict: fragment line does not match src line
FAIL
FAIL    github.com/bluekeyes/go-gitdiff/gitdiff 0.321s
FAIL

The offending check can be found

func applyTextLine(dst io.Writer, line Line, preimage [][]byte, i int64) (err error) {

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions