repo: Repo does not always handle '.' parameter correctly

The repo script allows a manifest to specify a '.' as the path the
top-level directory, which co-locates the .git and .repo directories,
and places files from the git repository at the top-level:

  <project name="proj_name" path="." />
  <project name="sierra.other.git" path="other" />

Most commands work correctly with this setup. Some commands, however,
fail to find the project. For instance, 'repo sync' works, and 'repo sync .'
works in a sub-project ('other' in this case) but 'repo sync .' in the
top-level directory fails with the error:

error: project . not found

There are two reasons for this:

1. The self.worktree attribute of the Project object is not normalized,
so with a '.' for path its value would be '/my/project/root/.'. This is
fine when used as a path, since it's the same path as '/my/project/root',
but when used in a string comparison it fails. This commit applies
os.path.normpath() to that value before storing it.

2. The _GetProjectByPath method in command.py was not checking the path
against manifest.topdir, so even once it was normalized the project was
not found. This commit adds a check against manifest.topdir if the
loop drops out without finding a project.

Change-Id: Ic84d053f1bbb5a357cad566805d5a326ae8246d2
This commit is contained in:
Mark E. Hamilton 2016-02-23 18:10:42 -07:00 committed by David Pursehouse
parent bdb866ea76
commit f9fe3e14d2
2 changed files with 6 additions and 1 deletions

View File

@ -119,6 +119,11 @@ class Command(object):
except KeyError: except KeyError:
oldpath = path oldpath = path
path = os.path.dirname(path) path = os.path.dirname(path)
if not project and path == manifest.topdir:
try:
project = self._by_path[path]
except KeyError:
pass
else: else:
try: try:
project = self._by_path[path] project = self._by_path[path]

View File

@ -626,7 +626,7 @@ class Project(object):
self.gitdir = gitdir.replace('\\', '/') self.gitdir = gitdir.replace('\\', '/')
self.objdir = objdir.replace('\\', '/') self.objdir = objdir.replace('\\', '/')
if worktree: if worktree:
self.worktree = worktree.replace('\\', '/') self.worktree = os.path.normpath(worktree.replace('\\', '/'))
else: else:
self.worktree = None self.worktree = None
self.relpath = relpath self.relpath = relpath