libgit2 / libgit2/libgit2

`git_diff_from_buffer` fails to parse a diff file containing an empty file

Open
#5,713 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
10.6k
Forks
2.7k
PR merge metrics
No merged PRs in 30d

Description

Reproduction steps:
Calling git_diff_from_buffer when the diff file contains deletion/creation of an empty file.
Call git_diff_from_buffer with the following diff file:

diff --git a/patchFolder/deleteFile.txt b/patchFolder/deleteFile.txt
deleted file mode 100644
index e69de29..0000000
diff --git a/patchFolder/modifyFile.txt b/patchFolder/modifyFile.txt
index ce01362..14be0d4 100644
--- a/patchFolder/modifyFile.txt
+++ b/patchFolder/modifyFile.txt
@@ -1 +1 @@
-hello
+hello2

Same happens with:

diff --git a/emptyfile2 b/emptyfile2
new file mode 100644
index 0000000..e69de29

Expected behavior:
Proper git_diff object. Command line version of git has no problem with the diff file.
Actual behavior:
Error code -1, git_diff null.

Version of libgit2 (release number or SHA1)
1.1.0-1
Operating system(s) tested
Arch linux

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the git_diff_from_buffer entry point and reproduce the supplied deletion and creation diffs for empty files. Compare the result with the non-empty-file diff behavior; done means both empty-file cases return a proper git_diff object instead of error code -1 and null.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, git
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.