@@ -874,6 +874,72 @@ private Commit AddFileCommitToRepo(IRepository repository, string filename, stri
874874 return repository . Commit ( "New commit" , Constants . Signature , Constants . Signature ) ;
875875 }
876876
877+
878+ [ Theory ]
879+ [ InlineData ( "master" , MergeAnalysis . Unborn | MergeAnalysis . FastForward , true ) ]
880+ [ InlineData ( "fast_forward" , MergeAnalysis . Normal | MergeAnalysis . FastForward , false ) ]
881+ [ InlineData ( "conflicts" , MergeAnalysis . Normal , false ) ]
882+
883+ public void CanAnalyzeMerge ( string branchName , MergeAnalysis analysis , bool makeUnborn )
884+ {
885+ string path = SandboxMergeTestRepo ( ) ;
886+ using ( var repo = new Repository ( path ) )
887+ {
888+ if ( makeUnborn )
889+ {
890+ repo . Refs . UpdateTarget ( "HEAD" , "refs/heads/unborn" ) ;
891+ }
892+
893+ // test both Commit and Reference overload
894+ MergeAnalysisResult result = repo . AnalyzeMerge ( repo . Branches [ branchName ] . Tip ) ;
895+ MergeAnalysisResult result2 = repo . AnalyzeMerge ( repo . Refs [ "refs/heads/" + branchName ] ) ;
896+
897+ Assert . Equal ( analysis , result . Analysis ) ;
898+ Assert . Equal ( analysis , result2 . Analysis ) ;
899+ }
900+ }
901+
902+ [ Theory ]
903+ [ InlineData ( "false" , MergePreference . NoFastForward ) ]
904+ [ InlineData ( "only" , MergePreference . FastForwardOnly ) ]
905+ [ InlineData ( null , MergePreference . Default ) ]
906+ public void CanRetrieveMergePreference ( string value , MergePreference preference )
907+ {
908+ string path = SandboxMergeTestRepo ( ) ;
909+ using ( var repo = new Repository ( path ) )
910+ {
911+ if ( value != null )
912+ {
913+ repo . Config . Set ( "merge.ff" , value ) ;
914+ }
915+
916+ // it doesn't matter too much which branch we ask about, we want the preference
917+ MergeAnalysisResult result = repo . AnalyzeMerge ( repo . Branches [ "fast_forward" ] . Tip ) ;
918+
919+ Assert . Equal ( preference , result . Preference ) ;
920+ }
921+ }
922+
923+ [ Fact ]
924+ public void CanAnalyzeFastForward ( )
925+ {
926+ string path = SandboxMergeTestRepo ( ) ;
927+ using ( var repo = new Repository ( path ) )
928+ {
929+ // test both Commit and Reference overload
930+ MergeAnalysisResult result = repo . AnalyzeMerge ( repo . Branches [ "fast_forward" ] . Tip ) ;
931+ MergeAnalysisResult result2 = repo . AnalyzeMerge ( repo . Refs [ "refs/heads/fast_forward" ] ) ;
932+
933+ Assert . True ( result . Analysis . HasFlag ( MergeAnalysis . FastForward ) ) ;
934+ Assert . True ( result . Analysis . HasFlag ( MergeAnalysis . Normal ) ) ;
935+ Assert . False ( result . Analysis . HasFlag ( MergeAnalysis . Unborn ) ) ;
936+ Assert . False ( result . Analysis . HasFlag ( MergeAnalysis . UpToDate ) ) ;
937+
938+ Assert . Equal ( result , result2 ) ;
939+ }
940+ }
941+
942+
877943 // Commit IDs of the checked in merge_testrepo
878944 private const string masterBranchInitialId = "83cebf5389a4adbcb80bda6b68513caee4559802" ;
879945 private const string fastForwardBranchInitialId = "4dfaa1500526214ae7b33f9b2c1144ca8b6b1f53" ;
0 commit comments