diff options
author | Max Kostyukevich <maxim.kostyukevich@mera.com> | 2019-08-20 03:29:45 +0300 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2020-03-26 16:20:11 +0100 |
commit | d6e5c44f28f96386aa2d6e8b82ca58a0335d340e (patch) | |
tree | f55f3d70515a15e7816aba55b0ca261d087bf1a9 | |
parent | 30cd1e1f89c838b6f523b31d1c2f2d1b85310613 (diff) | |
download | libgit2-d6e5c44f28f96386aa2d6e8b82ca58a0335d340e.tar.gz |
apply: git_apply_to_tree fails to apply patches that add new files
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.
-rw-r--r-- | src/apply.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/apply.c b/src/apply.c index 4d25eff7f..3ec63f2fb 100644 --- a/src/apply.c +++ b/src/apply.c @@ -642,9 +642,12 @@ int git_apply_to_tree( for (i = 0; i < git_diff_num_deltas(diff); i++) { delta = git_diff_get_delta(diff, i); - if ((error = git_index_remove(postimage, - delta->old_file.path, 0)) < 0) - goto done; + if (delta->status == GIT_DELTA_DELETED || + delta->status == GIT_DELTA_RENAMED) { + if ((error = git_index_remove(postimage, + delta->old_file.path, 0)) < 0) + goto done; + } } if ((error = apply_deltas(repo, pre_reader, NULL, post_reader, postimage, diff, &opts)) < 0) |