Skip to content

apply: git_apply_to_tree fails to apply patches that add new files#5208

Merged
ethomson merged 3 commits into
libgit2:masterfrom
mkostyuk:apply-removed-new-file
Aug 27, 2019
Merged

apply: git_apply_to_tree fails to apply patches that add new files#5208
ethomson merged 3 commits into
libgit2:masterfrom
mkostyuk:apply-removed-new-file

Conversation

@mkostyuk

Copy link
Copy Markdown
Contributor

git_apply_to_tree() cannot be used to apply patches with new files.

An attempt to apply such a patch fails because git_apply_to_tree() tries to
remove a non-existing file from an old index.

The solution is to modify git_apply_to_tree() to git_index_remove() when the
patch states that the modified files is removed.

git_apply_to_tree() cannot be used apply patches with new files. An attempt
to apply such a patch fails because git_apply_to_tree() tries to remove a
non-existing file from an old index.

The solution is to modify git_apply_to_tree() to git_index_remove() when the
patch states that the modified files is removed.
@ethomson

Copy link
Copy Markdown
Member

This definitely makes sense and looks correct. We should have a test that exercises this, though.

Introduce an unit test to validate if git_apply_to_tree() fails when an
applied patch adds new files.
@mkostyuk

Copy link
Copy Markdown
Contributor Author

Hi Edward. Could you please check if the test case is okay? It looks okay for me, but maybe I missed something obvious. Thank you.

@ethomson

Copy link
Copy Markdown
Member

I added a commit to free the index - there was a bit of a memory leak, but everything else looks ok!

@ethomson ethomson merged commit 5fc27aa into libgit2:master Aug 27, 2019
@mkostyuk

Copy link
Copy Markdown
Contributor Author

Thank you.

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

Successfully merging this pull request may close these issues.

3 participants