/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/push.py

  • Committer: Jelmer Vernooij
  • Date: 2020-03-22 01:35:14 UTC
  • mfrom: (7490.7.6 work)
  • mto: This revision was merged to the branch mainline in revision 7499.
  • Revision ID: jelmer@jelmer.uk-20200322013514-7vw1ntwho04rcuj3
merge lp:brz/3.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""UI helper for the push command."""
18
18
 
19
 
from __future__ import absolute_import
20
 
 
21
19
from . import (
22
20
    branch as _mod_branch,
23
21
    controldir,
52
50
        if self.branch_push_result is None:
53
51
            if self.stacked_on is not None:
54
52
                note(gettext('Created new stacked branch referring to %s.') %
55
 
                    self.stacked_on)
 
53
                     self.stacked_on)
56
54
            else:
57
55
                note(gettext('Created new branch.'))
58
56
        else:
60
58
 
61
59
 
62
60
def _show_push_branch(br_from, revision_id, location, to_file, verbose=False,
63
 
    overwrite=False, remember=False, stacked_on=None, create_prefix=False,
64
 
    use_existing_dir=False, no_tree=False):
 
61
                      overwrite=False, remember=False, stacked_on=None, create_prefix=False,
 
62
                      use_existing_dir=False, no_tree=False, lossy=False):
65
63
    """Push a branch to a location.
66
64
 
67
65
    :param br_from: the source branch
79
77
        at the destination if they don't already exist
80
78
    :param use_existing_dir: if True, proceed even if the destination
81
79
        directory exists without a current control directory in it
 
80
    :param lossy: Allow lossy push
82
81
    """
83
 
    to_transport = transport.get_transport(location)
 
82
    to_transport = transport.get_transport(location, purpose='write')
84
83
    try:
85
84
        dir_to = controldir.ControlDir.open_from_transport(to_transport)
86
85
    except errors.NotBranchError:
90
89
    if dir_to is None:
91
90
        try:
92
91
            br_to = br_from.create_clone_on_transport(to_transport,
93
 
                revision_id=revision_id, stacked_on=stacked_on,
94
 
                create_prefix=create_prefix, use_existing_dir=use_existing_dir,
95
 
                no_tree=no_tree)
96
 
        except errors.AlreadyControlDirError as err:
 
92
                                                      revision_id=revision_id, stacked_on=stacked_on,
 
93
                                                      create_prefix=create_prefix, use_existing_dir=use_existing_dir,
 
94
                                                      no_tree=no_tree)
 
95
        except errors.AlreadyControlDirError:
97
96
            raise errors.BzrCommandError(gettext(
98
97
                "Target directory %s already contains a .bzr directory, "
99
98
                "but it is not valid.") % (location,))
100
 
        except errors.FileExists as err:
 
99
        except errors.FileExists:
101
100
            if not use_existing_dir:
102
101
                raise errors.BzrCommandError(gettext("Target directory %s"
103
 
                     " already exists, but does not have a .bzr"
104
 
                     " directory. Supply --use-existing-dir to push"
105
 
                     " there anyway.") % location)
 
102
                                                     " already exists, but does not have a .bzr"
 
103
                                                     " directory. Supply --use-existing-dir to push"
 
104
                                                     " there anyway.") % location)
106
105
            # This shouldn't occur, but if it does the FileExists error will be
107
106
            # more informative than an UnboundLocalError for br_to.
108
107
            raise
109
108
        except errors.NoSuchFile:
110
109
            if not create_prefix:
111
110
                raise errors.BzrCommandError(gettext("Parent directory of %s"
112
 
                    " does not exist."
113
 
                    "\nYou may supply --create-prefix to create all"
114
 
                    " leading parent directories.")
115
 
                    % location)
 
111
                                                     " does not exist."
 
112
                                                     "\nYou may supply --create-prefix to create all"
 
113
                                                     " leading parent directories.")
 
114
                                             % location)
116
115
            # This shouldn't occur (because create_prefix is true, so
117
116
            # create_clone_on_transport should be catching NoSuchFile and
118
117
            # creating the missing directories) but if it does the original
121
120
            raise
122
121
        except errors.TooManyRedirections:
123
122
            raise errors.BzrCommandError(gettext("Too many redirections trying "
124
 
                                         "to make %s.") % location)
 
123
                                                 "to make %s.") % location)
125
124
        push_result = PushResult()
126
125
        # TODO: Some more useful message about what was copied
127
126
        try:
135
134
        push_result.old_revno = 0
136
135
        # Remembers if asked explicitly or no previous location is set
137
136
        if (remember
138
 
            or (remember is None and br_from.get_push_location() is None)):
 
137
                or (remember is None and br_from.get_push_location() is None)):
139
138
            # FIXME: Should be done only if we succeed ? -- vila 2012-01-18
140
139
            br_from.set_push_location(br_to.base)
141
140
    else:
143
142
            warning("Ignoring request for a stacked branch as repository "
144
143
                    "already exists at the destination location.")
145
144
        try:
146
 
            push_result = dir_to.push_branch(br_from, revision_id, overwrite, 
147
 
                remember, create_prefix)
 
145
            push_result = dir_to.push_branch(br_from, revision_id, overwrite,
 
146
                                             remember, create_prefix, lossy=lossy)
148
147
        except errors.DivergedBranches:
149
148
            raise errors.BzrCommandError(gettext('These branches have diverged.'
150
 
                                    '  See "brz help diverged-branches"'
151
 
                                    ' for more information.'))
 
149
                                                 '  See "brz help diverged-branches"'
 
150
                                                 ' for more information.'))
152
151
        except errors.NoRoundtrippingSupport as e:
153
 
            raise errors.BzrCommandError(gettext("It is not possible to losslessly "
154
 
                "push to %s. You may want to use dpush instead.") % 
155
 
                    e.target_branch.mapping.vcs.abbreviation)
 
152
            raise errors.BzrCommandError(
 
153
                gettext("It is not possible to losslessly "
 
154
                        "push to %s. You may want to use --lossy.") %
 
155
                e.target_branch.mapping.vcs.abbreviation)
156
156
        except errors.NoRepositoryPresent:
157
157
            # we have a controldir but no branch or repository
158
158
            # XXX: Figure out what to do other than complain.
159
159
            raise errors.BzrCommandError(gettext("At %s you have a valid .bzr"
160
 
                " control directory, but not a branch or repository. This"
161
 
                " is an unsupported configuration. Please move the target"
162
 
                " directory out of the way and try again.") % location)
163
 
        if push_result.workingtree_updated == False:
164
 
            warning("This transport does not update the working " 
 
160
                                                 " control directory, but not a branch or repository. This"
 
161
                                                 " is an unsupported configuration. Please move the target"
 
162
                                                 " directory out of the way and try again.") % location)
 
163
        if push_result.workingtree_updated is False:
 
164
            warning("This transport does not update the working "
165
165
                    "tree of: %s. See 'brz help working-trees' for "
166
166
                    "more information." % push_result.target_branch.base)
167
167
    push_result.report(to_file)
168
168
    if verbose:
169
169
        br_to = push_result.target_branch
170
 
        br_to.lock_read()
171
 
        try:
 
170
        with br_to.lock_read():
172
171
            from .log import show_branch_change
173
 
            show_branch_change(br_to, to_file, push_result.old_revno, 
 
172
            show_branch_change(br_to, to_file, push_result.old_revno,
174
173
                               push_result.old_revid)
175
 
        finally:
176
 
            br_to.unlock()
177
 
 
178