felipec / git

Fork of Junio Hamano's git for users
Other
204 stars 34 forks source link

git pull fails with latest git-remote-bzr in repositories cloned with git-remote-bzr from 1.8.2 #36

Closed ahktenzero closed 11 years ago

ahktenzero commented 11 years ago

I did a git bisect between 1.8.2 and HEAD, running git pull in a clone of the CEDET bzr repo. Results are below

git bisect start '--' 'contrib/remote-helpers/git-remote-bzr'
# bad: [06c68b1e7ecdef9ce5c7172c4a10237c5a47bc66] remote-hg: remove files before modifications
git bisect bad 06c68b1e7ecdef9ce5c7172c4a10237c5a47bc66
# good: [239222f587ed06f96d90dd71c66d80a2b1e3dc9f] Git 1.8.2
git bisect good 239222f587ed06f96d90dd71c66d80a2b1e3dc9f
# bad: [e2ca33de640c2c59142dedc18a2e932866515d10] remote-bzr: add support for shared repo
git bisect bad e2ca33de640c2c59142dedc18a2e932866515d10
# good: [31a033f7417a30ca045d5c5a8f3c77a0bbebfe2b] remote-bzr: trivial cleanups
git bisect good 31a033f7417a30ca045d5c5a8f3c77a0bbebfe2b
# good: [a853903e898c55f0354031265f305c38fef56711] remote-bzr: add support to push URLs
git bisect good a853903e898c55f0354031265f305c38fef56711
# good: [a22c6b106b0cb1fac317b45de7f7dcb2427aadc6] remote-bzr: always try to update the worktree
git bisect good a22c6b106b0cb1fac317b45de7f7dcb2427aadc6
# good: [c3eae3a382df879870d4b2352d0028258d7f8305] remote-bzr: use branch variable when appropriate
git bisect good c3eae3a382df879870d4b2352d0028258d7f8305
# bad: [7d809f4f2d61de0a03253d57806d646beffc4931] remote-bzr: add support for bzr repos
git bisect bad 7d809f4f2d61de0a03253d57806d646beffc4931
felipec commented 11 years ago

I'm investigating this issue, but in the latest code I'm getting a different error than what you reported in issue #35.

DEBUG: initializing
DEBUG: fetching remote 'origin' 'lp:~felipec/+junk/test'
Updating bzr branches
Cloning branch 'master'
Traceback (most recent call last):
  File "/home/felipec/bin/git-remote-bzr", line 972, in <module>
    sys.exit(main(sys.argv))
  File "/home/felipec/bin/git-remote-bzr", line 952, in main
    do_list(parser)
  File "/home/felipec/bin/git-remote-bzr", line 771, in do_list
    branch = get_remote_branch(master_branch)
  File "/home/felipec/bin/git-remote-bzr", line 808, in get_remote_branch
    branch = clone(branch_path, remote_branch)
  File "/home/felipec/bin/git-remote-bzr", line 789, in clone
    repo = bdir.find_repository()
  File "/usr/lib/python2.7/site-packages/bzrlib/bzrdir.py", line 574, in find_repository
    raise errors.NoRepositoryPresent(self)
bzrlib.errors.NoRepositoryPresent: No repository present: "file:///tmp/test-git/.git/bzr/origin/clone/master/"
fatal: Reading from helper 'git-remote-bzr' failed
felipec commented 11 years ago

Ah, the second time I do it I get the same error you reported.

felipec commented 11 years ago

This seems to do the trick:

--- a/contrib/remote-helpers/git-remote-bzr
+++ b/contrib/remote-helpers/git-remote-bzr
@@ -785,7 +785,10 @@ def do_list(parser):
     print

 def clone(path, remote_branch):
-    bdir = bzrlib.bzrdir.BzrDir.create(path)
+    try:
+        bdir = bzrlib.bzrdir.BzrDir.create(path)
+    except bzrlib.errors.AlreadyControlDirError:
+        bdir = bzrlib.bzrdir.BzrDir.open(path)
     repo = bdir.find_repository()
     repo.fetch(remote_branch.repository)
     return remote_branch.sprout(bdir, repository=repo)
@@ -860,6 +863,13 @@ def get_repo(url, alias):
         clone_path = os.path.join(dirname, 'clone')
         if not os.path.exists(clone_path):
             os.mkdir(clone_path)
+        else:
+            # check and remove old organization
+            try:
+                bdir = bzrlib.bzrdir.BzrDir.open(clone_path)
+                bdir.destroy_repository()
+            except bzrlib.errors.NoRepositoryPresent:
+                pass

     info('Updating bzr branches')
ahktenzero commented 11 years ago

That diff fixes the problem with pulling in repos created with 1.8.2 but it seems to have broken pulling in the ones I cloned with the latest version, I get

DEBUG: initializing
DEBUG: fetching remote 'origin' 'http://code.bitlbee.org/bitlbee/'
Traceback (most recent call last):
  File "/usr/lib/git-core/git-remote-bzr", line 982, in <module>
    sys.exit(main(sys.argv))
  File "/usr/lib/git-core/git-remote-bzr", line 952, in main
    repo = get_repo(url, alias)
  File "/usr/lib/git-core/git-remote-bzr", line 869, in get_repo
    bdir = bzrlib.bzrdir.BzrDir.open(clone_path)
  File "/usr/lib/python2.7/dist-packages/bzrlib/controldir.py", line 689, in open
    _unsupported=_unsupported)
  File "/usr/lib/python2.7/dist-packages/bzrlib/controldir.py", line 718, in open_from_transport
    find_format, transport, redirected)
  File "/usr/lib/python2.7/dist-packages/bzrlib/transport/__init__.py", line 1719, in do_catching_redirections
    return action(transport)
  File "/usr/lib/python2.7/dist-packages/bzrlib/controldir.py", line 706, in find_format
    probers=probers)
  File "/usr/lib/python2.7/dist-packages/bzrlib/controldir.py", line 1155, in find_format
    raise errors.NotBranchError(path=transport.base)
bzrlib.errors.NotBranchError: Not a branch: "/home/ahktenzero/src/apps/bitlbee/.git/bzr/origin/clone/".

when I try to pull. If I remove the diff it works.

felipec commented 11 years ago

Right, then this in addition:

--- contrib/remote-helpers/git-remote-bzr   2013-05-13 19:19:07.308241475 -0500
+++ /home/felipec/bin/git-remote-bzr    2013-05-13 19:46:39.028285706 -0500
@@ -868,7 +868,7 @@
             try:
                 bdir = bzrlib.bzrdir.BzrDir.open(clone_path)
                 bdir.destroy_repository()
-            except bzrlib.errors.NoRepositoryPresent:
+            except (bzrlib.errors.NoRepositoryPresent, bzrlib.errors.NotBranchError):
                 pass

     info('Updating bzr branches')
ahktenzero commented 11 years ago

Thanks, that's fixed it.

felipec commented 11 years ago

All right, I pushed the fix 1aea34a.