@@ -677,3 +677,69 @@ def test_reset_reset_failure(mock_repo):
677
677
mock_repo .head .reset .side_effect = git .GitCommandError ('reset' , '' )
678
678
with pytest .raises (exceptions .ResetException ):
679
679
repo .branch .hard_reset (refresh = False )
680
+
681
+
682
+ def test_local_branch_exists (mock_repo ):
683
+ """
684
+ GIVEN GitRepo is initialized with a path and repo
685
+ WHEN branch.exists is called with a valid branch and None remote
686
+ THEN True is returned
687
+ """
688
+ repo = GitRepo (repo = mock_repo )
689
+ mock_repo .branches = ["master" , "test" ]
690
+
691
+ assert repo .branch .exists ("test" ) is True
692
+
693
+
694
+ def test_local_branch_doesnt_exist (mock_repo ):
695
+ """
696
+ GIVEN GitRepo is initialized with a path and repo
697
+ WHEN branch.exists is called with an invalid branch and None remote
698
+ THEN False is returned
699
+ """
700
+ repo = GitRepo (repo = mock_repo )
701
+ mock_repo .branches = ["master" , "test" ]
702
+
703
+ assert repo .branch .exists ("another-test" ) is False
704
+
705
+
706
+ def test_branch_exists_with_invalid_remote (mock_repo ):
707
+ """
708
+ GIVEN GitRepo is initialized with a path and repo
709
+ WHEN branch.exists is called with a valid branch and invalid remote
710
+ THEN a RemoteException is raised
711
+ """
712
+ repo = GitRepo (repo = mock_repo )
713
+
714
+ with pytest .raises (exceptions .RemoteException ):
715
+ assert repo .branch .exists ("another" , "doesntexist" )
716
+
717
+
718
+ def test_remote_branch_exists (mock_repo ):
719
+ """
720
+ GIVEN GitRepo is initialized with a path and repo
721
+ WHEN branch.exists is called with a valid branch and valid remote
722
+ THEN True is returned
723
+ """
724
+ repo = GitRepo (repo = mock_repo )
725
+
726
+ remote = Mock (spec = git .Remote )
727
+ remote .configure_mock (name = "testremote" , refs = ["testbranch" ])
728
+ mock_repo .remotes .extend ([remote ])
729
+
730
+ assert repo .branch .exists ("testbranch" , "testremote" ) is True
731
+
732
+
733
+ def test_remote_branch_doesnt_exists (mock_repo ):
734
+ """
735
+ GIVEN GitRepo is initialized with a path and repo
736
+ WHEN branch.exists is called with an invalid branch and valid remote
737
+ THEN True is returned
738
+ """
739
+ repo = GitRepo (repo = mock_repo )
740
+
741
+ remote = Mock (spec = git .Remote )
742
+ remote .configure_mock (name = "testremote" , refs = [])
743
+ mock_repo .remotes .extend ([remote ])
744
+
745
+ assert repo .branch .exists ("testbranch" , "testremote" ) is False
0 commit comments