mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
* feat(downloader): Install cog from specific commit in repo (initial commit) - Repo and Installable have commit property now - New class inheriting from Installable - InstalledCog (old one from converters.py removed) - New Repo.checkout() method, which is also async ctx manager ref #2527 * fix(downloader): Keep information about repo's branch in config - This is needed to make sure that repo can go back from detached state in some rare unexpected cases - current branch is determined by `git symbolic-ref` now as this command errors for detached HEAD * feat(downloader): Update repo without cogs, update single cog The most important part of issue #2527 has been added here - `[p]repo update` command added - new conf format - nested dictionary repo_name->cog_name->cog_json installed libraries are now kept in conf too - `InstalledCog` renamed to `InstalledModule` - installed libraries use this class - `Downloader.installed_libraries()` and `Downloader.installed_modules()` added - `Downloader._add_to_installed()` and `Downloader._remove_from_installed()` now accept list of modules, of both cogs and libraries - `[p]cog install` tells about fails of copying cog and installing shared libraries - `[p]cog update` will truly update only chosen cogs (if provided) or cogs that need update - pinned cogs aren't checked - before update, repos are updated - to determine if update is needed `Repo.get_modified_modules()` is used - `[p]cog pin` and `[p]cog unpin` commands for pinning/unpinning cogs added - `Repo.checkout()` allows to choose ctx manager exit's checkout revision - `Repo.install_cog()` returns `InstalledModule` now and raises CopyingError (maybe breaking?) - `Repo.install_libraries()` returns 2-tuple of installed and failed libraries (maybe breaking?) - `RepoManager.get_all_cogs()` added, which returns cogs from all repos - `RepoManager.repos` property added, which contains tuple of `Repo` * test(downloader): Repo.current_branch() throws an exception, when branch can't be determined * style(downloader): rename _add_to_installed to _save_to_installed This method is used for both adding and updating existing modules in Config * refactor(downloader): add ctx.typing() for few commands `[p]cog install` is nested hell, can't wait for moving install logic to separate method * fix(downloader): refactor and fix `set` usage * perf(downloader): update commits for ALL checked modules to omit diffs next time This will also disable running git diff for cogs that have the same commit as the latest one * style(downloader): few style improvements - use of mutable object in method definition - make Repo._get_full_sha1() public method - too long line - don't use len to check if sequence is empty * feat(downloader): add `[p]cog updateallfromrepos` and `[p]cog updatetoversion` commands - moved cog update logic into `Downloader._cog_update_logic()` (lack of better name) - splitted whole cog update process into smaller methods - might still need some improvements - added new methods to `Repo` class: - `is_on_branch()` to check if repo is currently checked out to branch - `is_ancestor()` to check if one commit is ancestor of the other - fix for `Downloader._available_updates()` behaviour broken by commit 5755ab08ba67556b3863e907c6f44d80f4f13d88 * feat(downloader): try to find last commit where module is still present Enhancements: - `Installable` now has `repo` attribute containing repo object or `None` if repo is missing - `Downloader._install_cogs()` and `Downloader._reinstall_libraries()` are able to install modules from different commits of repo - `Repo.checkout()` as ctx manager will now exit to commit which was active before checking out - unification of `rev` and `hash` terms: All function parameters are explicitly called `hash`, if it can only be commit's full sha1 hash or `rev` if it can be anything that names a commit object, see [link](https://git-scm.com/docs/git-rev-parse#_specifying_revisions) - new `Repo.get_last_module_occurence()` method, which gets module's Installable from last commit in which it still occurs * docs(downloader): Add basic description for `InstalledModule` * fix(downloader): cog ignored during updates if its commit was missing After config format update, commit string is empty until update and when such cog was checked and it wasn't available in repo anymore, it was ignored * refactor(downloader): Installing cogs from specific rev will pin them * perf(downloader): Don't checkout when current commit equals target hash - changes to `Repo.checkout()`: - `exit_to_rev` is now keyword only argument - added `force_checkout` to force checkout even if `Repo.commit` value is the same as target hash * refactor(downloader): Repo._run() stderr is redirected to debug log now - added two keyword arguments: - `valid_exit_codes` which specifies valid exit codes, used to determine if stderr should be sent as debug or error level in logging - `debug_only` which specifies if stderr can be sent only as debug level in logging * style(downloader): stop using `set` as arg name in `_load_repos()` * feat(downloader): pass multiple cogs to `[p]cog (un)pin` * refactor(downloader): accept module name instead of instance, fix spelling * style(downloader): few small style changes * fix(downloader): add type annotations + fixes based on them - fix wrong type annotations and add a lot of new ones - add checks for `Installable.repo` being `None` - fix wrong return type in `Downloader._install_requirements` - show repo names correctly when updating all repos - fix error when some requirement fails to install BREAKING CHANGE: - type of `Repo.available_modules` is now consistent (always `tuple`) * tests: use same event loop policy as in Red's code * enhance(downloader): fully handle ambiguous revisions * build(deps): add pytest-mock dependency to tests extra * fix(downloader): minor fixes * feat(downloader): add tool for editing Downloader's test repo This script aims to help update the human-readable version of repo used for git integration tests in ``redbot/tests/downloader_testrepo.export`` by exporting/importing it in/from provided directory. Note ---- Editing `downloader_git_test_repo.export` file manually is strongly discouraged, especially editing any part of commit directives as that causes a change in the commit's hash. Another problem devs could encounter when trying to manually edit that file are editors that will use CRLF instead of LF for new line character(s) and therefore break it. I also used `.gitattributes` to prevent autocrlf from breaking testrepo. Also, if Git ever changes currently used SHA-1 to SHA-256 we will have to update old hashes with new ones. But it's a small drawback, when we can have human-readable version of repo. Known limitations ----------------- ``git fast-export`` exports commits without GPG signs so this script disables it in repo's config. This also means devs shouldn't use ``--gpg-sign`` flag in ``git commit`` within the test repo. * tests(downloader): add git tests and test repo for them Also added Markdown file that is even more clear than export file on what the test repo contains. This is manually created but can be automated on later date. * test(downloader): add more tests related to RepoManager These tests use expected output that is already guaranteed by git tests. * chore(CODEOWNERS): add jack1142 to Downloader's folders I know this doesn't actually give any benefit to people that don't have write permission to the repo but I saw other big fella devs doing this, so I think this might be advisable. * enhance(downloader): allow easy schema updates in future * enhance(downloader): more typing fixes, add comments for clarity * feat(downloader): add python and bot version check to update process follow-up on #2605, this commit fully fixes #1866 * chore(changelog): add towncrier entries * fix(downloader): use `*args` instead of `commands.Greedy` * fix(downloader): hot-reload issue - `InstallableType` now inherits from `IntEnum` There's desync of `InstallableType` class types due to hot-reload and `IntEnum` allows for equality check between different types * enhance(downloader): ensure there's no cog with same name installed should fix #2927 * fix(downloader): last few changes before marking as ready for review
453 lines
14 KiB
Python
453 lines
14 KiB
Python
from pathlib import Path
|
|
import subprocess as sp
|
|
|
|
import pytest
|
|
|
|
from redbot.cogs.downloader.repo_manager import ProcessFormatter, Repo
|
|
from redbot.pytest.downloader import (
|
|
cloned_git_repo,
|
|
git_repo,
|
|
git_repo_with_remote,
|
|
_session_git_repo,
|
|
)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_git_clone_nobranch(git_repo, tmp_path):
|
|
p = await git_repo._run(
|
|
ProcessFormatter().format(
|
|
git_repo.GIT_CLONE_NO_BRANCH,
|
|
url=git_repo.folder_path,
|
|
folder=tmp_path / "cloned_repo_test",
|
|
)
|
|
)
|
|
assert p.returncode == 0
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_git_clone_branch(git_repo, tmp_path):
|
|
p = await git_repo._run(
|
|
ProcessFormatter().format(
|
|
git_repo.GIT_CLONE,
|
|
branch="master",
|
|
url=git_repo.folder_path,
|
|
folder=tmp_path / "cloned_repo_test",
|
|
)
|
|
)
|
|
assert p.returncode == 0
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_git_clone_non_existent_branch(git_repo, tmp_path):
|
|
p = await git_repo._run(
|
|
ProcessFormatter().format(
|
|
git_repo.GIT_CLONE,
|
|
branch="non-existent-branch",
|
|
url=git_repo.folder_path,
|
|
folder=tmp_path / "cloned_repo_test",
|
|
)
|
|
)
|
|
assert p.returncode == 128
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_git_clone_notgit_repo(git_repo, tmp_path):
|
|
notgit_repo = tmp_path / "test_clone_folder"
|
|
p = await git_repo._run(
|
|
ProcessFormatter().format(
|
|
git_repo.GIT_CLONE, branch=None, url=notgit_repo, folder=tmp_path / "cloned_repo_test"
|
|
)
|
|
)
|
|
assert p.returncode == 128
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_git_current_branch_master(git_repo):
|
|
p = await git_repo._run(
|
|
ProcessFormatter().format(git_repo.GIT_CURRENT_BRANCH, path=git_repo.folder_path)
|
|
)
|
|
assert p.returncode == 0
|
|
assert p.stdout.decode().strip() == "master"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_git_current_branch_detached(git_repo):
|
|
await git_repo._run(
|
|
ProcessFormatter().format(
|
|
git_repo.GIT_CHECKOUT,
|
|
path=git_repo.folder_path,
|
|
rev="c950fc05a540dd76b944719c2a3302da2e2f3090",
|
|
)
|
|
)
|
|
p = await git_repo._run(
|
|
ProcessFormatter().format(git_repo.GIT_CURRENT_BRANCH, path=git_repo.folder_path)
|
|
)
|
|
assert p.returncode == 128
|
|
assert p.stderr.decode().strip() == "fatal: ref HEAD is not a symbolic ref"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_git_current_commit_on_branch(git_repo):
|
|
# HEAD on dont_add_commits (a0ccc2390883c85a361f5a90c72e1b07958939fa)
|
|
# setup
|
|
p = await git_repo._run(
|
|
ProcessFormatter().format(
|
|
git_repo.GIT_CHECKOUT, path=git_repo.folder_path, rev="dont_add_commits"
|
|
)
|
|
)
|
|
assert p.returncode == 0
|
|
|
|
p = await git_repo._run(
|
|
ProcessFormatter().format(git_repo.GIT_CURRENT_COMMIT, path=git_repo.folder_path)
|
|
)
|
|
assert p.returncode == 0
|
|
assert p.stdout.decode().strip() == "a0ccc2390883c85a361f5a90c72e1b07958939fa"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_git_current_commit_detached(git_repo):
|
|
# detached HEAD state (c950fc05a540dd76b944719c2a3302da2e2f3090)
|
|
await git_repo._run(
|
|
ProcessFormatter().format(
|
|
git_repo.GIT_CHECKOUT,
|
|
path=git_repo.folder_path,
|
|
rev="c950fc05a540dd76b944719c2a3302da2e2f3090",
|
|
)
|
|
)
|
|
p = await git_repo._run(
|
|
ProcessFormatter().format(git_repo.GIT_CURRENT_COMMIT, path=git_repo.folder_path)
|
|
)
|
|
assert p.returncode == 0
|
|
assert p.stdout.decode().strip() == "c950fc05a540dd76b944719c2a3302da2e2f3090"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_git_latest_commit(git_repo):
|
|
# HEAD on dont_add_commits (a0ccc2390883c85a361f5a90c72e1b07958939fa)
|
|
p = await git_repo._run(
|
|
ProcessFormatter().format(
|
|
git_repo.GIT_LATEST_COMMIT, path=git_repo.folder_path, branch="dont_add_commits"
|
|
)
|
|
)
|
|
assert p.returncode == 0
|
|
assert p.stdout.decode().strip() == "a0ccc2390883c85a361f5a90c72e1b07958939fa"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_git_hard_reset(cloned_git_repo, tmp_path):
|
|
staged_file = cloned_git_repo.folder_path / "staged_file.txt"
|
|
staged_file.touch()
|
|
git_dirparams = ("git", "-C", str(cloned_git_repo.folder_path))
|
|
sp.run((*git_dirparams, "add", "staged_file.txt"), check=True)
|
|
assert staged_file.exists() is True
|
|
p = await cloned_git_repo._run(
|
|
ProcessFormatter().format(
|
|
cloned_git_repo.GIT_HARD_RESET, path=cloned_git_repo.folder_path, branch="master"
|
|
)
|
|
)
|
|
assert p.returncode == 0
|
|
assert staged_file.exists() is False
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_git_pull(git_repo_with_remote, tmp_path):
|
|
# setup
|
|
staged_file = Path(git_repo_with_remote.url) / "staged_file.txt"
|
|
staged_file.touch()
|
|
git_dirparams = ("git", "-C", git_repo_with_remote.url)
|
|
sp.run((*git_dirparams, "add", "staged_file.txt"), check=True)
|
|
sp.run(
|
|
(*git_dirparams, "commit", "-m", "test commit", "--no-gpg-sign", "--no-verify"), check=True
|
|
)
|
|
assert not (git_repo_with_remote.folder_path / "staged_file.txt").exists()
|
|
|
|
p = await git_repo_with_remote._run(
|
|
ProcessFormatter().format(
|
|
git_repo_with_remote.GIT_PULL, path=git_repo_with_remote.folder_path
|
|
)
|
|
)
|
|
assert p.returncode == 0
|
|
assert (git_repo_with_remote.folder_path / "staged_file.txt").exists()
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_git_diff_file_status(git_repo):
|
|
p = await git_repo._run(
|
|
ProcessFormatter().format(
|
|
git_repo.GIT_DIFF_FILE_STATUS,
|
|
path=git_repo.folder_path,
|
|
old_rev="c950fc05a540dd76b944719c2a3302da2e2f3090",
|
|
new_rev="fb99eb7d2d5bed514efc98fe6686b368f8425745",
|
|
)
|
|
)
|
|
assert p.returncode == 0
|
|
stdout = p.stdout.strip(b"\t\n\x00 ").decode()
|
|
assert stdout == (
|
|
"A\x00added_file.txt\x00\t"
|
|
"M\x00mycog/__init__.py\x00\t"
|
|
"D\x00sample_file1.txt\x00\t"
|
|
"D\x00sample_file2.txt\x00\t"
|
|
"A\x00sample_file3.txt"
|
|
)
|
|
|
|
|
|
# might need to add test for test_git_log, but it's unused method currently
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_git_discover_remote_url(cloned_git_repo, tmp_path):
|
|
p = await cloned_git_repo._run(
|
|
ProcessFormatter().format(
|
|
cloned_git_repo.GIT_DISCOVER_REMOTE_URL, path=cloned_git_repo.folder_path
|
|
)
|
|
)
|
|
assert p.returncode == 0
|
|
assert p.stdout.decode().strip() == cloned_git_repo.url
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_git_checkout_detached_head(git_repo):
|
|
p = await git_repo._run(
|
|
ProcessFormatter().format(
|
|
git_repo.GIT_CHECKOUT,
|
|
path=git_repo.folder_path,
|
|
rev="c950fc05a540dd76b944719c2a3302da2e2f3090",
|
|
)
|
|
)
|
|
assert p.returncode == 0
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_git_checkout_branch(git_repo):
|
|
p = await git_repo._run(
|
|
ProcessFormatter().format(
|
|
git_repo.GIT_CHECKOUT, path=git_repo.folder_path, rev="dont_add_commits"
|
|
)
|
|
)
|
|
assert p.returncode == 0
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_git_checkout_non_existent_branch(git_repo):
|
|
p = await git_repo._run(
|
|
ProcessFormatter().format(
|
|
git_repo.GIT_CHECKOUT, path=git_repo.folder_path, rev="non-existent-branch"
|
|
)
|
|
)
|
|
assert p.returncode == 1
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_git_get_full_sha1_from_branch_name(git_repo):
|
|
p = await git_repo._run(
|
|
ProcessFormatter().format(
|
|
git_repo.GIT_GET_FULL_SHA1, path=git_repo.folder_path, rev="dont_add_commits"
|
|
)
|
|
)
|
|
assert p.returncode == 0
|
|
assert p.stdout.decode().strip() == "a0ccc2390883c85a361f5a90c72e1b07958939fa"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_git_get_full_sha1_from_full_hash(git_repo):
|
|
p = await git_repo._run(
|
|
ProcessFormatter().format(
|
|
git_repo.GIT_GET_FULL_SHA1,
|
|
path=git_repo.folder_path,
|
|
rev="c950fc05a540dd76b944719c2a3302da2e2f3090",
|
|
)
|
|
)
|
|
assert p.returncode == 0
|
|
assert p.stdout.decode().strip() == "c950fc05a540dd76b944719c2a3302da2e2f3090"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_git_get_full_sha1_from_short_hash(git_repo):
|
|
p = await git_repo._run(
|
|
ProcessFormatter().format(
|
|
git_repo.GIT_GET_FULL_SHA1, path=git_repo.folder_path, rev="c950"
|
|
)
|
|
)
|
|
assert p.returncode == 0
|
|
assert p.stdout.decode().strip() == "c950fc05a540dd76b944719c2a3302da2e2f3090"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_git_get_full_sha1_from_too_short_hash(git_repo):
|
|
p = await git_repo._run(
|
|
ProcessFormatter().format(git_repo.GIT_GET_FULL_SHA1, path=git_repo.folder_path, rev="c95")
|
|
)
|
|
assert p.returncode == 128
|
|
assert p.stderr.decode().strip() == "fatal: Needed a single revision"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_git_get_full_sha1_from_lightweight_tag(git_repo):
|
|
p = await git_repo._run(
|
|
ProcessFormatter().format(
|
|
git_repo.GIT_GET_FULL_SHA1, path=git_repo.folder_path, rev="lightweight"
|
|
)
|
|
)
|
|
assert p.returncode == 0
|
|
assert p.stdout.decode().strip() == "fb99eb7d2d5bed514efc98fe6686b368f8425745"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_git_get_full_sha1_from_annotated_tag(git_repo):
|
|
p = await git_repo._run(
|
|
ProcessFormatter().format(
|
|
git_repo.GIT_GET_FULL_SHA1, path=git_repo.folder_path, rev="annotated"
|
|
)
|
|
)
|
|
assert p.returncode == 0
|
|
assert p.stdout.decode().strip() == "a7120330cc179396914e0d6af80cfa282adc124b"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_git_get_full_sha1_from_invalid_ref(git_repo):
|
|
p = await git_repo._run(
|
|
ProcessFormatter().format(
|
|
git_repo.GIT_GET_FULL_SHA1, path=git_repo.folder_path, rev="invalid"
|
|
)
|
|
)
|
|
assert p.returncode == 128
|
|
assert p.stderr.decode().strip() == "fatal: Needed a single revision"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_git_get_full_sha1_from_ambiguous_commits(git_repo):
|
|
# 2 ambiguous refs:
|
|
# branch ambiguous_1 - 95da0b576271cb5bee5f3e075074c03ee05fed05
|
|
# branch ambiguous_2 - 95da0b57a416d9c8ce950554228d1fc195c30b43
|
|
p = await git_repo._run(
|
|
ProcessFormatter().format(
|
|
git_repo.GIT_GET_FULL_SHA1, path=git_repo.folder_path, rev="95da0b57"
|
|
)
|
|
)
|
|
assert p.returncode == 128
|
|
assert p.stderr.decode().strip() == (
|
|
"error: short SHA1 95da0b57 is ambiguous\n"
|
|
"hint: The candidates are:\n"
|
|
"hint: 95da0b576 commit 2019-10-22 - Ambiguous commit 16955\n"
|
|
"hint: 95da0b57a commit 2019-10-22 - Ambiguous commit 44414\n"
|
|
"fatal: Needed a single revision"
|
|
)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_git_get_full_sha1_from_ambiguous_tag_and_commit(git_repo):
|
|
# 2 ambiguous refs:
|
|
# branch ambiguous_with_tag - c6f0e5ec04d99bdf8c6c78ff20d66d286eecb3ea
|
|
# tag ambiguous_tag_66387 - c6f0e5ec04d99bdf8c6c78ff20d66d286eecb3ea
|
|
p = await git_repo._run(
|
|
ProcessFormatter().format(
|
|
git_repo.GIT_GET_FULL_SHA1, path=git_repo.folder_path, rev="c6f0"
|
|
)
|
|
)
|
|
assert p.returncode == 128
|
|
assert p.stderr.decode().strip() == (
|
|
"error: short SHA1 c6f0 is ambiguous\n"
|
|
"hint: The candidates are:\n"
|
|
"hint: c6f028f tag ambiguous_tag_66387\n"
|
|
"hint: c6f0e5e commit 2019-10-24 - Commit ambiguous with tag.\n"
|
|
"fatal: Needed a single revision"
|
|
)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_git_is_ancestor_true(git_repo):
|
|
p = await git_repo._run(
|
|
ProcessFormatter().format(
|
|
git_repo.GIT_IS_ANCESTOR,
|
|
path=git_repo.folder_path,
|
|
maybe_ancestor_rev="c950fc05a540dd76b944719c2a3302da2e2f3090",
|
|
descendant_rev="fb99eb7d2d5bed514efc98fe6686b368f8425745",
|
|
)
|
|
)
|
|
assert p.returncode == 0
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_git_is_ancestor_false(git_repo):
|
|
p = await git_repo._run(
|
|
ProcessFormatter().format(
|
|
git_repo.GIT_IS_ANCESTOR,
|
|
path=git_repo.folder_path,
|
|
maybe_ancestor_rev="fb99eb7d2d5bed514efc98fe6686b368f8425745",
|
|
descendant_rev="c950fc05a540dd76b944719c2a3302da2e2f3090",
|
|
)
|
|
)
|
|
assert p.returncode == 1
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_git_is_ancestor_invalid_ref(git_repo):
|
|
p = await git_repo._run(
|
|
ProcessFormatter().format(
|
|
git_repo.GIT_IS_ANCESTOR,
|
|
path=git_repo.folder_path,
|
|
maybe_ancestor_rev="invalid1",
|
|
descendant_rev="invalid2",
|
|
)
|
|
)
|
|
assert p.returncode == 128
|
|
assert p.stderr.decode().strip() == "fatal: Not a valid object name invalid1"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_git_check_if_module_exists_true(git_repo):
|
|
p = await git_repo._run(
|
|
ProcessFormatter().format(
|
|
git_repo.GIT_CHECK_IF_MODULE_EXISTS,
|
|
path=git_repo.folder_path,
|
|
rev="fb99eb7d2d5bed514efc98fe6686b368f8425745",
|
|
module_name="mycog",
|
|
)
|
|
)
|
|
assert p.returncode == 0
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_git_check_if_module_exists_false(git_repo):
|
|
p = await git_repo._run(
|
|
ProcessFormatter().format(
|
|
git_repo.GIT_CHECK_IF_MODULE_EXISTS,
|
|
path=git_repo.folder_path,
|
|
rev="a7120330cc179396914e0d6af80cfa282adc124b",
|
|
module_name="mycog",
|
|
)
|
|
)
|
|
assert p.returncode == 128
|
|
assert p.stderr.decode().strip() == (
|
|
"fatal: Not a valid object name a7120330cc179396914e0d6af80cfa282adc124b:mycog/__init__.py"
|
|
)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_git_find_last_occurrence_existent(git_repo):
|
|
p = await git_repo._run(
|
|
ProcessFormatter().format(
|
|
git_repo.GIT_GET_LAST_MODULE_OCCURRENCE_COMMIT,
|
|
path=git_repo.folder_path,
|
|
descendant_rev="2db662c1d341b1db7d225ccc1af4019ba5228c70",
|
|
module_name="mycog",
|
|
)
|
|
)
|
|
assert p.returncode == 0
|
|
# the command gives a commit after last occurrence
|
|
assert p.stdout.decode().strip() == "a7120330cc179396914e0d6af80cfa282adc124b"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_git_find_last_occurrence_non_existent(git_repo):
|
|
p = await git_repo._run(
|
|
ProcessFormatter().format(
|
|
git_repo.GIT_GET_LAST_MODULE_OCCURRENCE_COMMIT,
|
|
path=git_repo.folder_path,
|
|
descendant_rev="c950fc05a540dd76b944719c2a3302da2e2f3090",
|
|
module_name="mycog",
|
|
)
|
|
)
|
|
assert p.returncode == 0
|
|
assert p.stdout.decode().strip() == ""
|