0
 |    get_symlink_target(change.path[1])
                    try:
                        self.upload_symlink(change.path[1], target)
                    except errors.TransportNotPossible:
                        if not self.quiet:
                            self.outf.write('Not uploading symlink %s -> %s\n'
                                            % (change.path[1], target))
                else:
                    raise NotImplementedError

            # XXX: Add a test for exec_change
            for change in changes.modified:
                if self.is_ignored(change.path[1]):
                    if not self.quiet:
                        self.outf.write('Ignoring %s\n' % change.path[1])
                    continue
                if change.kind[1] == 'file':
                    self.upload_file(change.path[1], change.path[1])
                elif change.kind[1] == 'symlink':
                    target = self.tree.get_symlink_target(change.path[1])
                    self.upload_symlink(change.path[1], target)
                else:
                    raise NotImplementedError

            self.set_uploaded_revid(self.rev_id)


class CannotUploadToWorkingTree(errors.CommandError):

    _fmt = 'Cannot upload to a bzr managed working tree: %(url)s".'


class DivergedUploadedTree(errors.CommandError):

    _fmt = ("Your branch (%(revid)s)"
            " and the uploaded tree (%(uploaded_revid)s) have diverged: ")


class cmd_upload(commands.Command):
    """Upload a working tree, as a whole or incrementally.

    If no destination is specified use the last one used.
    If no revision is specified upload the changes since the last upload.

    Changes include files added, renamed, modified or removed.
    """
    _see_also = ['plugins/upload']
    takes_args = ['location?']
    takes_options = [
        'revision',
        'remember',
        'overwrite',
        option.Option('full', 'Upload the full working tree.'),
        option.Option('quiet', 'Do not output what is being done.',
                      short_name='q'),
        option.Option('directory',
                      help='Branch to upload from, '
                      'rather than the one containing the working directory.',
                      short_name='d',
                      type=str,
                      ),
        option.Option('auto',
                      'Trigger an upload from this branch whenever the tip '
                      'revision changes.')
        ]

    def run(self, location=None, full=False, revision=None, remember=None,
            directory=None, quiet=False, auto=None, overwrite=False
            ):
        if directory is None:
            directory = '.'

        (wt, branch,
         relpath) = controldir.ControlDir.open_containing_tree_or_branch(
             directory)

        if wt:
            locked = wt
        else:
            locked = branch
        with locked.lock_read():
            if wt:
                changes = wt.changes_from(wt.basis_tree())

                if revision is None and changes.has_changed():
                    raise errors.UncommittedChanges(wt)

            conf = branch.get_config_stack()
            if location is None:
                stored_loc = conf.get('upload_location')
                if stored_loc is None:
                    raise errors.CommandError(
                        'No upload location known or specified.')
                else:
                    # FIXME: Not currently tested
                    display_url = urlutils.unescape_for_display(stored_loc,
                                                                self.outf.encoding)
                    self.outf.write("Using saved location: %s\n" % display_url)
                    location = stored_loc

            to_transport = transport.get_transport(location)

            # Check that we are not uploading to a existing working tree.
            try:
                to_bzr_dir = controldir.ControlDir.open_from_transport(
                    to_transport)
                has_wt = to_bzr_dir.has_workingt