libgit2 / libgit2sharp

Git + .NET = ❤
http://libgit2.github.com
MIT License
3.13k stars 879 forks source link

Getting patch with unicode characters confuses git apply #1974

Open tapika opened 2 years ago

tapika commented 2 years ago
var patches = repo0.Diff.Compare<Patch>(commit1?.Tree, commit2.Tree, Enumerable.Repeat(change.Path, 1), compareOptions: compareOptions);

Getting patches + applying them to file does not seems to work if there are unicode characters in file itself.

Have tried to save it in utf8, but problem still persists.

As a walkaround to this problem, I have added extra comparison that there aren't any unicode characters.

// If we have some unicode characters, then cannot be handled as text diff.
canBeHandledAsTextPatch = strpatches.All(c => c <= 255);

But, libgit itself has built in support for patching, See https://libgit2.org/libgit2/#HEAD, git_apply* function calls - but none of these operations seems to be supported in libgit2sharp.

jburggraaf commented 2 years ago

hi @tapika looks like a similiar issue to mine There is no way to make Diff Patch contain any binary deltas. I've submitted a PR !1967.