Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Fix fatal: corrupt patch error in unified diff format#932

Merged
mcuadros merged 1 commit intosrc-d:masterfrom
werf:fix-negative-range-info
Sep 10, 2018
Merged

Fix fatal: corrupt patch error in unified diff format#932
mcuadros merged 1 commit intosrc-d:masterfrom
werf:fix-negative-range-info

Conversation

@distorhead
Copy link
Copy Markdown

There may be negative number in the range of unified diff. Negative number occurs when patch changes for example first or second line of file. Bug related to ContextLines number.

Demonstration repo and program to generate wrong patch available here:

https://github.com/flant/go-git-test/

Resulting patch:

diff --git a/README.md b/README.md
index 94954abda49de8615a048f8d2e64b5de848e27a1..f3dad9514629b9ff9136283ae331ad1fc95748a8 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +-1,2 @@
 hello
-world
+bug

+-1,2 causes git apply to complain:

fatal: corrupt patch at line 5

@mcuadros
Copy link
Copy Markdown
Contributor

Can you provide a test? Thanks

distorhead added a commit to werf/werf that referenced this pull request Sep 6, 2018
Go-git experiment failed for now.

There is blocking issue to continue use go-git:
 * Corrupt patch generation for files without newline-at-the-end: src-d/go-git#936

And some non-blocking, but harmful:
 * Memory usage is too big on big repos: src-d/go-git#832.
 * Corrupt patch generation (solved in fork): src-d/go-git#932.

Libgit2 is too complex to install or statically build into dapp. Also libgit2 has memory leaks.

The decision is to use raw git command in a clean and efficient way.

Implemented Diff operation.
distorhead added a commit to werf/werf that referenced this pull request Sep 6, 2018
Go-git experiment failed for now.

There is blocking issue to continue use go-git:
 * Corrupt patch generation for files without newline-at-the-end: src-d/go-git#936

And some non-blocking, but harmful:
 * Memory usage is too big on big repos: src-d/go-git#832
 * Corrupt patch generation (solved in fork): src-d/go-git#932

Libgit2 is too complex to install or statically build into dapp. Also libgit2 has memory leaks.

The decision is to use raw git command in a clean and efficient way.

Implemented Diff operation.
@mcuadros
Copy link
Copy Markdown
Contributor

mcuadros commented Sep 6, 2018

@ajnavarro PTAL

@ajnavarro
Copy link
Copy Markdown
Contributor

@mcuadros the change looks good to me, but I will appreciate a test for it.

Signed-off-by: Antonio Jesus Navarro Perez <[email protected]>
@mcuadros mcuadros merged commit a2d62f5 into src-d:master Sep 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants