/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 __init__.py

(garyvdm, vila) Allows uploading from remote branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
Known limitations:
26
26
- Symlinks are ignored,
27
27
 
28
 
- chmod bits are not supported.
 
28
- chmod bits (other than the owner's execution bit) are not supported.
29
29
"""
30
30
 
31
31
# TODO: the chmod bits *can* be supported via the upload protocols
49
49
import stat
50
50
 
51
51
from bzrlib import (
 
52
    bzrdir,
52
53
    errors,
53
54
    revisionspec,
54
55
    transport,
322
323
        finally:
323
324
            self.tree.unlock()
324
325
 
 
326
class CannotUploadToWorkingTreeError(errors.BzrCommandError):
 
327
 
 
328
    _fmt = 'Cannot upload to a bzr managed working tree: %(url)s".'
 
329
 
 
330
    def __init__(self, url):
 
331
        super(CannotUploadToWorkingTreeError, self).__init__(self)
 
332
        self.url = url
 
333
 
325
334
 
326
335
class cmd_upload(commands.Command):
327
336
    """Upload a working tree, as a whole or incrementally.
357
366
            raise BzrCommandError("Your version of bzr does not have the "
358
367
                    "hooks necessary for --auto to work")
359
368
 
360
 
        wt = workingtree.WorkingTree.open_containing(directory)[0]
361
 
        changes = wt.changes_from(wt.basis_tree())
362
 
 
363
 
        if revision is None and  changes.has_changed():
364
 
            raise errors.UncommittedChanges(wt)
365
 
 
366
 
        branch = wt.branch
 
369
        (wt, branch,
 
370
         relpath) = bzrdir.BzrDir.open_containing_tree_or_branch(directory)
 
371
 
 
372
        if wt:
 
373
            changes = wt.changes_from(wt.basis_tree())
 
374
 
 
375
            if revision is None and  changes.has_changed():
 
376
                raise errors.UncommittedChanges(wt)
367
377
 
368
378
        if location is None:
369
379
            stored_loc = get_upload_location(branch)
378
388
                location = stored_loc
379
389
 
380
390
        to_transport = transport.get_transport(location)
 
391
 
 
392
        # Check that we are not uploading to a existing working tree.
 
393
        try:
 
394
            to_bzr_dir = bzrdir.BzrDir.open_from_transport(to_transport)
 
395
            has_wt = to_bzr_dir.has_workingtree()
 
396
        except errors.NotBranchError:
 
397
            has_wt = False
 
398
        except errors.NotLocalUrl:
 
399
            # The exception raised is a bit weird... but that's life.
 
400
            has_wt = True
 
401
 
 
402
        if has_wt:
 
403
            raise CannotUploadToWorkingTreeError(location)
 
404
 
381
405
        if revision is None:
382
406
            rev_id = branch.last_revision()
383
407
        else: