Пример #1
0
def test_loader_external_in_versioned_path(swh_storage, repo_url,
                                           external_repo_url, tmp_path):
    # first commit on external
    add_commit(
        external_repo_url,
        "Create a file in an external repository",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="src/foo.sh",
                data=b"#!/bin/bash\necho foo",
            ),
        ],
    )

    # first commit
    add_commit(
        repo_url,
        "Add trunk/src dir",
        [
            CommitChange(change_type=CommitChangeType.AddOrUpdate,
                         path="trunk/src/")
        ],
    )

    # second commit
    add_commit(
        repo_url,
        "Add a file in trunk/src directory and set external on trunk targeting src",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="trunk/src/bar.sh",
                data=b"#!/bin/bash\necho bar",
            ),
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="trunk/",
                properties={
                    "svn:externals":
                    (f"{svn_urljoin(external_repo_url, 'src')} src")
                },
            ),
        ],
    )

    loader = SvnLoader(
        swh_storage,
        repo_url,
        temp_directory=tmp_path,
        check_revision=1,
    )
    assert loader.load() == {"status": "eventful"}
    assert_last_visit_matches(
        loader.storage,
        repo_url,
        status="full",
        type="svn",
    )
    check_snapshot(loader.snapshot, loader.storage)
Пример #2
0
def test_loader_with_invalid_svn_externals(swh_storage, repo_url, tmp_path,
                                           mocker):

    # first commit
    add_commit(
        repo_url,
        "Create repository structure.",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="branches/",
            ),
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="tags/",
            ),
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="trunk/",
            ),
        ],
    )

    # second commit
    add_commit(
        repo_url,
        ("Set svn:externals property on trunk/externals path of repository to load."
         "The externals URLs are not valid."),
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="trunk/externals/",
                properties={
                    "svn:externals":
                    ("file:///tmp/invalid/svn/repo/hello hello\n"
                     "file:///tmp/invalid/svn/repo/foo.sh foo.sh")
                },
            ),
        ],
    )

    loader = SvnLoader(swh_storage,
                       repo_url,
                       temp_directory=tmp_path,
                       check_revision=1)
    assert loader.load() == {"status": "eventful"}
    assert_last_visit_matches(
        loader.storage,
        repo_url,
        status="full",
        type="svn",
    )
    check_snapshot(loader.snapshot, loader.storage)
Пример #3
0
def test_loader_set_invalid_externals_then_remove(swh_storage, repo_url,
                                                  tmp_path):

    # first commit
    add_commit(
        repo_url,
        "Add trunk directory and set invalid external",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="trunk/",
                properties={
                    "svn:externals":
                    "file:///tmp/invalid/svn/repo/code external/code"
                },
            ),
        ],
    )

    # second commit
    add_commit(
        repo_url,
        "Unset externals on trunk",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="trunk/",
                properties={"svn:externals": None},
            ),
        ],
    )

    loader = SvnLoader(swh_storage,
                       repo_url,
                       temp_directory=tmp_path,
                       check_revision=1)
    assert loader.load() == {"status": "eventful"}
    assert_last_visit_matches(
        loader.storage,
        repo_url,
        status="full",
        type="svn",
    )
    check_snapshot(loader.snapshot, loader.storage)
Пример #4
0
def test_loader_with_invalid_externals_and_versioned_path(
        swh_storage, repo_url, tmp_path):

    # first commit
    add_commit(
        repo_url,
        "Add file in main repository",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="trunk/script.sh",
                data=b"#!/bin/bash\necho foo",
            ),
        ],
    )

    # second commit
    add_commit(
        repo_url,
        "Add invalid externals targeting the versioned file",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="trunk/",
                properties={
                    "svn:externals":
                    ("file:///tmp/invalid/svn/repo/code/script.sh script.sh")
                },
            ),
        ],
    )

    loader = SvnLoader(swh_storage,
                       repo_url,
                       temp_directory=tmp_path,
                       check_revision=1)
    assert loader.load() == {"status": "eventful"}
    assert_last_visit_matches(
        loader.storage,
        repo_url,
        status="full",
        type="svn",
    )
    check_snapshot(loader.snapshot, loader.storage)
