Example #1
0
def test_bare_clone():
    """
    GIVEN GitRepo without a path or repo
    WHEN clone is called with valid parameters and bare set to True
    THEN Repo.clone_from is called with bare=True
    """
    with patch('git.repo.base.Repo.clone_from') as mock_clone:
        GitRepo.clone('./', './testclone', True)
        mock_clone.assert_called_with('./', ANY, bare=True)
Example #2
0
def test_clone_failed():
    """
    GIVEN GitRepo without a path or repo
    WHEN clone is called with a valid clone_from URL and clone_to path
    AND Repo.clone_from fails with an exception
    THEN a RepoCreationException is raised
    """
    with patch('git.repo.base.Repo.clone_from') as mock_clone:
        mock_clone.side_effect = git.GitCommandError('clone', '')
        with pytest.raises(exceptions.RepoCreationException):
            GitRepo.clone('./', './testclone')
Example #3
0
def test_destroy_and_reclone(clone_repo_root, clone_repo_url):
    repo_root = clone_repo_root
    repo_url = clone_repo_url

    # Start by creating a new repo to destroy
    GitRepo.clone(repo_url, repo_root)

    # Get a timestamp for a random file
    f_path = os.path.join(repo_root, 'requirements.txt')
    orig_timestamp = os.path.getmtime(f_path)

    # Run the reclone action
    clone = GitRepo(repo_root)
    clone.destroy_and_reclone()

    # Ensure timestamp changed
    new_timestamp = os.path.getmtime(f_path)
    assert new_timestamp != orig_timestamp
Example #4
0
 def apply_inflight_patch():
     tmp_repo_root = "/tmp/test_retry"
     if os.path.exists(tmp_repo_root):
         # We already applied the inflight patch
         return
     else:
         tmp_repo = GitRepo.clone(patches_repo_root, tmp_repo_root)
         tmp_repo.branch.apply_patch("master", (datadir / "inflight.patch"))
         tmp_repo.git.push("origin", "master")
Example #5
0
def test_clone():
    """
    GIVEN GitRepo without a path or repo
    WHEN clone is called with a valid clone_from URL and clone_to path
    THEN Repo.clone_from is called
    """
    with patch('git.repo.base.Repo.clone_from') as mock_clone:
        clone = GitRepo.clone('./', './testclone')
        assert mock_clone.called is True
        assert isinstance(clone, GitRepo)
Example #6
0
def local_repo(datadir):
    """A clone of the patches repo, with a remote to the 'upstream' repo"""
    set_up_patches_repo(datadir)

    local_repo = GitRepo.clone(PATCHES_REPO_ROOT, LOCAL_REPO_ROOT)
    local_repo.remote.add("upstream", UPSTREAM_REPO_ROOT)

    yield local_repo

    # Clean up before the next run
    shutil.rmtree(LOCAL_REPO_ROOT, ignore_errors=True)
    shutil.rmtree(PATCHES_REPO_ROOT, ignore_errors=True)
Example #7
0
def test_clone_from_filesystem(clone_repo_root, clone_repo_url, repo_root):
    new_repo_root = clone_repo_root
    repo_url = "file://%s" % repo_root

    # Create a new clone
    clone = GitRepo.clone(repo_url, new_repo_root)

    # Ensure repo has expected tags, some commits
    assert hasattr(clone, "repo") is True
    clone.repo.commit("f8f7abc4ce87db051f9998c5d4dd153695e35675")
    tag = clone.repo.commit("0.1.0")
    assert tag.hexsha == "2e6c014bc296be90a7ed04d155ea7d9da2240bbc"
    assert clone.repo.bare is False
Example #8
0
def set_up_patches_repo(datadir):
    """Set up an older copy of the upstream repo, and add an extra commit"""
    tmp_repo = "/tmp/patches_repo"

    upstream_repo = GitRepo(UPSTREAM_REPO_ROOT)
    tmp_patches_repo = GitRepo.clone(UPSTREAM_REPO_ROOT, tmp_repo)

    upstream_head = upstream_repo.repo.head.object.hexsha
    assert tmp_patches_repo.repo.head.object.hexsha == upstream_head

    # Set the local repo back a few commits (so there is something to
    # rebase from upstream)
    tmp_patches_repo.branch.hard_reset_to_ref("master", "b96f74b3")
    assert tmp_patches_repo.repo.head.object.hexsha != upstream_head

    # And also add a local-only patch
    patch_path = (datadir / "local-only.patch")
    tmp_patches_repo.branch.apply_patch("master", patch_path)

    # Finally, now that the repo preparations are done, get a bare clone ready
    GitRepo.clone(tmp_repo, PATCHES_REPO_ROOT, bare=True)

    shutil.rmtree(tmp_repo, ignore_errors=True)
Example #9
0
def test_clone(clone_repo_root, clone_repo_url):
    repo_root = clone_repo_root
    repo_url = clone_repo_url

    # Create a new clone
    clone = GitRepo.clone(repo_url, repo_root, bare=True)

    # Ensure repo has expected tags, some commits
    assert hasattr(clone, "repo") is True

    commit = clone.repo.commit("f8f7abc4ce87db051f9998c5d4dd153695e35675")
    assert commit is not None

    tag = clone.repo.commit("0.1.0")
    assert tag.hexsha == "2e6c014bc296be90a7ed04d155ea7d9da2240bbc"

    assert clone.repo.bare is True
Example #10
0
def test_clone_failed(clone_repo_root, clone_repo_url):
    repo_root = clone_repo_root
    repo_url = "http://localhost"

    with pytest.raises(exceptions.RepoCreationException):
        GitRepo.clone(repo_url, repo_root)