~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to bzrtools.py

  • Committer: Aaron Bentley
  • Date: 2007-11-02 02:03:09 UTC
  • Revision ID: aaron.bentley@utoronto.ca-20071102020309-p818ojtsho5ubtxk
Fix rspush lock error when excluding working tree

Show diffs side-by-side

added added

removed removed

Lines of Context:
253
253
 
254
254
def rspush(tree, location=None, overwrite=False, working_tree=True,
255
255
    _rsync=None):
256
 
    my_rsync = _rsync
257
 
    if my_rsync is None:
258
 
        my_rsync = rsync
259
 
    if (tree.bzrdir.root_transport.base !=
260
 
        tree.branch.bzrdir.root_transport.base):
261
 
        raise NotStandalone(tree.bzrdir.root_transport.base)
262
 
    if (tree.branch.get_bound_location() is not None):
263
 
        raise NotStandalone(tree.bzrdir.root_transport.base)
264
 
    if (tree.branch.repository.is_shared()):
265
 
        raise NotStandalone(tree.bzrdir.root_transport.base)
266
 
    push_location = get_push_data(tree)
267
 
    if location is not None:
268
 
        if not location.endswith('/'):
269
 
            location += '/'
270
 
        push_location = location
271
 
 
272
 
    if push_location is None:
273
 
        raise BzrCommandError("No rspush location known or specified.")
274
 
 
275
 
    if (push_location.find('::') != -1):
276
 
        usessh=False
277
 
    else:
278
 
        usessh=True
279
 
 
280
 
    if (push_location.find('://') != -1 or
281
 
        push_location.find(':') == -1):
282
 
        raise BzrCommandError("Invalid rsync path %r." % push_location)
283
 
 
284
 
    if working_tree:
285
 
        clean, non_source = is_clean(tree)
286
 
        if not clean:
287
 
            print """Error: This tree has uncommitted changes or unknown (?) files.
288
 
    Use "bzr status" to list them."""
289
 
            sys.exit(1)
290
 
        final_exclusions = non_source[:]
291
 
    else:
292
 
        wt = tree
293
 
        final_exclusions = []
294
 
        for path, status, kind, file_id, entry in wt.list_files():
295
 
            final_exclusions.append(path)
296
 
 
297
 
    final_exclusions.extend(exclusions)
298
 
    if not overwrite:
299
 
        try:
300
 
            if not history_subset(push_location, tree.branch, _rsync=my_rsync):
301
 
                raise bzrlib.errors.BzrCommandError("Local branch is not a"
302
 
                                                    " newer version of remote"
303
 
                                                    " branch.")
304
 
        except RsyncNoFile:
305
 
            if not empty_or_absent(push_location):
306
 
                raise bzrlib.errors.BzrCommandError("Remote location is not a"
307
 
                                                    " bzr branch (or empty"
308
 
                                                    " directory)")
309
 
        except RsyncStreamIO:
310
 
            raise bzrlib.errors.BzrCommandError("Rsync could not use the"
311
 
                " specified location.  Please ensure that"
312
 
                ' "%s" is of the form "machine:/path".' % push_location)
313
 
    print "Pushing to %s" % push_location
314
 
    my_rsync(tree.basedir+'/', push_location, ssh=usessh,
315
 
          excludes=final_exclusions)
316
 
 
317
 
    set_push_data(tree, push_location)
 
256
    tree.lock_write()
 
257
    try:
 
258
        my_rsync = _rsync
 
259
        if my_rsync is None:
 
260
            my_rsync = rsync
 
261
        if (tree.bzrdir.root_transport.base !=
 
262
            tree.branch.bzrdir.root_transport.base):
 
263
            raise NotStandalone(tree.bzrdir.root_transport.base)
 
264
        if (tree.branch.get_bound_location() is not None):
 
265
            raise NotStandalone(tree.bzrdir.root_transport.base)
 
266
        if (tree.branch.repository.is_shared()):
 
267
            raise NotStandalone(tree.bzrdir.root_transport.base)
 
268
        push_location = get_push_data(tree)
 
269
        if location is not None:
 
270
            if not location.endswith('/'):
 
271
                location += '/'
 
272
            push_location = location
 
273
 
 
274
        if push_location is None:
 
275
            raise BzrCommandError("No rspush location known or specified.")
 
276
 
 
277
        if (push_location.find('::') != -1):
 
278
            usessh=False
 
279
        else:
 
280
            usessh=True
 
281
 
 
282
        if (push_location.find('://') != -1 or
 
283
            push_location.find(':') == -1):
 
284
            raise BzrCommandError("Invalid rsync path %r." % push_location)
 
285
 
 
286
        if working_tree:
 
287
            clean, non_source = is_clean(tree)
 
288
            if not clean:
 
289
                print ('Error: This tree has uncommitted changes or unknown'
 
290
                ' (?) files.  Use "bzr status" to list them.')
 
291
                sys.exit(1)
 
292
            final_exclusions = non_source[:]
 
293
        else:
 
294
            wt = tree
 
295
            final_exclusions = []
 
296
            for path, status, kind, file_id, entry in wt.list_files():
 
297
                final_exclusions.append(path)
 
298
 
 
299
        final_exclusions.extend(exclusions)
 
300
        if not overwrite:
 
301
            try:
 
302
                if not history_subset(push_location, tree.branch,
 
303
                                      _rsync=my_rsync):
 
304
                    raise bzrlib.errors.BzrCommandError(
 
305
                        "Local branch is not a newer version of remote"
 
306
                        " branch.")
 
307
            except RsyncNoFile:
 
308
                if not empty_or_absent(push_location):
 
309
                    raise bzrlib.errors.BzrCommandError(
 
310
                        "Remote location is not a bzr branch (or empty"
 
311
                        " directory)")
 
312
            except RsyncStreamIO:
 
313
                raise bzrlib.errors.BzrCommandError("Rsync could not use the"
 
314
                    " specified location.  Please ensure that"
 
315
                    ' "%s" is of the form "machine:/path".' % push_location)
 
316
        print "Pushing to %s" % push_location
 
317
        my_rsync(tree.basedir+'/', push_location, ssh=usessh,
 
318
              excludes=final_exclusions)
 
319
 
 
320
        set_push_data(tree, push_location)
 
321
    finally:
 
322
        tree.unlock()
318
323
 
319
324
 
320
325
def short_committer(committer):