Пример #5
0
def test_loader_export_external_path_using_peg_rev(swh_storage, repo_url,
                                                   external_repo_url,
                                                   tmp_path):
    # first commit on external
    add_commit(
        external_repo_url,
        "Create a file in an external repository",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="code/foo.sh",
                data=b"#!/bin/bash\necho foo",
            ),
        ],
    )

    # second commit on external
    add_commit(
        external_repo_url,
        "Remove previously added file",
        [
            CommitChange(
                change_type=CommitChangeType.Delete,
                path="code/foo.sh",
            ),
        ],
    )

    # third commit on external
    add_commit(
        external_repo_url,
        "Add file again but with different content",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="code/foo.sh",
                data=b"#!/bin/bash\necho bar",
            ),
        ],
    )

    # first commit
    add_commit(
        repo_url,
        "Add trunk dir",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="trunk/",
            ),
        ],
    )

    # second commit
    add_commit(
        repo_url,
        "Set external on trunk targeting first revision of external repo",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="trunk/",
                properties={
                    "svn:externals":
                    (f"{svn_urljoin(external_repo_url, 'code/foo.sh')}@1 foo.sh"
                     )
                },
            ),
        ],
    )

    # third commit
    add_commit(
        repo_url,
        "Modify external on trunk to target third revision of external repo",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="trunk/",
                properties={
                    "svn:externals":
                    (f"{svn_urljoin(external_repo_url, 'code/foo.sh')}@3 foo.sh"
                     )
                },
            ),
        ],
    )

    loader = SvnLoader(
        swh_storage,
        repo_url,
        temp_directory=tmp_path,
        check_revision=1,
    )
    assert loader.load() == {"status": "eventful"}
    assert_last_visit_matches(
        loader.storage,
        repo_url,
        status="full",
        type="svn",
    )
    check_snapshot(loader.snapshot, loader.storage)
Пример #6
0
def test_loader_remove_versioned_path_with_external_overlap(
        swh_storage, repo_url, external_repo_url, tmp_path):
    # first commit on external
    add_commit(
        external_repo_url,
        "Create a file in an external repository",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="code/hello.sh",
                data=b"#!/bin/bash\necho Hello World !",
            ),
        ],
    )

    # first commit
    add_commit(
        repo_url,
        "Add a file",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="trunk/project/script.sh",
                data=b"#!/bin/bash\necho foo",
            ),
        ],
    )

    # second commit
    add_commit(
        repo_url,
        "Set external on trunk overlapping versioned path",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="trunk/",
                properties={
                    "svn:externals":
                    (f"{svn_urljoin(external_repo_url, 'code')} project/code")
                },
            ),
        ],
    )

    # third commit
    add_commit(
        repo_url,
        "Remove trunk/project/ versioned path",
        [
            CommitChange(
                change_type=CommitChangeType.Delete,
                path="trunk/project/",
            ),
        ],
    )

    loader = SvnLoader(
        swh_storage,
        repo_url,
        temp_directory=tmp_path,
        check_revision=1,
    )
    assert loader.load() == {"status": "eventful"}
    assert_last_visit_matches(
        loader.storage,
        repo_url,
        status="full",
        type="svn",
    )
    check_snapshot(loader.snapshot, loader.storage)
Пример #7
0
def test_loader_externals_cache(swh_storage, repo_url, external_repo_url,
                                tmp_path):

    # first commit on external
    add_commit(
        external_repo_url,
        "Create some directories and files in an external repository",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="code/hello/hello-world",
                properties={"svn:executable": "*"},
                data=b"#!/bin/bash\necho Hello World !",
            ),
        ],
    )

    # first commit
    add_commit(
        repo_url,
        "Create repository structure.",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="project1/",
            ),
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="project2/",
            ),
        ],
    )

    external_url = svn_urljoin(external_repo_url, "code/hello")

    # second commit
    add_commit(
        repo_url,
        ("Set svn:externals property on trunk/externals path of repository to load."
         "One external targets a remote directory and another one a remote file."
         ),
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="project1/externals/",
                properties={"svn:externals": (f"{external_url} hello\n")},
            ),
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="project2/externals/",
                properties={"svn:externals": (f"{external_url} hello\n")},
            ),
        ],
    )

    loader = SvnLoader(swh_storage,
                       repo_url,
                       temp_directory=tmp_path,
                       check_revision=1)
    assert loader.load() == {"status": "eventful"}
    assert_last_visit_matches(
        loader.storage,
        repo_url,
        status="full",
        type="svn",
    )
    check_snapshot(loader.snapshot, loader.storage)

    assert (
        external_url,
        None,
        False,
    ) in loader.svnrepo.swhreplay.editor.externals_cache
