@@ -1177,12 +1177,16 @@ func (repoDataLoader *RepoDataLoader) DiffStage(statusType StatusType) (diff *Di
1177
1177
diff = & Diff {}
1178
1178
1179
1179
rawDiff , err := repoDataLoader .generateRawDiff (statusType )
1180
+ if err != nil {
1181
+ if diffErrorRegex .MatchString (err .Error ()) {
1182
+ log .Infof ("Falling back to git cli after encountering error: %v" , err )
1183
+ repoDataLoader .diffErrorPresent = true
1184
+ return repoDataLoader .generateStageDiffUsingCLI (statusType )
1185
+ }
1180
1186
1181
- if err != nil && diffErrorRegex .MatchString (err .Error ()) {
1182
- log .Infof ("Falling back to git cli after encountering error: %v" , err )
1183
- repoDataLoader .diffErrorPresent = true
1184
- return repoDataLoader .generateStageDiffUsingCLI (statusType )
1185
- } else if err != nil || rawDiff == nil {
1187
+ return
1188
+ } else if rawDiff == nil {
1189
+ err = fmt .Errorf ("Failed to generate diff for %v files" , StatusTypeDisplayName (statusType ))
1186
1190
return
1187
1191
}
1188
1192
defer rawDiff .Free ()
@@ -1201,11 +1205,16 @@ func (repoDataLoader *RepoDataLoader) DiffFile(statusType StatusType, path strin
1201
1205
diff = & Diff {}
1202
1206
1203
1207
rawDiff , err := repoDataLoader .generateRawDiff (statusType )
1204
- if err != nil && diffErrorRegex .MatchString (err .Error ()) {
1205
- log .Infof ("Falling back to git cli after encountering error: %v" , err )
1206
- repoDataLoader .diffErrorPresent = true
1207
- return repoDataLoader .generateFileDiffUsingCLI (statusType , path )
1208
- } else if err != nil || rawDiff == nil {
1208
+ if err != nil {
1209
+ if diffErrorRegex .MatchString (err .Error ()) {
1210
+ log .Infof ("Falling back to git cli after encountering error: %v" , err )
1211
+ repoDataLoader .diffErrorPresent = true
1212
+ return repoDataLoader .generateFileDiffUsingCLI (statusType , path )
1213
+ }
1214
+
1215
+ return
1216
+ } else if rawDiff == nil {
1217
+ err = fmt .Errorf ("Failed to generate diff for %v file %v" , StatusTypeDisplayName (statusType ), path )
1209
1218
return
1210
1219
}
1211
1220
defer rawDiff .Free ()
@@ -1249,13 +1258,12 @@ func (repoDataLoader *RepoDataLoader) DiffFile(statusType StatusType, path strin
1249
1258
func (repoDataLoader * RepoDataLoader ) generateRawDiff (statusType StatusType ) (rawDiff * git.Diff , err error ) {
1250
1259
var index * git.Index
1251
1260
var options git.DiffOptions
1261
+ var head Ref
1262
+ var commit * Commit
1263
+ var tree * git.Tree
1252
1264
1253
1265
switch statusType {
1254
1266
case StStaged :
1255
- var head Ref
1256
- var commit * Commit
1257
- var tree * git.Tree
1258
-
1259
1267
if head , err = repoDataLoader .Head (); err != nil {
1260
1268
return
1261
1269
}
@@ -1291,6 +1299,26 @@ func (repoDataLoader *RepoDataLoader) generateRawDiff(statusType StatusType) (ra
1291
1299
if rawDiff , err = repoDataLoader .repo .DiffIndexToWorkdir (index , & options ); err != nil {
1292
1300
return
1293
1301
}
1302
+ case StConflicted :
1303
+ if head , err = repoDataLoader .Head (); err != nil {
1304
+ return
1305
+ }
1306
+
1307
+ if commit , err = repoDataLoader .Commit (head .Oid ()); err != nil {
1308
+ return
1309
+ }
1310
+
1311
+ if tree , err = commit .commit .Tree (); err != nil {
1312
+ return
1313
+ }
1314
+
1315
+ if options , err = git .DefaultDiffOptions (); err != nil {
1316
+ return
1317
+ }
1318
+
1319
+ if rawDiff , err = repoDataLoader .repo .DiffTreeToWorkdir (tree , & options ); err != nil {
1320
+ return
1321
+ }
1294
1322
}
1295
1323
1296
1324
return
0 commit comments