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

Patches for files without newline at the end are not appliable by git apply #936

Closed
distorhead opened this issue Aug 28, 2018 · 4 comments
Closed
Labels
bug hacktoberfest Ready to pick for Hacktoberfest

Comments

@distorhead
Copy link

Go-git generates broken diff-s for files without newline at the end. These patches cannot be applied by git apply command.

Original git diff command will generate patch with special line \ No newline at end of file marker.

Here is repo with example program in main.go: https://github.com/flant/go-git-test-2.

git clone https://github.com/flant/go-git-test-2 /tmp/go-git-test-2
cd /tmp/go-git-test-2
go build ./main.go
./main > bad.patch
git checkout c73fd0c6d5669affde76a78c60e4cc372d39abc1
git apply bad.patch

Gives:

error: patch failed: README.md:1
error: README.md: patch does not apply
@smola smola added the bug label Sep 6, 2018
distorhead added a commit to werf/werf that referenced this issue 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 issue 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
Copy link
Author

distorhead commented Sep 27, 2018

Found workaround: use git apply --inaccurate-eof.

@smola smola added the hacktoberfest Ready to pick for Hacktoberfest label Oct 2, 2018
@nclandrei
Copy link

Hi @distorhead! Can I start work on this? 🙂

@distorhead
Copy link
Author

Hi! Sure, I does not have any code contributions for this, unfortunately.

@ZerooCool
Copy link

With PHP, JavaScript and CSS file, i use PHP-CodeSniffer
Work good to format with the PSR-2 standard + 1 end line
Then, i don't have this message : "No newline at end of file"

PHP-CodeSniffer :
https://wiki.visionduweb.fr/index.php?title=Sommaire_des_tutoriels_pour_developpeur#Php-codeSniffer

mcuadros added a commit that referenced this issue Oct 15, 2019
format: diff, Handle no newline at end of file. Fixes #936
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug hacktoberfest Ready to pick for Hacktoberfest
Projects
None yet
Development

No branches or pull requests

4 participants