Пример #8
0
def test_loader_set_externals_then_remove_and_add_as_local(
        swh_storage, repo_url, external_repo_url, tmp_path):
    # first commit on external
    add_commit(
        external_repo_url,
        "Create a file in an external repository",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="code/script.sh",
                data=b"#!/bin/bash\necho Hello World !",
            ),
        ],
    )

    # first commit
    add_commit(
        repo_url,
        "Add trunk directory and set externals",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="trunk/",
                properties={
                    "svn:externals":
                    (f"{svn_urljoin(external_repo_url, 'code')} code")
                },
            ),
        ],
    )

    # second commit
    add_commit(
        repo_url,
        "Unset externals on trunk and add remote path as local path",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="trunk/",
                properties={"svn:externals": None},
            ),
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="trunk/code/script.sh",
                data=b"#!/bin/bash\necho Hello World !",
            ),
        ],
    )

    loader = SvnLoader(swh_storage,
                       repo_url,
                       temp_directory=tmp_path,
                       check_revision=1)
    assert loader.load() == {"status": "eventful"}
    assert_last_visit_matches(
        loader.storage,
        repo_url,
        status="full",
        type="svn",
    )
    check_snapshot(loader.snapshot, loader.storage)
Пример #9
0
def test_loader_with_valid_svn_externals(swh_storage, repo_url,
                                         external_repo_url, tmp_path):
    # first commit on external
    add_commit(
        external_repo_url,
        "Create some directories and files in an external repository",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="code/hello/hello-world",
                properties={"svn:executable": "*"},
                data=b"#!/bin/bash\necho Hello World !",
            ),
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="foo.sh",
                properties={"svn:executable": "*"},
                data=b"#!/bin/bash\necho foo",
            ),
        ],
    )

    # first commit
    add_commit(
        repo_url,
        "Create repository structure.",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="branches/",
            ),
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="tags/",
            ),
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="trunk/",
            ),
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="trunk/bar.sh",
                properties={"svn:executable": "*"},
                data=b"#!/bin/bash\necho bar",
            ),
        ],
    )

    # second commit
    add_commit(
        repo_url,
        ("Set svn:externals property on trunk/externals path of repository to load."
         "One external targets a remote directory and another one a remote file."
         ),
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="trunk/externals/",
                properties={
                    "svn:externals":
                    (f"{svn_urljoin(external_repo_url, 'code/hello')} hello\n"
                     f"{svn_urljoin(external_repo_url, 'foo.sh')} foo.sh\n"
                     f"{svn_urljoin(repo_url, 'trunk/bar.sh')} bar.sh")
                },
            ),
        ],
    )

    # first load
    loader = SvnLoader(swh_storage,
                       repo_url,
                       temp_directory=tmp_path,
                       check_revision=1)
    assert loader.load() == {"status": "eventful"}
    assert_last_visit_matches(
        loader.storage,
        repo_url,
        status="full",
        type="svn",
    )
    check_snapshot(loader.snapshot, loader.storage)

    # third commit
    add_commit(
        repo_url,
        "Unset svn:externals property on trunk/externals path",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="trunk/externals/",
                properties={"svn:externals": None},
            ),
        ],
    )

    # second load
    loader = SvnLoader(swh_storage,
                       repo_url,
                       temp_directory=tmp_path,
                       check_revision=1)
    assert loader.load() == {"status": "eventful"}
    assert_last_visit_matches(
        loader.storage,
        repo_url,
        status="full",
        type="svn",
    )
    check_snapshot(loader.snapshot, loader.storage)
