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

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

Merged
merged 1 commit into from
Sep 10, 2018
Merged

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

merged 1 commit into from
Sep 10, 2018

Conversation

distorhead
Copy link

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
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
Contributor

mcuadros commented Sep 6, 2018

@ajnavarro PTAL

@ajnavarro
Copy link
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