remote-bzr: recover from failed clones
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Felipe Contreras committed
May 24, 2013 at 21:24 UTC
99a4fdb950b214de3a0ad0ac255f6a2491f975d4
1 file changed
+10
-8
contrib/remote-helpers/git-remote-bzr
+10
-8
@@ -769,22 +769,24 @@ def get_remote_branch(origin, remote_branch, name):
769
global dirname, peers
770
771
branch_path = os.path.join(dirname, 'clone', name)
772
- if os.path.exists(branch_path):
773
- # pull
772
+
773
+ try:
774
d = bzrlib.bzrdir.BzrDir.open(branch_path)
775
branch = d.open_branch()
776
- try:
777
- branch.pull(remote_branch, [], None, False)
778
- except bzrlib.errors.DivergedBranches:
779
- # use remote branch for now
780
- return remote_branch
781
- else:
776
+ except bzrlib.errors.NotBranchError:
777
# clone
778
d = origin.sprout(branch_path, None,
779
hardlink=True, create_tree_if_local=False,
780
force_new_repo=False,
781
source_branch=remote_branch)
782
branch = d.open_branch()
783
+ else:
784
+ # pull
785
+ try:
786
+ branch.pull(remote_branch, [], None, False)
787
+ except bzrlib.errors.DivergedBranches:
788
+ # use remote branch for now
789
+ return remote_branch
790
791
return branch
792