Пример #10
0
def test_loader_with_valid_externals_modification(swh_storage, repo_url,
                                                  external_repo_url, tmp_path):
    # first commit on external
    add_commit(
        external_repo_url,
        "Create some directories and files in an external repository",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="code/hello/hello-world",
                properties={"svn:executable": "*"},
                data=b"#!/bin/bash\necho Hello World !",
            ),
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="code/bar/bar.sh",
                properties={"svn:executable": "*"},
                data=b"#!/bin/bash\necho bar",
            ),
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="foo.sh",
                properties={"svn:executable": "*"},
                data=b"#!/bin/bash\necho foo",
            ),
        ],
    )

    # first commit
    add_commit(
        repo_url,
        ("Set svn:externals property on trunk/externals path of repository to load."
         ),
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="trunk/externals/",
                properties={
                    "svn:externals": (
                        f"{svn_urljoin(external_repo_url, 'code/hello')} src/code/hello\n"  # noqa
                        f"{svn_urljoin(external_repo_url, 'foo.sh')} src/foo.sh\n"
                    )
                },
            ),
        ],
    )

    # second commit
    add_commit(
        repo_url,
        (
            "Modify svn:externals property on trunk/externals path of repository to load."  # noqa
        ),
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="trunk/externals/",
                properties={
                    "svn:externals": (
                        f"{svn_urljoin(external_repo_url, 'code/bar')} src/code/bar\n"  # noqa
                        f"{svn_urljoin(external_repo_url, 'foo.sh')} src/foo.sh\n"
                    )
                },
            ),
        ],
    )

    loader = SvnLoader(swh_storage,
                       repo_url,
                       temp_directory=tmp_path,
                       check_revision=1)
    assert loader.load() == {"status": "eventful"}
    assert_last_visit_matches(
        loader.storage,
        repo_url,
        status="full",
        type="svn",
    )
    check_snapshot(loader.snapshot, loader.storage)
Пример #11
0
def test_loader_with_externals_parsing_error(swh_storage, repo_url,
                                             external_repo_url, tmp_path):
    # first commit on external
    add_commit(
        external_repo_url,
        "Create code directory",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="code/",
            ),
        ],
    )

    # second commit on external
    add_commit(
        external_repo_url,
        "Create code/foo.sh file",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="code/foo.sh",
                properties={"svn:executable": "*"},
                data=b"#!/bin/bash\necho foo",
            ),
        ],
    )

    # first commit
    add_commit(
        repo_url,
        "Create trunk directory.",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="trunk/",
            ),
        ],
    )

    # second commit
    add_commit(
        repo_url,
        "Set external on trunk directory that will result in a parsing error.",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="trunk/",
                properties={
                    "svn:externals":
                    (f"-r2{svn_urljoin(external_repo_url, 'code/foo.sh')} foo.sh"
                     )
                },
            ),
        ],
    )

    # third commit
    add_commit(
        repo_url,
        "Fix external definition on trunk directory.",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="trunk/",
                properties={
                    "svn:externals":
                    (f"-r2 {svn_urljoin(external_repo_url, 'code/foo.sh')} foo.sh"
                     )
                },
            ),
        ],
    )

    loader = SvnLoader(
        swh_storage,
        repo_url,
        temp_directory=tmp_path,
        check_revision=1,
    )
    assert loader.load() == {"status": "eventful"}
    assert_last_visit_matches(
        loader.storage,
        repo_url,
        status="full",
        type="svn",
    )
    check_snapshot(loader.snapshot, loader.storage)
Пример #12
0
def test_loader_directory_symlink_in_external(swh_storage, repo_url,
                                              external_repo_url, tmp_path):
    # first commit on external
    add_commit(
        external_repo_url,
        "Create dirs in an external repository",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="src/apps/",
            ),
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="src/deps/",
            ),
        ],
    )

    # second commit on external
    add_commit(
        external_repo_url,
        "Add symlink to src/deps in src/apps directory",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="src/apps/deps",
                data=b"link ../deps",
                properties={"svn:special": "*"},
            ),
        ],
    )

    # first commit
    add_commit(
        repo_url,
        "Add deps dir",
        [CommitChange(change_type=CommitChangeType.AddOrUpdate, path="deps/")],
    )

    # second commit
    add_commit(
        repo_url,
        "Set external to deps folder",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="deps/",
                properties={
                    "svn:externals": (f"{external_repo_url} external")
                },
            ),
        ],
    )

    loader = SvnLoader(
        swh_storage,
        repo_url,
        temp_directory=tmp_path,
        check_revision=1,
    )
    assert loader.load() == {"status": "eventful"}
    assert_last_visit_matches(
        loader.storage,
        repo_url,
        status="full",
        type="svn",
    )
    check_snapshot(loader.snapshot, loader.storage)
