|
11 | 11 | REPOS_FILE_URL = \ |
12 | 12 | 'https://raw.githubusercontent.com/dirk-thomas/vcstool/master/test/list.repos' # noqa: E501 |
13 | 13 | REPOS2_FILE = os.path.join(os.path.dirname(__file__), 'list2.repos') |
| 14 | +REPOS_EXTENDS_FILE = os.path.join( |
| 15 | + os.path.dirname(__file__), 'list_extends.repos') |
| 16 | +REPOS_EXTENDS_LOOP_FILE = os.path.join( |
| 17 | + os.path.dirname(__file__), 'list_extends_loop.repos') |
14 | 18 | TEST_WORKSPACE = os.path.join( |
15 | 19 | os.path.dirname(os.path.dirname(__file__)), 'test_workspace') |
16 | 20 |
|
@@ -321,6 +325,119 @@ def test_status(self): |
321 | 325 | expected = get_expected_output('status') |
322 | 326 | self.assertEqual(output, expected) |
323 | 327 |
|
| 328 | + def test_import_extends(self): |
| 329 | + workdir = os.path.join(TEST_WORKSPACE, 'import-extends') |
| 330 | + os.makedirs(workdir) |
| 331 | + try: |
| 332 | + output = run_command( |
| 333 | + 'import', ['--input', REPOS_EXTENDS_FILE, '.'], |
| 334 | + subfolder='import-extends') |
| 335 | + # the actual output contains absolute paths |
| 336 | + output = output.replace( |
| 337 | + b'repository in ' + workdir.encode() + b'/', |
| 338 | + b'repository in ./') |
| 339 | + expected = get_expected_output('import_extends') |
| 340 | + # newer git versions don't append three dots after the commit hash |
| 341 | + assert output == expected or \ |
| 342 | + output == expected.replace(b'... ', b' ') |
| 343 | + finally: |
| 344 | + rmtree(workdir) |
| 345 | + |
| 346 | + def test_import_extends_loop(self): |
| 347 | + with self.assertRaises(subprocess.CalledProcessError) as e: |
| 348 | + run_command( |
| 349 | + 'import', ['--input', REPOS_EXTENDS_LOOP_FILE, '.']) |
| 350 | + self.assertIn( |
| 351 | + b'Infinite loop in repos extensions', e.exception.output) |
| 352 | + |
| 353 | + def test_import_extends_merge(self): |
| 354 | + from vcstool.commands.import_ import merge_repositories |
| 355 | + # only one set of repos |
| 356 | + repos = [ |
| 357 | + { |
| 358 | + 'some/path': { |
| 359 | + 'type': 'git', |
| 360 | + 'url': 'https://github.com/user/repo', |
| 361 | + 'version': 'master', |
| 362 | + }, |
| 363 | + }, |
| 364 | + ] |
| 365 | + merged_repos = merge_repositories(repos) |
| 366 | + self.assertDictEqual(repos[0], merged_repos) |
| 367 | + # multiple sets repos |
| 368 | + repos = [ |
| 369 | + { |
| 370 | + 'a/b/c': { |
| 371 | + 'type': 'git', |
| 372 | + 'url': 'https://github.com/a/bc', |
| 373 | + 'version': '1.0.0', |
| 374 | + }, |
| 375 | + 'd/e': { |
| 376 | + 'type': 'hg', |
| 377 | + 'url': 'very.old.com', |
| 378 | + 'version': '-1', |
| 379 | + }, |
| 380 | + 'f': { |
| 381 | + 'type': 'svn', |
| 382 | + 'url': 'https://gitlab.com/f/f', |
| 383 | + 'version': 'master', |
| 384 | + }, |
| 385 | + 'g/h': { |
| 386 | + 'type': 'git', |
| 387 | + 'url': 'https://gitlab.com/g/h', |
| 388 | + 'version': '2.7', |
| 389 | + }, |
| 390 | + }, |
| 391 | + { |
| 392 | + 'a/b/c': { |
| 393 | + 'type': 'git', |
| 394 | + 'url': 'https://github.com/a/bc', |
| 395 | + 'version': 'master', |
| 396 | + }, |
| 397 | + 'i/j': { |
| 398 | + 'type': 'git', |
| 399 | + 'url': 'https://some.website', |
| 400 | + 'version': '42', |
| 401 | + }, |
| 402 | + }, |
| 403 | + { |
| 404 | + 'g/h': { |
| 405 | + 'type': 'git', |
| 406 | + 'url': 'https://gitlab.com/custom/h', |
| 407 | + 'version': '2.8', |
| 408 | + }, |
| 409 | + }, |
| 410 | + ] |
| 411 | + expected_merged_repos = { |
| 412 | + 'a/b/c': { |
| 413 | + 'type': 'git', |
| 414 | + 'url': 'https://github.com/a/bc', |
| 415 | + 'version': 'master', |
| 416 | + }, |
| 417 | + 'd/e': { |
| 418 | + 'type': 'hg', |
| 419 | + 'url': 'very.old.com', |
| 420 | + 'version': '-1', |
| 421 | + }, |
| 422 | + 'f': { |
| 423 | + 'type': 'svn', |
| 424 | + 'url': 'https://gitlab.com/f/f', |
| 425 | + 'version': 'master', |
| 426 | + }, |
| 427 | + 'g/h': { |
| 428 | + 'type': 'git', |
| 429 | + 'url': 'https://gitlab.com/custom/h', |
| 430 | + 'version': '2.8', |
| 431 | + }, |
| 432 | + 'i/j': { |
| 433 | + 'type': 'git', |
| 434 | + 'url': 'https://some.website', |
| 435 | + 'version': '42', |
| 436 | + }, |
| 437 | + } |
| 438 | + merged_repos = merge_repositories(repos) |
| 439 | + self.assertDictEqual(expected_merged_repos, merged_repos) |
| 440 | + |
324 | 441 |
|
325 | 442 | def run_command(command, args=None, subfolder=None): |
326 | 443 | repo_root = os.path.dirname(os.path.dirname(__file__)) |
|
0 commit comments