Merge from 0.3 branch
[jelmer/subvertpy.git] / convert.py
index eafc4933e5d5de8f42925714c72c011290999ff0..5ada85161bf5304cdf2b4b2ea08d086f617b6ced 100644 (file)
@@ -1,5 +1,3 @@
-#!/usr/bin/env python2.4
-#
 # Copyright (C) 2005-2006 by Jelmer Vernooij
 # 
 # This program is free software; you can redistribute it and/or modify
 # Copyright (C) 2005-2006 by Jelmer Vernooij
 # 
 # This program is free software; you can redistribute it and/or modify
@@ -47,6 +45,8 @@ def transport_makedirs(transport, location_url):
             transport.mkdir(relpath)
             needed.pop()
         except NoSuchFile:
             transport.mkdir(relpath)
             needed.pop()
         except NoSuchFile:
+            if relpath == "":
+                raise
             needed.append((transport, urlutils.dirname(relpath)))
 
 
             needed.append((transport, urlutils.dirname(relpath)))
 
 
@@ -103,7 +103,7 @@ def convert_repository(url, output_url, scheme, create_shared_repo=True,
         if create_shared_repo:
             try:
                 target_repos = get_dir("").open_repository()
         if create_shared_repo:
             try:
                 target_repos = get_dir("").open_repository()
-                assert scheme.is_branch("") or target_repos.is_shared()
+                assert scheme.is_branch("") or scheme.is_tag("") or target_repos.is_shared()
             except NoRepositoryPresent:
                 target_repos = get_dir("").create_repository(shared=True)
             target_repos.set_make_working_trees(working_trees)
             except NoRepositoryPresent:
                 target_repos = get_dir("").create_repository(shared=True)
             target_repos.set_make_working_trees(working_trees)
@@ -140,6 +140,14 @@ def convert_repository(url, output_url, scheme, create_shared_repo=True,
                     target_branch = target_dir.create_branch()
                 if not revid in target_branch.revision_history():
                     source_branch = Branch.open(urlutils.join(url, branch))
                     target_branch = target_dir.create_branch()
                 if not revid in target_branch.revision_history():
                     source_branch = Branch.open(urlutils.join(url, branch))
+                    # Check if target_branch contains a subset of 
+                    # source_branch. If that is not the case, 
+                    # assume that source_branch has been replaced 
+                    # and remove target_branch
+                    if not target_branch.last_revision() in \
+                            source_branch.revision_history():
+                        target_branch.set_revision_history([])
+
                     target_branch.pull(source_branch)
                 if working_trees and not target_dir.has_workingtree():
                     target_dir.create_workingtree()
                     target_branch.pull(source_branch)
                 if working_trees and not target_dir.has_workingtree():
                     target_dir.create_workingtree()