def test_fetch_and_reset(temp_repo_static): """ Tests updating already cloned repo, which was rebased. Prevents ``fatal: refusing to merge unrelated histories``. """ arca = Arca(base_dir=BASE_DIR) initial_value = str(uuid4()) temp_repo_static.file_path.write_text(initial_value) temp_repo_static.repo.index.add([str(temp_repo_static.file_path)]) temp_repo_static.repo.index.commit("Update") initial_commit = temp_repo_static.repo.head.object.hexsha for _ in range(5): temp_repo_static.file_path.write_text(str(uuid4())) temp_repo_static.repo.index.add([str(temp_repo_static.file_path)]) temp_repo_static.repo.index.commit("Update") arca.get_files(temp_repo_static.url, temp_repo_static.branch) temp_repo_static.repo.head.reset(initial_commit) _, path_to_cloned = arca.get_files(temp_repo_static.url, temp_repo_static.branch) assert (path_to_cloned / temp_repo_static.file_path.name).read_text() == initial_value
def test_reference(): arca = Arca(base_dir=BASE_DIR) branch = "master" git_dir_1 = Path("/tmp/arca/") / str(uuid4()) git_url_1 = f"file://{git_dir_1}" filepath_1 = git_dir_1 / "test_file.txt" repo_1 = Repo.init(git_dir_1) last_uuid = None for _ in range(20): last_uuid = str(uuid4()) filepath_1.write_text(last_uuid) repo_1.index.add([str(filepath_1)]) repo_1.index.commit("Initial") # test nonexistent reference cloned_repo, cloned_repo_path = arca.get_files(git_url_1, branch, reference=Path("/tmp/arca/") / str(uuid4())) assert (cloned_repo_path / "test_file.txt").read_text() == last_uuid shutil.rmtree(str(cloned_repo_path)) # test existing reference with no common commits git_dir_2 = Path("/tmp/arca/") / str(uuid4()) filepath_2 = git_dir_2 / "test_file.txt" repo_2 = Repo.init(git_dir_2) for _ in range(20): filepath_2.write_text(str(uuid4())) repo_2.index.add([str(filepath_2)]) repo_2.index.commit("Initial") cloned_repo, cloned_repo_path = arca.get_files(git_url_1, branch, reference=git_dir_2) assert (cloned_repo_path / "test_file.txt").read_text() == last_uuid shutil.rmtree(str(cloned_repo_path)) # test existing reference with common commits git_dir_3 = Path("/tmp/arca/") / str(uuid4()) git_url_3 = f"file://{git_dir_3}" filepath_3 = git_dir_3 / "test_file.txt" repo_3 = repo_1.clone(str(git_dir_3)) # must pass string, fails otherwise for _ in range(20): last_uuid = str(uuid4()) filepath_3.write_text(last_uuid) repo_3.index.add([str(filepath_3)]) repo_3.index.commit("Initial") cloned_repo, cloned_repo_path = arca.get_files(git_url_3, branch, reference=git_dir_1) assert (cloned_repo_path / "test_file.txt").read_text() == last_uuid
def test_current_git_hash(temp_repo_static): """ Test that the :meth:`Arca.current_git_hash <arca.Arca.current_git_hash>` behaves the same when ``single_pull`` is disabled or enabled. """ arca = Arca(base_dir=BASE_DIR) repo, _ = arca.get_files(temp_repo_static.url, temp_repo_static.branch) long_hash = arca.current_git_hash(temp_repo_static.url, temp_repo_static.branch, repo) short_hash = arca.current_git_hash(temp_repo_static.url, temp_repo_static.branch, repo, short=True) assert len(short_hash) < len(long_hash) assert long_hash.startswith(short_hash) arca = Arca(base_dir=BASE_DIR, single_pull=True) repo, _ = arca.get_files(temp_repo_static.url, temp_repo_static.branch) long_hash_single_pull = arca.current_git_hash(temp_repo_static.url, temp_repo_static.branch, repo) short_hash_single_pull = arca.current_git_hash(temp_repo_static.url, temp_repo_static.branch, repo, short=True) assert long_hash == long_hash_single_pull assert short_hash == short_hash_single_pull
def list_python_versions(self): from arca import Arca arca = Arca() _, pyenv = arca.get_files("https://github.com/pyenv/pyenv.git", "master") build_for = re.compile(r"^3\.[67]\.[0-9]+$") for path in sorted( (pyenv / "plugins/python-build/share/python-build/").iterdir()): if path.is_dir(): continue if build_for.match(path.name): yield path.name
def test_depth(temp_repo_static): arca = Arca(base_dir=BASE_DIR) for _ in range(19): # since one commit is made in the fixture temp_repo_static.file_path.write_text(str(uuid4())) temp_repo_static.repo.index.add([str(temp_repo_static.file_path)]) temp_repo_static.repo.index.commit("Initial") # test that in default settings, the whole repo is pulled in one go cloned_repo, cloned_repo_path = arca.get_files(temp_repo_static.url, temp_repo_static.branch) assert cloned_repo.commit().count() == 1 # default is 1 # test when pulled again, the depth is increased since the local copy is stored temp_repo_static.file_path.write_text(str(uuid4())) temp_repo_static.repo.index.add([str(temp_repo_static.file_path)]) temp_repo_static.repo.index.commit("Initial") cloned_repo, cloned_repo_path = arca.get_files(temp_repo_static.url, temp_repo_static.branch) assert cloned_repo.commit().count() == 2 shutil.rmtree(str(cloned_repo_path)) # test that when setting a certain depth, at least the depth is pulled (in case of merges etc) cloned_repo, cloned_repo_path = arca.get_files(temp_repo_static.url, temp_repo_static.branch, depth=10) assert cloned_repo.commit().count() >= 10 before_second_pull = cloned_repo.commit().count() # test when pulled again, the depth setting is ignored temp_repo_static.file_path.write_text(str(uuid4())) temp_repo_static.repo.index.add([str(temp_repo_static.file_path)]) temp_repo_static.repo.index.commit("Initial") cloned_repo, cloned_repo_path = arca.get_files(temp_repo_static.url, temp_repo_static.branch) assert cloned_repo.commit().count() == before_second_pull + 1 shutil.rmtree(str(cloned_repo_path)) # test when setting depth bigger than repo size, no fictional commits are included cloned_repo, cloned_repo_path = arca.get_files(temp_repo_static.url, temp_repo_static.branch, depth=100) assert cloned_repo.commit().count() == 22 # 20 plus the 2 extra commits shutil.rmtree(str(cloned_repo_path)) # test no limit cloned_repo, cloned_repo_path = arca.get_files(temp_repo_static.url, temp_repo_static.branch, depth=None) assert cloned_repo.commit().count() == 22 # 20 plus the 2 extra commits
def test_get_reference_repository(temp_repo_static): """ Test that the :meth:`Arca.get_reference_repository` works when reference is not provided by the user or when branch `master` is not pulled first (as it is in other tests). """ temp_repo_static.file_path.write_text("master") temp_repo_static.repo.index.add([str(temp_repo_static.file_path)]) temp_repo_static.repo.index.commit("Initial") for branch in "branch1", "branch2", "branch3": temp_repo_static.repo.create_head(branch) temp_repo_static.repo.branches[branch].checkout() temp_repo_static.file_path.write_text(branch) temp_repo_static.repo.index.add([str(temp_repo_static.file_path)]) temp_repo_static.repo.index.commit(branch) arca = Arca(base_dir=BASE_DIR) for branch in "branch1", "branch2", "master", "branch3": _, path = arca.get_files(temp_repo_static.url, branch) assert (path / temp_repo_static.file_path.name).read_text() == branch
def test_pull_error(): arca = Arca(base_dir=BASE_DIR) git_dir = Path("/tmp/arca/") / str(uuid4()) git_url = f"file://{git_dir}" with pytest.raises(PullError): arca.get_files(git_url, "master") filepath = git_dir / "test_file.txt" repo = Repo.init(git_dir) filepath.write_text(str(uuid4())) repo.index.add([str(filepath)]) repo.index.commit("Initial") arca.get_files(git_url, "master") with pytest.raises(PullError): arca.get_files(git_url, "some_branch") shutil.rmtree(str(git_dir)) with pytest.raises(PullError): arca.get_files(git_url, "master")