northteam / git-repo

Automatically exported from code.google.com/p/git-repo
Apache License 2.0
0 stars 0 forks source link

Having a path switching from underlying git repository to another is badly handled #201

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago

With v1.12.24 and commit 384b3c594831 ('Fail if gitdir does not point to objdir 
during sync') [1], when switching from one branch to another, with a path 
backed by a different project between the two branches:

diff --git a/manifest.xml b/manifest.xml
index aaaaaaaaaaa..bbbbbbbbbb 100644
--- a/default.xml
+++ b/default.xml
-<project name="old/old_project" path="project" ...>
+<project name="new/new_project" path="project" ...>

Initial checkout:

  $ repo init -u .... -b old -m manifest.xml
  $ repo sync

Switch to different branch:

  $ repo init -b new -m manifest.xml
  $ repo sync

Repo sync failed with following error message:

Fetching projects:   7% (7/89)  Fetching project new/new_project
Traceback (most recent call last):
  File "/home/ydroneaud/src/work/.repo/repo/main.py", line 513, in <module>
    _Main(sys.argv[1:])
  File "/home/ydroneaud/src/work/.repo/repo/main.py", line 489, in _Main
    result = repo._Run(argv) or 0
  File "/home/ydroneaud/src/work/.repo/repo/main.py", line 162, in _Run
    result = cmd.Execute(copts, cargs)
  File "/home/ydroneaud/src/work/.repo/repo/subcmds/sync.py", line 659, in Execute
    fetched = self._Fetch(to_fetch, opt)
  File "/home/ydroneaud/src/work/.repo/repo/subcmds/sync.py", line 350, in _Fetch
    self._FetchProjectList(**kwargs)
  File "/home/ydroneaud/src/work/.repo/repo/subcmds/sync.py", line 244, in _FetchProjectList
    success = self._FetchHelper(opt, project, *args, **kwargs)
  File "/home/ydroneaud/src/work/.repo/repo/subcmds/sync.py", line 286, in _FetchHelper
    optimized_fetch=opt.optimized_fetch)
  File "/home/ydroneaud/src/work/.repo/repo/project.py", line 1143, in Sync_NetworkHalf
    self._InitGitDir()
  File "/home/ydroneaud/src/work/.repo/repo/project.py", line 2183, in _InitGitDir
    self._CheckDirReference(self.objdir, self.gitdir, share_refs=False)
  File "/home/ydroneaud/src/work/.repo/repo/project.py", line 2305, in _CheckDirReference
    raise GitError('cannot overwrite a local work tree')
error.GitError: cannot overwrite a local work tree

After adding some debug to project.py:

diff --git a/project.py b/project.py
index 00f6b90457a1..d5516ce90ca4 100644
--- a/project.py
+++ b/project.py
@@ -2301,6 +2301,7 @@ class Project(object):
         src = os.path.realpath(os.path.join(srcdir, name))
         # Fail if the links are pointing to the wrong place
         if src != dst:
+          print(' srcdir = %s\n destdir = %s\n name = %s\n src = %s\n dst = 
%s\n' % (srcdir, destdir, name, src, dst))
           raise GitError('cannot overwrite a local work tree')

   def _ReferenceGitDir(self, gitdir, dotgit, share_refs, copy_all):

Repo init reports the following:

 srcdir =  /home/ydroneaud/src/work/.repo/project-objects/new_project.git
 destdir = /home/ydroneaud/src/work/.repo/projects/project.git
 name = info
 src = /home/ydroneaud/src/work/.repo/project-objects/new/new_project.git/info
 dst = /home/ydroneaud/src/work/.repo/project-objects/old/old_project.git/info

It seems that .repo/projects/ has 'project' still linked to older repository 
objects:
.repo/projects/project.git/info is a symlink to 
.repo/project-objects/old/old_project.git/info while it should become a symlink 
to .repo/project-objects/new/new_project.git/info.

As already noted in issue #200, I understand the issue the commit [1] is trying 
to catch, but it doesn't make anything to avoid the issue, it doesn't do 
anything to recover from the issue and doesn't give a hint to fix the issue.

Here, repo sync failed before making the switch to the new repository.

Regards.

Original issue reported on code.google.com by yann@droneaud.fr on 27 Jul 2015 at 2:34