@@ -492,25 +492,30 @@ fn process_change(
492492 ( None , new_change)
493493 }
494494 ( false , true ) => {
495- * offset_in_destination += added. end - added. start ;
496- * offset_in_destination -= number_of_lines_deleted;
497-
498495 // <-------> (hunk)
499496 // <------> (added)
500497 // <---> (blamed)
501498 // <--> (new hunk)
502- new_hunks_to_blame. push ( UnblamedHunk :: new (
503- ( added. end + 1 ) ..hunk. range_in_blamed_file . end ,
504- Offset :: Added ( hunk. range_in_destination . start - hunk. range_in_blamed_file . start ) ,
505- ) ) ;
506499
507500 lines_blamed. push ( BlameEntry :: with_offset (
508501 hunk. range_in_destination . start ..added. end ,
509502 suspect,
510- * offset_in_destination ,
503+ hunk . offset ( ) ,
511504 ) ) ;
512505
513- ( None , None )
506+ * offset_in_destination += added. end - added. start ;
507+ * offset_in_destination -= number_of_lines_deleted;
508+
509+ let new_hunk = if hunk. range_in_destination . end > added. end {
510+ Some ( UnblamedHunk :: from_destination (
511+ added. end ..hunk. range_in_destination . end ,
512+ hunk. offset ( ) ,
513+ ) )
514+ } else {
515+ None
516+ } ;
517+
518+ ( new_hunk, None )
514519 }
515520 ( false , false ) => {
516521 // Any of the following cases are handled by this branch:
@@ -1355,6 +1360,37 @@ fn process_change_works_added_hunk_8() {
13551360 assert_eq ! ( offset_in_destination, Offset :: Added ( 2 ) ) ;
13561361}
13571362
1363+ #[ test]
1364+ fn process_change_works_added_hunk_9 ( ) {
1365+ let mut lines_blamed: Vec < BlameEntry > = vec ! [ ] ;
1366+ let mut new_hunks_to_blame: Vec < UnblamedHunk > = vec ! [ ] ;
1367+ let mut offset_in_destination: Offset = Offset :: Added ( 0 ) ;
1368+ let suspect = ObjectId :: null ( gix_hash:: Kind :: Sha1 ) ;
1369+
1370+ let ( hunk, change) = process_change (
1371+ & mut lines_blamed,
1372+ & mut new_hunks_to_blame,
1373+ & mut offset_in_destination,
1374+ suspect,
1375+ // range_in_destination: 21..22
1376+ Some ( UnblamedHunk :: new ( 23 ..24 , Offset :: Added ( 2 ) ) ) ,
1377+ Some ( Change :: Added ( 18 ..22 , 3 ) ) ,
1378+ ) ;
1379+
1380+ assert_eq ! ( hunk, None ) ;
1381+ assert_eq ! ( change, None ) ;
1382+ assert_eq ! (
1383+ lines_blamed,
1384+ vec![ BlameEntry {
1385+ range_in_blamed_file: 23 ..24 ,
1386+ range_in_original_file: 21 ..22 ,
1387+ commit_id: suspect
1388+ } ]
1389+ ) ;
1390+ assert_eq ! ( new_hunks_to_blame, vec![ ] ) ;
1391+ assert_eq ! ( offset_in_destination, Offset :: Added ( 1 ) ) ;
1392+ }
1393+
13581394#[ test]
13591395fn process_change_works_no_overlap ( ) {
13601396 let mut lines_blamed: Vec < BlameEntry > = vec ! [ ] ;
0 commit comments