Пример #13
0
def test_loader_externals_add_remove_readd_on_subpath(swh_storage, repo_url,
                                                      external_repo_url,
                                                      tmp_path):
    # first commit on external
    add_commit(
        external_repo_url,
        "Create files in an external repository",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="src/foo.sh",
                data=b"#!/bin/bash\necho foo",
            ),
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="src/bar.sh",
                data=b"#!/bin/bash\necho bar",
            ),
        ],
    )

    # first commit
    add_commit(
        repo_url,
        "Set external on two paths targeting the same absolute path",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="trunk/src/",
                properties={
                    "svn:externals":
                    (f"{svn_urljoin(external_repo_url, 'src/foo.sh')} foo.sh")
                },
            ),
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="trunk/",
                properties={
                    "svn:externals":
                    (f"{svn_urljoin(external_repo_url, 'src/foo.sh')} src/foo.sh"
                     )
                },
            ),
        ],
    )

    # second commit
    add_commit(
        repo_url,
        "Remove external on a single path",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="trunk/",
                properties={
                    "svn:externals":
                    (f"{svn_urljoin(external_repo_url, 'src/bar.sh')} src/bar.sh"
                     )
                },
            ),
        ],
    )

    loader = SvnLoader(
        swh_storage,
        repo_url,
        temp_directory=tmp_path,
        check_revision=1,
    )
    assert loader.load() == {"status": "eventful"}
    assert_last_visit_matches(
        loader.storage,
        repo_url,
        status="full",
        type="svn",
    )
    check_snapshot(loader.snapshot, loader.storage)
Пример #14
0
def test_loader_remove_external_overlapping_versioned_path(
        swh_storage, repo_url, external_repo_url, tmp_path):
    # first commit on external
    add_commit(
        external_repo_url,
        "Create files in an external repository",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="code/foo.sh",
                data=b"#!/bin/bash\necho foo",
            ),
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="code/link",
                data=b"#!/bin/bash\necho link",
            ),
        ],
    )

    # first commit
    add_commit(
        repo_url,
        "Add trunk dir and a link file",
        [
            CommitChange(change_type=CommitChangeType.AddOrUpdate,
                         path="trunk/"),
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="trunk/link",
                data=b"link ../test",
                properties={"svn:special": "*"},
            ),
        ],
    )

    # second commit
    add_commit(
        repo_url,
        "Set external on root dir overlapping versioned trunk path",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="",  # repo root dir
                properties={
                    "svn:externals": (
                        f"{svn_urljoin(external_repo_url, 'code/foo.sh')} trunk/code/foo.sh\n"  # noqa
                        f"{svn_urljoin(external_repo_url, 'code/link')} trunk/link"
                    )
                },
            ),
        ],
    )

    # third commit
    add_commit(
        repo_url,
        "Remove external on root dir",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="",
                properties={"svn:externals": None},
            ),
        ],
    )

    loader = SvnLoader(
        swh_storage,
        repo_url,
        temp_directory=tmp_path,
        check_revision=1,
    )
    assert loader.load() == {"status": "eventful"}
    assert_last_visit_matches(
        loader.storage,
        repo_url,
        status="full",
        type="svn",
    )
    check_snapshot(loader.snapshot, loader.storage)
Пример #15
0
def test_loader_with_valid_externals_and_versioned_path(
        swh_storage, repo_url, external_repo_url, tmp_path):
    # first commit on external
    add_commit(
        external_repo_url,
        "Create a file in an external repository",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="code/script.sh",
                data=b"#!/bin/bash\necho Hello World !",
            ),
        ],
    )

    # first commit
    add_commit(
        repo_url,
        "Add file with same name but different content in main repository",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="trunk/script.sh",
                data=b"#!/bin/bash\necho foo",
            ),
        ],
    )

    # second commit
    add_commit(
        repo_url,
        "Add externals targeting the versioned file",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="trunk/",
                properties={
                    "svn:externals": (
                        f"{svn_urljoin(external_repo_url, 'code/script.sh')} script.sh"  # noqa
                    )
                },
            ),
        ],
    )

    # third commit
    add_commit(
        repo_url,
        "Modify the versioned file",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="trunk/script.sh",
                data=b"#!/bin/bash\necho bar",
            ),
        ],
    )

    loader = SvnLoader(swh_storage,
                       repo_url,
                       temp_directory=tmp_path,
                       check_revision=1)
    assert loader.load() == {"status": "eventful"}
    assert_last_visit_matches(
        loader.storage,
        repo_url,
        status="full",
        type="svn",
    )
    check_snapshot(loader.snapshot, loader.storage)
