libgit2 / libgit2sharp

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

Make GIT_DIFF_SHOW_BINARY flag settable by users through CompareOptions #1967

Open jburggraaf opened 2 years ago

jburggraaf commented 2 years ago

Addresses Bug#1966 Scenario:

Need to create a patch file that contains binary deltas using Diff.Compare<T> function. This is needed for binary files to be created/updated when calling git apply using the generated patch file.

Effort:

The necessary flag already existed in Core.GitDiff.GitDiffOptionFlags (GIT_DIFF_SHOW_BINARY) and some quick research showed that this flag is recognized by the libgit2 library. To give library users access to this flag I added it as a property of the CompareOptions class (ShowBinary) defaults false and maintains current expected functionality. Finally checking the value of CompareOptions.ShowBinary in the function Diff.BuildOptions so that the options are populated with this flag before being passed through to libgit2

Outcome:

If an instance of CompareOptions with the ShowBinary flag set to true is passed to any overload of Diff.Compare<Patch> that takes CompareOptions as a parameter, the resulting patch will have the necessary delta to create/update binary files when it is applied.

Testing:

Added 2 test scenarios:

  1. confirm that the default behaviour for binaries has not changed.
  2. confirm that if the ShowBinary flag is set to true that the diff contains delta information as expected

ran the full test suite to verify nothing was broken by this change.