mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
project: allow src=. with symlinks
Some Android/Nest manifests are using <linkfile> with src="." to create stable paths to specific projects. Allow that specific use case as it seems reasonable to support. Bug: https://crbug.com/gerrit/11218 Change-Id: I16dbe8d9fe42ea45440afcb61404c753bff1930d Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/254330 Reviewed-by: Chanho Park <parkch98@gmail.com> Reviewed-by: Mike Frysinger <vapier@google.com> Tested-by: Mike Frysinger <vapier@google.com>
This commit is contained in:
parent
3285e4b436
commit
07392ed326
@ -382,6 +382,11 @@ class _LinkFile(object):
|
|||||||
Handles wild cards on the src linking all of the files in the source in to
|
Handles wild cards on the src linking all of the files in the source in to
|
||||||
the destination directory.
|
the destination directory.
|
||||||
"""
|
"""
|
||||||
|
# Some people use src="." to create stable links to projects. Lets allow
|
||||||
|
# that but reject all other uses of "." to keep things simple.
|
||||||
|
if self.src == '.':
|
||||||
|
src = self.git_worktree
|
||||||
|
else:
|
||||||
src = _SafeExpandPath(self.git_worktree, self.src)
|
src = _SafeExpandPath(self.git_worktree, self.src)
|
||||||
|
|
||||||
if os.path.exists(src):
|
if os.path.exists(src):
|
||||||
|
@ -314,6 +314,14 @@ class LinkFile(CopyLinkTestCase):
|
|||||||
lf._Link()
|
lf._Link()
|
||||||
self.assertExists(os.path.join(self.topdir, 'foo'))
|
self.assertExists(os.path.join(self.topdir, 'foo'))
|
||||||
|
|
||||||
|
def test_src_self(self):
|
||||||
|
"""Link to the project itself."""
|
||||||
|
dest = os.path.join(self.topdir, 'foo', 'bar')
|
||||||
|
lf = self.LinkFile('.', 'foo/bar')
|
||||||
|
lf._Link()
|
||||||
|
self.assertExists(dest)
|
||||||
|
self.assertEqual('../git-project', os.readlink(dest))
|
||||||
|
|
||||||
def test_dest_subdir(self):
|
def test_dest_subdir(self):
|
||||||
"""Link a file to a subdir of a checkout."""
|
"""Link a file to a subdir of a checkout."""
|
||||||
src = os.path.join(self.worktree, 'foo.txt')
|
src = os.path.join(self.worktree, 'foo.txt')
|
||||||
@ -323,6 +331,21 @@ class LinkFile(CopyLinkTestCase):
|
|||||||
lf._Link()
|
lf._Link()
|
||||||
self.assertExists(os.path.join(self.topdir, 'sub', 'dir', 'foo', 'bar'))
|
self.assertExists(os.path.join(self.topdir, 'sub', 'dir', 'foo', 'bar'))
|
||||||
|
|
||||||
|
def test_src_block_relative(self):
|
||||||
|
"""Do not allow relative symlinks."""
|
||||||
|
BAD_SOURCES = (
|
||||||
|
'./',
|
||||||
|
'..',
|
||||||
|
'../',
|
||||||
|
'foo/.',
|
||||||
|
'foo/./bar',
|
||||||
|
'foo/..',
|
||||||
|
'foo/../foo',
|
||||||
|
)
|
||||||
|
for src in BAD_SOURCES:
|
||||||
|
lf = self.LinkFile(src, 'foo')
|
||||||
|
self.assertRaises(error.ManifestInvalidPathError, lf._Link)
|
||||||
|
|
||||||
def test_update(self):
|
def test_update(self):
|
||||||
"""Make sure changed targets get updated."""
|
"""Make sure changed targets get updated."""
|
||||||
dest = os.path.join(self.topdir, 'sym')
|
dest = os.path.join(self.topdir, 'sym')
|
||||||
|
Loading…
Reference in New Issue
Block a user