Skip to content

diff breaks for patches #196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gudmundur opened this issue Nov 28, 2014 · 7 comments
Closed

diff breaks for patches #196

gudmundur opened this issue Nov 28, 2014 · 7 comments
Assignees
Milestone

Comments

@gudmundur
Copy link

If a commit contains a .patch, the parsing logic for https://github.com/schacon/ruby-git/blob/master/lib/git/diff.rb#L132 fails. It'll start reporting, for example: type: '-deleted'. The patch in a diff will be printed out as -deleted file mode 100644.

To reproduce, try committing https://github.com/isaacs/readable-stream/blob/master/float.patch and do repo.diff(prev_commit, head_commit)

@robertodecurnex robertodecurnex added this to the 1.2.9 milestone Nov 28, 2014
@robertodecurnex robertodecurnex self-assigned this Nov 28, 2014
@robertodecurnex
Copy link
Contributor

Is there any public repo to reproduce this?

Working good locally so far. The only way to get the deleted type would be to use head_commit as first param and prev_commit as second.

Can you try to set the HEAD to the sha where the file was first created and run a diff like this:
repo.diff('HEAD^', 'HEAD')

That would be bulletproof. Your Git version would be useful too.

Does a command line git diff prev_commit head_commit works as expected ?

@gudmundur
Copy link
Author

Sorry for not including steps to reproduce, but here you go:

$ git clone https://github.com/isaacs/readable-stream
$ cd readable-stream
$ irb
irb> require 'git'
irb> repo = Git.open('.')
irb> diff = repo.diff('5aec72b01618ddfc46ad09cdbc66dc8d26211e52', 'c49f6387e8de23dd8da96b513037ca99800014c3')
irb> diff.map(&:type)
[ ..., "+deleted", ... ]

@robertodecurnex
Copy link
Contributor

Funny (?) cuz yours is just the tip of the iceberg.

Any file line, within any kind of file, containing \bfilemode\b.{6} will modify the previously value of the type and mode.

Also, any line containing index\b.{7}\.\..{7} will also modify src, dst and even the mode in some cases.

It's weird that an small validation (that does not prevent mode from been overwritten) has been added for the later scenario, but just for mode:

final[current_file][:mode] = m[3].strip if m[3]

I'll create some tests. I think we can easily prevent problems
* Improving the regexps just a little bit
* Protecting those values if they are already set

Ideally the parsing logic should be improved to detect context and forget about specifics within those.

Working on it....

@robertodecurnex
Copy link
Contributor

Damn, you can even "create files" that do not even exist by adding/having lines following diff --git a\/(.*?) b\/(.*?)

Basically .patch files, logs, or things like that can create tons of invalid diff entires if they are included. in the diff output.

@robertodecurnex
Copy link
Contributor

Opening a new issue for a general refactor of the thing.

Anyways, all the previously listed scenarios should be fixed.

@robertodecurnex
Copy link
Contributor

Tests e55f3bd

othatbrian pushed a commit to othatbrian/ruby-git that referenced this issue Dec 8, 2014
@gudmundur
Copy link
Author

Thanks @robertodecurnex. Verified it works on my end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants