@@ -215,20 +215,29 @@ func parseDiffStat(stdout string) (numFiles, totalAdditions, totalDeletions int,
215
215
}
216
216
217
217
// GetDiffOrPatch generates either diff or formatted patch data between given revisions
218
- func (repo * Repository ) GetDiffOrPatch (base , head string , w io.Writer , formatted bool ) error {
219
- if formatted {
218
+ func (repo * Repository ) GetDiffOrPatch (base , head string , w io.Writer , patch , binary bool ) error {
219
+ if patch {
220
220
return repo .GetPatch (base , head , w )
221
221
}
222
+ if binary {
223
+ return repo .GetDiffBinary (base , head , w )
224
+ }
222
225
return repo .GetDiff (base , head , w )
223
226
}
224
227
225
- // GetDiff generates and returns patch data between given revisions.
228
+ // GetDiff generates and returns patch data between given revisions, optimized for human readability
226
229
func (repo * Repository ) GetDiff (base , head string , w io.Writer ) error {
230
+ return NewCommand ("diff" , "-p" , base , head ).
231
+ RunInDirPipeline (repo .Path , w , nil )
232
+ }
233
+
234
+ // GetDiffBinary generates and returns patch data between given revisions, including binary diffs.
235
+ func (repo * Repository ) GetDiffBinary (base , head string , w io.Writer ) error {
227
236
return NewCommand ("diff" , "-p" , "--binary" , base , head ).
228
237
RunInDirPipeline (repo .Path , w , nil )
229
238
}
230
239
231
- // GetPatch generates and returns format-patch data between given revisions.
240
+ // GetPatch generates and returns format-patch data between given revisions, able to be used with `git apply`
232
241
func (repo * Repository ) GetPatch (base , head string , w io.Writer ) error {
233
242
stderr := new (bytes.Buffer )
234
243
err := NewCommand ("format-patch" , "--binary" , "--stdout" , base + "..." + head ).
@@ -246,8 +255,7 @@ func (repo *Repository) GetDiffFromMergeBase(base, head string, w io.Writer) err
246
255
err := NewCommand ("diff" , "-p" , "--binary" , base + "..." + head ).
247
256
RunInDirPipeline (repo .Path , w , stderr )
248
257
if err != nil && bytes .Contains (stderr .Bytes (), []byte ("no merge base" )) {
249
- return NewCommand ("diff" , "-p" , "--binary" , base , head ).
250
- RunInDirPipeline (repo .Path , w , nil )
258
+ return repo .GetDiffBinary (base , head , w )
251
259
}
252
260
return err
253
261
}
0 commit comments