@@ -356,6 +356,78 @@ public void CanCompareTwoVersionsOfAFileWithADiffOfTwoHunks()
356356 }
357357 }
358358
359+ [ Fact ]
360+ public void CanHandleTwoTreeEntryChangesWithTheSamePath ( )
361+ {
362+ SelfCleaningDirectory scd = BuildSelfCleaningDirectory ( ) ;
363+
364+ using ( Repository repo = Repository . Init ( scd . DirectoryPath ) )
365+ {
366+ Blob mainContent = CreateBlob ( repo , "awesome content\n " ) ;
367+ Blob linkContent = CreateBlob ( repo , "../../objc/Nu.h" ) ;
368+
369+ string path = string . Format ( "include{0}Nu{0}Nu.h" , Path . DirectorySeparatorChar ) ;
370+
371+ var tdOld = new TreeDefinition ( )
372+ . Add ( path , linkContent , Mode . SymbolicLink )
373+ . Add ( "objc/Nu.h" , mainContent , Mode . NonExecutableFile ) ;
374+
375+ Tree treeOld = repo . ObjectDatabase . CreateTree ( tdOld ) ;
376+
377+ var tdNew = new TreeDefinition ( )
378+ . Add ( path , mainContent , Mode . NonExecutableFile ) ;
379+
380+ Tree treeNew = repo . ObjectDatabase . CreateTree ( tdNew ) ;
381+
382+ TreeChanges changes = repo . Diff . Compare ( treeOld , treeNew ) ;
383+
384+ /*
385+ * $ git diff-tree -p 5c87b67 d5278d0
386+ * diff --git a/include/Nu/Nu.h b/include/Nu/Nu.h
387+ * deleted file mode 120000
388+ * index 19bf568..0000000
389+ * --- a/include/Nu/Nu.h
390+ * +++ /dev/null
391+ * @@ -1 +0,0 @@
392+ * -../../objc/Nu.h
393+ * \ No newline at end of file
394+ * diff --git a/include/Nu/Nu.h b/include/Nu/Nu.h
395+ * new file mode 100644
396+ * index 0000000..f9e6561
397+ * --- /dev/null
398+ * +++ b/include/Nu/Nu.h
399+ * @@ -0,0 +1 @@
400+ * +awesome content
401+ * diff --git a/objc/Nu.h b/objc/Nu.h
402+ * deleted file mode 100644
403+ * index f9e6561..0000000
404+ * --- a/objc/Nu.h
405+ * +++ /dev/null
406+ * @@ -1 +0,0 @@
407+ * -awesome content
408+ */
409+
410+ Assert . Equal ( 1 , changes . Deleted . Count ( ) ) ;
411+ Assert . Equal ( 0 , changes . Modified . Count ( ) ) ;
412+ Assert . Equal ( 1 , changes . TypeChanged . Count ( ) ) ;
413+
414+ TreeEntryChanges change = changes [ path ] ;
415+ Assert . Equal ( Mode . SymbolicLink , change . OldMode ) ;
416+ Assert . Equal ( Mode . NonExecutableFile , change . Mode ) ;
417+ Assert . Equal ( ChangeKind . TypeChanged , change . Status ) ;
418+ Assert . Equal ( path , change . Path ) ;
419+ }
420+ }
421+
422+ private static Blob CreateBlob ( Repository repo , string content )
423+ {
424+ using ( var stream = new MemoryStream ( Encoding . UTF8 . GetBytes ( content ) ) )
425+ using ( var binReader = new BinaryReader ( stream ) )
426+ {
427+ return repo . ObjectDatabase . CreateBlob ( binReader ) ;
428+ }
429+ }
430+
359431 [ Fact ]
360432 public void CanCompareATreeAgainstANullTree ( )
361433 {
0 commit comments