~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

  • Committer: Andrew Bennetts
  • Date: 2010-01-11 02:07:30 UTC
  • mto: This revision was merged to the branch mainline in revision 4965.
  • Revision ID: andrew.bennetts@canonical.com-20100111020730-1dctpvfgburfrgkk
Defer checking for a repository in NotBranchError case until we format the error as a string. (test_smart currently fails)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1034
1034
        except errors.NotBranchError:
1035
1035
            return False
1036
1036
 
1037
 
    def has_repository(self):
1038
 
        """Tell if this bzrdir contains a repository.
1039
 
 
1040
 
        Note: if you're going to open the repository, you should just go ahead
1041
 
        and try, and not ask permission first.  (This method just opens the
1042
 
        repository and discards it, and that's somewhat expensive.)
1043
 
        """
1044
 
        try:
1045
 
            self.open_repository()
1046
 
            return True
1047
 
        except errors.NoRepositoryPresent:
1048
 
            return False
1049
 
 
1050
1037
    def has_workingtree(self):
1051
1038
        """Tell if this bzrdir contains a working tree.
1052
1039
 
1478
1465
        return not isinstance(self._format, format.__class__)
1479
1466
 
1480
1467
    def open_branch(self, unsupported=False, ignore_fallbacks=False):
1481
 
        """See BzrDir.open_branch.
1482
 
        
1483
 
        Note: Test for repository on failure is not required here as
1484
 
        BzrDirPreSplitOut always has a branch; if there's no branch,
1485
 
        then there's no BzrDirPreSplitOut and no repository.
1486
 
        """
 
1468
        """See BzrDir.open_branch."""
1487
1469
        from bzrlib.branch import BzrBranchFormat4
1488
1470
        format = BzrBranchFormat4()
1489
1471
        self._check_supported(format, unsupported)
1660
1642
 
1661
1643
    def get_branch_reference(self):
1662
1644
        """See BzrDir.get_branch_reference()."""
1663
 
        try:
1664
 
            from bzrlib.branch import BranchFormat
1665
 
            format = BranchFormat.find_format(self)
1666
 
            return format.get_reference(self)
1667
 
        except errors.NotBranchError, e:
1668
 
            # provide indication to the user if they're actually
1669
 
            # opening a repository (see bug 440952)
1670
 
            if self.has_repository():
1671
 
                raise errors.NotBranchError(path=e.path, detail='location is a repository')
1672
 
            raise e
 
1645
        from bzrlib.branch import BranchFormat
 
1646
        format = BranchFormat.find_format(self)
 
1647
        return format.get_reference(self)
1673
1648
 
1674
1649
    def get_branch_transport(self, branch_format):
1675
1650
        """See BzrDir.get_branch_transport()."""
1715
1690
            pass
1716
1691
        return self.transport.clone('checkout')
1717
1692
 
1718
 
    def has_repository(self):
1719
 
        """See BzrDir.has_repository()."""
1720
 
        from bzrlib.repository import RepositoryFormat
1721
 
        try:
1722
 
            RepositoryFormat.find_format(self)
1723
 
            return True
1724
 
        except errors.NoRepositoryPresent:
1725
 
            return False
1726
 
 
1727
1693
    def has_workingtree(self):
1728
1694
        """Tell if this bzrdir contains a working tree.
1729
1695
 
1777
1743
 
1778
1744
    def open_branch(self, unsupported=False, ignore_fallbacks=False):
1779
1745
        """See BzrDir.open_branch."""
1780
 
        try:
1781
 
            format = self.find_branch_format()
1782
 
            self._check_supported(format, unsupported)
1783
 
            return format.open(self, _found=True, ignore_fallbacks=ignore_fallbacks)
1784
 
        except errors.NotBranchError, e:
1785
 
            # provide indication to the user if they're actually
1786
 
            # opening a repository (see bug 440952)
1787
 
            if self.has_repository():
1788
 
                raise errors.NotBranchError(path=e.path, detail='location is a repository')
1789
 
            raise e
 
1746
        format = self.find_branch_format()
 
1747
        self._check_supported(format, unsupported)
 
1748
        return format.open(self, _found=True, ignore_fallbacks=ignore_fallbacks)
1790
1749
 
1791
1750
    def open_repository(self, unsupported=False):
1792
1751
        """See BzrDir.open_repository."""