/breezy/trunk

To get this branch, use:
bzr branch https://code.breezy-vcs.org/breezy/trunk

« back to all changes in this revision

Viewing changes to breezy/git/dir.py

Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
from .. import (
23
23
    branch as _mod_branch,
24
 
    errors as bzr_errors,
 
24
    errors as brz_errors,
25
25
    trace,
26
26
    osutils,
27
27
    urlutils,
58
58
        return None
59
59
 
60
60
    def set_default_stack_on(self, value):
61
 
        raise bzr_errors.BzrError("Cannot set configuration")
 
61
        raise brz_errors.BzrError("Cannot set configuration")
62
62
 
63
63
 
64
64
class GitControlDirFormat(ControlDirFormat):
122
122
 
123
123
    def _get_selected_ref(self, branch, ref=None):
124
124
        if ref is not None and branch is not None:
125
 
            raise bzr_errors.BzrError("can't specify both ref and branch")
 
125
            raise brz_errors.BzrError("can't specify both ref and branch")
126
126
        if ref is not None:
127
127
            return ref
128
128
        if branch is not None:
159
159
        # Create/update the result branch
160
160
        try:
161
161
            result = ControlDir.open_from_transport(target_transport)
162
 
        except bzr_errors.NotBranchError:
 
162
        except brz_errors.NotBranchError:
163
163
            result = cloning_format.initialize_on_transport(target_transport)
164
164
        source_branch = self.open_branch()
165
165
        source_repository = self.find_repository()
166
166
        try:
167
167
            result_repo = result.find_repository()
168
 
        except bzr_errors.NoRepositoryPresent:
 
168
        except brz_errors.NoRepositoryPresent:
169
169
            result_repo = result.create_repository()
170
170
        if stacked:
171
171
            raise _mod_branch.UnstackableBranchFormat(
231
231
            if result_dir.open_repository().make_working_trees():
232
232
                self.open_workingtree().clone(
233
233
                    result_dir, revision_id=revision_id)
234
 
        except (bzr_errors.NoWorkingTree, bzr_errors.NotLocalUrl):
 
234
        except (brz_errors.NoWorkingTree, brz_errors.NotLocalUrl):
235
235
            pass
236
236
 
237
237
        return result_dir
295
295
        push_result.stacked_on = None
296
296
        from .branch import GitBranch
297
297
        if isinstance(source, GitBranch) and lossy:
298
 
            raise bzr_errors.LossyPushToSameVCS(source.controldir, self)
 
298
            raise brz_errors.LossyPushToSameVCS(source.controldir, self)
299
299
        target = self.open_branch(name, nascent_ok=True)
300
300
        push_result.branch_push_result = source.push(
301
301
            target, overwrite=overwrite, stop_revision=revision_id,
346
346
            return transport._redirected_to(e.source, e.target)
347
347
        gitrepo = do_catching_redirections(_open, transport, redirected)
348
348
        if not gitrepo._controltransport.has('HEAD'):
349
 
            raise bzr_errors.NotBranchError(path=transport.base)
 
349
            raise brz_errors.NotBranchError(path=transport.base)
350
350
        return LocalGitDir(transport, gitrepo, self)
351
351
 
352
352
    def get_format_description(self):
371
371
            trace.note(redirection_notice)
372
372
            return transport._redirected_to(e.source, e.target)
373
373
        try:
374
 
            transport = do_catching_redirections(make_directory, transport,
375
 
                                                 redirected)
376
 
        except bzr_errors.FileExists:
 
374
            transport = do_catching_redirections(
 
375
                make_directory, transport, redirected)
 
376
        except brz_errors.FileExists:
377
377
            if not use_existing_dir:
378
378
                raise
379
 
        except bzr_errors.NoSuchFile:
 
379
        except brz_errors.NoSuchFile:
380
380
            if not create_prefix:
381
381
                raise
382
382
            transport.create_prefix()
397
397
    def supports_transport(self, transport):
398
398
        try:
399
399
            external_url = transport.external_url()
400
 
        except bzr_errors.InProcessTransport:
401
 
            raise bzr_errors.NotBranchError(path=transport.base)
 
400
        except brz_errors.InProcessTransport:
 
401
            raise brz_errors.NotBranchError(path=transport.base)
402
402
        return external_url.startswith("file:")
403
403
 
404
404
 
463
463
            self._git.refs.set_symbolic_ref(ref, target_branch.ref)
464
464
        else:
465
465
            try:
466
 
                target_path = target_transport.local_abspath('.')
467
 
            except bzr_errors.NotLocalUrl:
468
 
                raise bzr_errors.IncompatibleFormat(
 
466
                target_path = (
 
467
                    target_branch.controldir.control_transport.local_abspath(
 
468
                        '.'))
 
469
            except brz_errors.NotLocalUrl:
 
470
                raise brz_errors.IncompatibleFormat(
469
471
                    target_branch._format, self._format)
470
472
            # TODO(jelmer): Do some consistency checking across branches..
471
473
            self.control_transport.put_bytes(
483
485
                    continue
484
486
                break
485
487
            else:
486
 
                # Can't create a reference to something that is not a in a
487
 
                # repository.
488
 
                raise bzr_errors.IncompatibleFormat(
 
488
                # Can't create a reference to something that is not a in a repository.
 
489
                raise brz_errors.IncompatibleFormat(
489
490
                    self.set_branch_reference, self)
490
491
            self._git.refs.set_symbolic_ref(ref, target_ref)
491
492
 
506
507
                    params = {}
507
508
            try:
508
509
                commondir = self.control_transport.get_bytes('commondir')
509
 
            except bzr_errors.NoSuchFile:
 
510
            except brz_errors.NoSuchFile:
510
511
                base_url = self.user_url.rstrip('/')
511
512
            else:
512
513
                base_url = urlutils.local_path_to_url(
527
528
            return self.transport
528
529
        if isinstance(branch_format, LocalGitControlDirFormat):
529
530
            return self.transport
530
 
        raise bzr_errors.IncompatibleFormat(branch_format, self._format)
 
531
        raise brz_errors.IncompatibleFormat(branch_format, self._format)
531
532
 
532
533
    def get_repository_transport(self, format):
533
534
        if format is None:
534
535
            return self.transport
535
536
        if isinstance(format, LocalGitControlDirFormat):
536
537
            return self.transport
537
 
        raise bzr_errors.IncompatibleFormat(format, self._format)
 
538
        raise brz_errors.IncompatibleFormat(format, self._format)
538
539
 
539
540
    def get_workingtree_transport(self, format):
540
541
        if format is None:
541
542
            return self.transport
542
543
        if isinstance(format, LocalGitControlDirFormat):
543
544
            return self.transport
544
 
        raise bzr_errors.IncompatibleFormat(format, self._format)
 
545
        raise brz_errors.IncompatibleFormat(format, self._format)
545
546
 
546
547
    def open_branch(self, name=None, unsupported=False, ignore_fallbacks=None,
547
548
                    ref=None, possible_transports=None, nascent_ok=False):
550
551
        from .branch import LocalGitBranch
551
552
        ref = self._get_selected_ref(name, ref)
552
553
        if not nascent_ok and ref not in self._git.refs:
553
 
            raise bzr_errors.NotBranchError(self.root_transport.base,
554
 
                                            controldir=self)
 
554
            raise brz_errors.NotBranchError(
 
555
                self.root_transport.base, controldir=self)
555
556
        ref_chain, unused_sha = self._git.refs.follow(ref)
556
557
        if ref_chain[-1] == b'HEAD':
557
558
            controldir = self
563
564
        refname = self._get_selected_ref(name)
564
565
        if refname == b'HEAD':
565
566
            # HEAD can't be removed
566
 
            raise bzr_errors.UnsupportedOperation(
 
567
            raise brz_errors.UnsupportedOperation(
567
568
                self.destroy_branch, self)
568
569
        try:
569
570
            del self._git.refs[refname]
570
571
        except KeyError:
571
 
            raise bzr_errors.NotBranchError(self.root_transport.base,
572
 
                                            controldir=self)
 
572
            raise brz_errors.NotBranchError(
 
573
                self.root_transport.base, controldir=self)
573
574
 
574
575
    def destroy_repository(self):
575
 
        raise bzr_errors.UnsupportedOperation(self.destroy_repository, self)
 
576
        raise brz_errors.UnsupportedOperation(self.destroy_repository, self)
576
577
 
577
578
    def destroy_workingtree(self):
578
 
        raise bzr_errors.UnsupportedOperation(self.destroy_workingtree, self)
 
579
        raise brz_errors.UnsupportedOperation(self.destroy_workingtree, self)
579
580
 
580
581
    def destroy_workingtree_metadata(self):
581
 
        raise bzr_errors.UnsupportedOperation(
 
582
        raise brz_errors.UnsupportedOperation(
582
583
            self.destroy_workingtree_metadata, self)
583
584
 
584
585
    def needs_format_conversion(self, format=None):
587
588
    def open_repository(self):
588
589
        """'open' a repository for this dir."""
589
590
        if self.control_transport.has('commondir'):
590
 
            raise bzr_errors.NoRepositoryPresent(self)
 
591
            raise brz_errors.NoRepositoryPresent(self)
591
592
        return self._gitrepository_class(self)
592
593
 
593
594
    def has_workingtree(self):
600
601
            branch = self.open_branch(ref=b'HEAD', nascent_ok=True)
601
602
            return GitWorkingTree(self, repo, branch)
602
603
        loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
603
 
        raise bzr_errors.NoWorkingTree(loc)
 
604
        raise brz_errors.NoWorkingTree(loc)
604
605
 
605
606
    def create_repository(self, shared=False):
606
607
        from .repository import GitRepositoryFormat
607
608
        if shared:
608
 
            raise bzr_errors.IncompatibleFormat(
 
609
            raise brz_errors.IncompatibleFormat(
609
610
                GitRepositoryFormat(), self._format)
610
611
        return self.find_repository()
611
612
 
613
614
                      append_revisions_only=None, ref=None):
614
615
        refname = self._get_selected_ref(name, ref)
615
616
        if refname != b'HEAD' and refname in self._git.refs:
616
 
            raise bzr_errors.AlreadyBranchError(self.user_url)
 
617
            raise brz_errors.AlreadyBranchError(self.user_url)
617
618
        repo = self.open_repository()
618
619
        if refname in self._git.refs:
619
620
            ref_chain, unused_sha = self._git.refs.follow(
639
640
    def create_workingtree(self, revision_id=None, from_branch=None,
640
641
                           accelerator_tree=None, hardlink=False):
641
642
        if self._git.bare:
642
 
            raise bzr_errors.UnsupportedOperation(
 
643
            raise brz_errors.UnsupportedOperation(
643
644
                self.create_workingtree, self)
644
645
        if from_branch is None:
645
646
            from_branch = self.open_branch(nascent_ok=True)
668
669
        self._mode_check_done = True
669
670
        try:
670
671
            st = self.transport.stat('.')
671
 
        except bzr_errors.TransportNotPossible:
 
672
        except brz_errors.TransportNotPossible:
672
673
            self._dir_mode = None
673
674
            self._file_mode = None
674
675
        else:
708
709
    def _find_commondir(self):
709
710
        try:
710
711
            commondir = self.control_transport.get_bytes('commondir')
711
 
        except bzr_errors.NoSuchFile:
 
712
        except brz_errors.NoSuchFile:
712
713
            return self
713
714
        else:
714
715
            commondir = commondir.rstrip(b'/.git/').decode(osutils._fs_enc)