From 95583f03ee53e8970b0a1fd83fcaf0300c675945 Mon Sep 17 00:00:00 2001 From: Red-GitHubBot <88117545+Red-GitHubBot@users.noreply.github.com> Date: Wed, 1 Jun 2022 01:11:01 +0200 Subject: [PATCH] [3.4] Update Downloader's git tests to work with Git 2.36+ (#5690) (#5715) There's no need to update RepoManager's code as: - regex for parsing output about ambiguous refs properly treats the date as part of description regardless of ref type - code for checking if module exists doesn't use the contents of the error message; the test only really checks for it to make sure that it triggers the error case we're actually testing for. We could instead just remove it too. (cherry picked from commit ec55622418810731e1ee2ede1569f81f9bddeeec) Co-authored-by: Jakub Kuczys <6032823+jack1142@users.noreply.github.com> Co-authored-by: Jakub Kuczys <6032823+jack1142@users.noreply.github.com> --- tests/cogs/downloader/test_git.py | 47 ++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/tests/cogs/downloader/test_git.py b/tests/cogs/downloader/test_git.py index 37eace9a2..e1cc1d517 100644 --- a/tests/cogs/downloader/test_git.py +++ b/tests/cogs/downloader/test_git.py @@ -339,10 +339,33 @@ async def test_git_get_full_sha1_from_ambiguous_commits(git_repo): @pytest.mark.skipif( - GIT_VERSION < (2, 31), reason="This is test for output from Git 2.31 and newer." + GIT_VERSION < (2, 36), reason="This is test for output from Git 2.36 and newer." ) @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 object ID c6f0 is ambiguous\n" + "hint: The candidates are:\n" + "hint: c6f028f tag 2019-10-24 - ambiguous_tag_66387\n" + "hint: c6f0e5e commit 2019-10-24 - Commit ambiguous with tag.\n" + "fatal: Needed a single revision" + ) + + +@pytest.mark.skipif( + not ((2, 31) <= GIT_VERSION < (2, 36)), reason="This is test for output from Git >=2.31,<2.36." +) +@pytest.mark.asyncio +async def test_git_get_full_sha1_from_ambiguous_tag_and_commit_pre_2_36(git_repo): # 2 ambiguous refs: # branch ambiguous_with_tag - c6f0e5ec04d99bdf8c6c78ff20d66d286eecb3ea # tag ambiguous_tag_66387 - c6f0e5ec04d99bdf8c6c78ff20d66d286eecb3ea @@ -476,8 +499,30 @@ async def test_git_check_if_module_exists_true(git_repo): assert p.returncode == 0 +@pytest.mark.skipif( + GIT_VERSION < (2, 36), reason="This is test for output from Git 2.36 and newer." +) @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: path 'mycog/__init__.py' does not exist in 'a7120330cc179396914e0d6af80cfa282adc124b'" + ) + + +@pytest.mark.skipif( + GIT_VERSION >= (2, 36), reason="This is test for output from Git older than 2.31." +) +@pytest.mark.asyncio +async def test_git_check_if_module_exists_false_pre_2_36(git_repo): p = await git_repo._run( ProcessFormatter().format( git_repo.GIT_CHECK_IF_MODULE_EXISTS,