~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to baz_import.py

  • Committer: Robert Collins
  • Date: 2005-09-07 16:33:05 UTC
  • mto: (147.2.6) (364.1.3 bzrtools)
  • mto: This revision was merged to the branch mainline in revision 324.
  • Revision ID: robertc@robertcollins.net-20050907163305-db235b6064a26d03
test empty import and tagged branches

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
 
from bzrlib.branch import Branch
 
16
 
 
17
from bzrlib.errors import NotBranchError
 
18
from bzrlib.branch import Branch, find_branch
17
19
from bzrlib.commands import Command
18
20
from errors import NoPyBaz
19
21
try:
50
52
    args.extend(files)
51
53
    return null_cmd(args)
52
54
 
 
55
saved_dir = None
 
56
 
53
57
def test_environ():
54
58
    """
55
59
    >>> q = test_environ()
61
65
    >>> os.path.exists(q)
62
66
    False
63
67
    """
 
68
    global saved_dir
 
69
    saved_dir = os.getcwdu()
64
70
    tdir = tempfile.mkdtemp(prefix="testdir-")
65
71
    os.environ["HOME"] = os.path.join(tdir, "home")
66
72
    os.mkdir(os.environ["HOME"])
104
110
    add_id([path], id)
105
111
 
106
112
def teardown_environ(tdir):
107
 
    os.chdir("/")
 
113
    os.chdir(saved_dir)
108
114
    shutil.rmtree(tdir)
109
115
 
110
116
def timport(tree, summary):
197
203
    try:
198
204
        revision = version.iter_revisions(reverse=True).next()
199
205
    except:
 
206
        print version
200
207
        if not version.exists():
201
208
            raise NoSuchVersion(version)
202
209
        else:
221
228
    if os.path.exists(output_dir):
222
229
        # We are starting from an existing directory, figure out what
223
230
        # the current version is
224
 
        branch = find_branch(output_dir)
 
231
        branch = find_branch(output_dir, find_root=False)
225
232
        last_patch = get_last_revision(branch)
226
233
        if version is None:
227
234
            version = last_patch.version
244
251
        # Strip off all of the ancestors which are already present
245
252
        # And get a directory starting with the latest ancestor
246
253
        latest_ancestor = ancestors[i]
247
 
        old_revno = find_branch(output_dir).revno()
 
254
        old_revno = find_branch(output_dir, find_root=False).revno()
248
255
        ancestors = ancestors[i+1:]
249
256
    return ancestors, old_revno
250
257
 
284
291
    """
285
292
    try:
286
293
        ancestors, old_revno = get_remaining_revisions(output_dir, version)
287
 
    except NotInABranch, e:
288
 
        raise UserError("%s exists, but is not a bzr branch." % e.path)
 
294
    except NotBranchError, e:
 
295
        raise UserError("%s exists, but is not a bzr branch." % output_dir)
289
296
    if len(ancestors) == 0:
290
 
        last_revision = get_last_revision(find_branch(output_dir))
 
297
        last_revision = get_last_revision(find_branch(output_dir, find_root=False))
291
298
        print 'Tree is up-to-date with %s' % last_revision
292
299
        return
293
300
 
358
365
    :param arch_revision: The Arch revision to generate an ID for.
359
366
 
360
367
    >>> revision_id(pybaz.Revision("you@example.com/cat--br--0--base-0"))
361
 
    'Arch-x:you@example.com%cat--br--0--base-0'
 
368
    'Arch-1:you@example.com%cat--br--0--base-0'
362
369
    """
363
 
    return "Arch-x:%s" % str(arch_revision).replace('/', '%')
 
370
    return "Arch-1:%s" % str(arch_revision).replace('/', '%')
364
371
 
365
372
class NotArchRevision(Exception):
366
373
    def __init__(self, revision_id):
370
377
 
371
378
def arch_revision(revision_id):
372
379
    """
373
 
    >>> str(arch_revision("Arch-x:jrandom@example.com%test--test--0"))
374
 
    Traceback (most recent call last):
375
 
    NotArchRevision: The revision id Arch-x:jrandom@example.com%test--test--0 does not look like it came from Arch.
376
 
    >>> str(arch_revision("Arch-x:jrandom@example.com%test--test--0--base-5"))
377
 
    Traceback (most recent call last):
378
 
    NotArchRevision: The revision id Arch-x:jrandom@example.com%test--test--0--base-5 does not look like it came from Arch.
379
 
    >>> str(arch_revision("Arch-x:jrandom@example.com%test--test--0--patch-5"))
 
380
    >>> str(arch_revision("Arch-1:jrandom@example.com%test--test--0"))
 
381
    Traceback (most recent call last):
 
382
    NotArchRevision: The revision id Arch-1:jrandom@example.com%test--test--0 does not look like it came from Arch.
 
383
    >>> str(arch_revision("Arch-1:jrandom@example.com%test--test--0--base-5"))
 
384
    Traceback (most recent call last):
 
385
    NotArchRevision: The revision id Arch-1:jrandom@example.com%test--test--0--base-5 does not look like it came from Arch.
 
386
    >>> str(arch_revision("Arch-1:jrandom@example.com%test--test--0--patch-5"))
380
387
    'jrandom@example.com/test--test--0--patch-5'
381
388
    """
382
389
    if revision_id is None:
383
390
        return None
384
 
    if revision_id[:7] != 'Arch-x:':
 
391
    if revision_id[:7] != 'Arch-1:':
385
392
        raise NotArchRevision(revision_id)
386
393
    else:
387
394
        try:
435
442
                shutil.copytree(bzr_dir, new_bzr_dir)
436
443
                # Now revdir should have a tree with the latest .bzr, and the
437
444
                # next revision of the baz tree
438
 
                branch = find_branch(revdir)
 
445
                branch = find_branch(revdir, find_root=False)
439
446
            else:
440
447
                branch = Branch(revdir, init=True)
441
448
        else:
445
452
            baz_inv, log = apply_revision(revdir, revision, 
446
453
                                          skip_symlinks=skip_symlinks)
447
454
            os.rename(new, old)
448
 
            branch = find_branch(revdir)
 
455
            branch = find_branch(revdir, find_root=False)
449
456
        timestamp = email.Utils.mktime_tz(log.date + (0,))
450
457
        rev_id = revision_id(revision)
451
458
        branch.lock_write()
528
535
    bzr_inv.sort()
529
536
    return bzr_inv
530
537
 
531
 
class NotInABranch(Exception):
532
 
    def __init__(self, path):
533
 
        Exception.__init__(self, "%s is not in a branch." % path)
534
 
        self.path = path
535
 
 
536
 
 
537
 
def find_branch(path):
538
 
    """
539
 
    >>> find_branch('/')
540
 
    Traceback (most recent call last):
541
 
    NotInABranch: / is not in a branch.
542
 
    >>> sb = bzrlib.ScratchBranch()
543
 
    >>> isinstance(find_branch(sb.base), Branch)
544
 
    True
545
 
    """
546
 
    try:
547
 
        return Branch(path)
548
 
    except BzrError, e:
549
 
        if e.args[0].endswith("' is not in a branch"):
550
 
            raise NotInABranch(path)
551
538
 
552
539
class cmd_baz_import(Command):
553
540
    """Import an Arch or Baz branch into a bzr branch"""