diff options
| -rw-r--r-- | project.py | 7 | ||||
| -rw-r--r-- | tests/test_project.py | 23 |
2 files changed, 29 insertions, 1 deletions
| @@ -382,7 +382,12 @@ class _LinkFile(object): | |||
| 382 | Handles wild cards on the src linking all of the files in the source in to | 382 | Handles wild cards on the src linking all of the files in the source in to |
| 383 | the destination directory. | 383 | the destination directory. |
| 384 | """ | 384 | """ |
| 385 | src = _SafeExpandPath(self.git_worktree, self.src) | 385 | # Some people use src="." to create stable links to projects. Lets allow |
| 386 | # that but reject all other uses of "." to keep things simple. | ||
| 387 | if self.src == '.': | ||
| 388 | src = self.git_worktree | ||
| 389 | else: | ||
| 390 | src = _SafeExpandPath(self.git_worktree, self.src) | ||
| 386 | 391 | ||
| 387 | if os.path.exists(src): | 392 | if os.path.exists(src): |
| 388 | # Entity exists so just a simple one to one link operation. | 393 | # Entity exists so just a simple one to one link operation. |
diff --git a/tests/test_project.py b/tests/test_project.py index 6d82da11..dc41f4c0 100644 --- a/tests/test_project.py +++ b/tests/test_project.py | |||
| @@ -314,6 +314,14 @@ class LinkFile(CopyLinkTestCase): | |||
| 314 | lf._Link() | 314 | lf._Link() |
| 315 | self.assertExists(os.path.join(self.topdir, 'foo')) | 315 | self.assertExists(os.path.join(self.topdir, 'foo')) |
| 316 | 316 | ||
| 317 | def test_src_self(self): | ||
| 318 | """Link to the project itself.""" | ||
| 319 | dest = os.path.join(self.topdir, 'foo', 'bar') | ||
| 320 | lf = self.LinkFile('.', 'foo/bar') | ||
| 321 | lf._Link() | ||
| 322 | self.assertExists(dest) | ||
| 323 | self.assertEqual('../git-project', os.readlink(dest)) | ||
| 324 | |||
| 317 | def test_dest_subdir(self): | 325 | def test_dest_subdir(self): |
| 318 | """Link a file to a subdir of a checkout.""" | 326 | """Link a file to a subdir of a checkout.""" |
| 319 | src = os.path.join(self.worktree, 'foo.txt') | 327 | src = os.path.join(self.worktree, 'foo.txt') |
| @@ -323,6 +331,21 @@ class LinkFile(CopyLinkTestCase): | |||
| 323 | lf._Link() | 331 | lf._Link() |
| 324 | self.assertExists(os.path.join(self.topdir, 'sub', 'dir', 'foo', 'bar')) | 332 | self.assertExists(os.path.join(self.topdir, 'sub', 'dir', 'foo', 'bar')) |
| 325 | 333 | ||
| 334 | def test_src_block_relative(self): | ||
| 335 | """Do not allow relative symlinks.""" | ||
| 336 | BAD_SOURCES = ( | ||
| 337 | './', | ||
| 338 | '..', | ||
| 339 | '../', | ||
| 340 | 'foo/.', | ||
| 341 | 'foo/./bar', | ||
| 342 | 'foo/..', | ||
| 343 | 'foo/../foo', | ||
| 344 | ) | ||
| 345 | for src in BAD_SOURCES: | ||
| 346 | lf = self.LinkFile(src, 'foo') | ||
| 347 | self.assertRaises(error.ManifestInvalidPathError, lf._Link) | ||
| 348 | |||
| 326 | def test_update(self): | 349 | def test_update(self): |
| 327 | """Make sure changed targets get updated.""" | 350 | """Make sure changed targets get updated.""" |
| 328 | dest = os.path.join(self.topdir, 'sym') | 351 | dest = os.path.join(self.topdir, 'sym') |