Пример #16
0
def test_loader_modify_external_same_path(swh_storage, repo_url,
                                          external_repo_url, tmp_path):
    # first commit on external
    add_commit(
        external_repo_url,
        "Create a file in an external repository",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="code/foo.sh",
                data=b"#!/bin/bash\necho foo",
            ),
        ],
    )

    # first commit
    add_commit(
        repo_url,
        "Add trunk dir",
        [
            CommitChange(change_type=CommitChangeType.AddOrUpdate,
                         path="trunk/")
        ],
    )

    # second commit
    add_commit(
        repo_url,
        "Set external code on trunk dir",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="trunk/",
                properties={
                    "svn:externals":
                    (f"{svn_urljoin(external_repo_url, 'code')} code")
                },
            ),
        ],
    )

    # third commit
    add_commit(
        repo_url,
        "Change code external on trunk targeting an invalid URL",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="trunk/",
                properties={
                    "svn:externals": "file:///tmp/invalid/svn/repo/path code"
                },
            ),
        ],
    )

    loader = SvnLoader(
        swh_storage,
        repo_url,
        temp_directory=tmp_path,
        check_revision=1,
    )
    assert loader.load() == {"status": "eventful"}
    assert_last_visit_matches(
        loader.storage,
        repo_url,
        status="full",
        type="svn",
    )
    check_snapshot(loader.snapshot, loader.storage)
Пример #17
0
def test_loader_with_recursive_external(swh_storage, repo_url,
                                        external_repo_url, tmp_path):
    # first commit on external
    add_commit(
        external_repo_url,
        "Create a file in an external repository",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="code/foo.sh",
                data=b"#!/bin/bash\necho foo",
            ),
        ],
    )

    # first commit
    add_commit(
        repo_url,
        "Add trunk dir and a file",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="trunk/bar.sh",
                data=b"#!/bin/bash\necho bar",
            )
        ],
    )

    # second commit
    add_commit(
        repo_url,
        "Set externals code on trunk/externals dir, one being recursive",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="trunk/externals/",
                properties={
                    "svn:externals":
                    (f"{svn_urljoin(external_repo_url, 'code')} code\n"
                     f"{repo_url} recursive")
                },
            ),
        ],
    )

    # first load
    loader = SvnLoader(
        swh_storage,
        repo_url,
        temp_directory=tmp_path,
        check_revision=1,
    )
    assert loader.load() == {"status": "eventful"}
    assert_last_visit_matches(
        loader.storage,
        repo_url,
        status="full",
        type="svn",
    )
    check_snapshot(loader.snapshot, loader.storage)
    assert loader.svnrepo.has_recursive_externals

    # second load on stale repo
    loader = SvnLoader(
        swh_storage,
        repo_url,
        temp_directory=tmp_path,
        check_revision=1,
    )
    assert loader.load() == {"status": "uneventful"}
    assert_last_visit_matches(
        loader.storage,
        repo_url,
        status="full",
        type="svn",
    )
    check_snapshot(loader.snapshot, loader.storage)
    assert loader.svnrepo.has_recursive_externals

    # third commit
    add_commit(
        repo_url,
        "Remove recursive external on trunk/externals dir",
        [
            CommitChange(
                change_type=CommitChangeType.AddOrUpdate,
                path="trunk/externals/",
                properties={
                    "svn:externals":
                    (f"{svn_urljoin(external_repo_url, 'code')} code")
                },
            ),
        ],
    )

    # third load
    loader = SvnLoader(
        swh_storage,
        repo_url,
        temp_directory=tmp_path,
        check_revision=1,
    )
    assert loader.load() == {"status": "eventful"}
    assert_last_visit_matches(
        loader.storage,
        repo_url,
        status="full",
        type="svn",
    )
    check_snapshot(loader.snapshot, loader.storage)
    assert not loader.svnrepo.has_recursive_externals