~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/push.py

  • Committer: Jelmer Vernooij
  • Date: 2009-02-03 15:48:02 UTC
  • mto: (3978.3.6 branch-bzrdir-inter)
  • mto: This revision was merged to the branch mainline in revision 4250.
  • Revision ID: jelmer@samba.org-20090203154802-niup4xrso35yba65
Move most of push to IterGenericBranchBzrDir.

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 bzrlib import (builtins, bzrdir, errors, revision as _mod_revision,
 
19
from bzrlib import (builtins, branch, bzrdir, errors, revision as _mod_revision,
20
20
                    transport)
21
21
from bzrlib.trace import note, warning
22
22
 
48
48
        dir_to = bzrdir.BzrDir.open_from_transport(to_transport)
49
49
    except errors.NotBranchError:
50
50
        pass # Didn't find anything
51
 
    else:
52
 
        # If we can open a branch, use its direct repository, otherwise see
53
 
        # if there is a repository without a branch.
54
 
        try:
55
 
            br_to = dir_to.open_branch()
56
 
        except errors.NotBranchError:
57
 
            # Didn't find a branch, can we find a repository?
58
 
            try:
59
 
                repository_to = dir_to.find_repository()
60
 
            except errors.NoRepositoryPresent:
61
 
                pass
62
 
        else:
63
 
            # Found a branch, so we must have found a repository
64
 
            repository_to = br_to.repository
65
51
 
66
52
    push_result = None
67
53
    if dir_to is None:
116
102
                 finally_stacked_on)
117
103
        else:
118
104
            note('Created new branch.')
119
 
        # We successfully created the target, remember it
120
 
        if br_from.get_push_location() is None or remember:
121
 
            br_from.set_push_location(br_to.base)
122
 
    elif repository_to is None:
123
 
        # we have a bzrdir but no branch or repository
124
 
        # XXX: Figure out what to do other than complain.
125
 
        raise errors.BzrCommandError("At %s you have a valid .bzr control"
126
 
            " directory, but not a branch or repository. This is an"
127
 
            " unsupported configuration. Please move the target directory"
128
 
            " out of the way and try again."
129
 
            % location)
130
 
    elif br_to is None:
131
 
        # We have a repository but no branch, copy the revisions, and then
132
 
        # create a branch.
 
105
    else:
133
106
        if stacked_on is not None:
134
107
            warning("Ignoring request for a stacked branch as repository "
135
108
                    "already exists at the destination location.")
136
 
        repository_to.fetch(br_from.repository, revision_id=revision_id)
137
 
        br_to = br_from.clone(dir_to, revision_id=revision_id)
138
 
        note('Created new branch.')
139
 
        if br_from.get_push_location() is None or remember:
140
 
            br_from.set_push_location(br_to.base)
141
 
    else: # We have a valid to branch
142
 
        if stacked_on is not None:
143
 
            warning("Ignoring request for a stacked branch as branch "
144
 
                    "already exists at the destination location.")
145
 
        # We were able to connect to the remote location, so remember it.
146
 
        # (We don't need to successfully push because of possible divergence.)
147
 
        if br_from.get_push_location() is None or remember:
148
 
            br_from.set_push_location(br_to.base)
 
109
        inter = branch.InterBranchBzrDir.get(br_from, dir_to)
149
110
        try:
150
 
            try:
151
 
                tree_to = dir_to.open_workingtree()
152
 
            except errors.NotLocalUrl:
153
 
                warning("This transport does not update the working " 
154
 
                        "tree of: %s. See 'bzr help working-trees' for "
155
 
                        "more information." % br_to.base)
156
 
                push_result = br_from.push(br_to, overwrite,
157
 
                                           stop_revision=revision_id)
158
 
            except errors.NoWorkingTree:
159
 
                push_result = br_from.push(br_to, overwrite,
160
 
                                           stop_revision=revision_id)
161
 
            else:
162
 
                tree_to.lock_write()
163
 
                try:
164
 
                    push_result = br_from.push(tree_to.branch, overwrite,
165
 
                                               stop_revision=revision_id)
166
 
                    tree_to.update()
167
 
                finally:
168
 
                    tree_to.unlock()
 
111
            push_result = inter.push(revision_id=revision_id, 
 
112
                overwrite=overwrite)
 
113
        except errors.NoRepositoryPresent:
 
114
            # we have a bzrdir but no branch or repository
 
115
            # XXX: Figure out what to do other than complain.
 
116
            raise errors.BzrCommandError("At %s you have a valid .bzr control"
 
117
                " directory, but not a branch or repository. This is an"
 
118
                " unsupported configuration. Please move the target directory"
 
119
                " out of the way and try again."
 
120
                % location)
169
121
        except errors.DivergedBranches:
170
122
            raise errors.BzrCommandError('These branches have diverged.'
171
123
                                    '  Try using "merge" and then "push".')
 
124
        if not push_result.workingtree_updated:
 
125
            warning("This transport does not update the working " 
 
126
                    "tree of: %s. See 'bzr help working-trees' for "
 
127
                    "more information." % push_result.target_branch.base)
 
128
 
 
129
        # We successfully pushed, remember it
 
130
        if push_result.source_branch.get_push_location() is None or remember:
 
131
            push_result.source_branch.set_push_location(push_result.target_branch.base)
 
132
 
172
133
    if push_result is not None:
173
134
        push_result.report(to_file)
174
135
        old_revid = push_result.old_revid
175
136
        old_revno = push_result.old_revno
 
137
        br_to = push_result.target_branch
176
138
    else:
177
139
        old_revid = _mod_revision.NULL_REVISION
178
140
        old_revno = 0