fix case when no files were commited in remote push trigger

The issue appears together with --intent-to-add flag for adding new
files. Original testing has been performed by having already added new
files, thus it passed all checks.

This commit also adds `commit_author` option which will allow to
overwrite the author.
This commit is contained in:
2022-11-14 00:59:43 +02:00
parent b2ed383de0
commit cdd66ee780
6 changed files with 68 additions and 29 deletions

View File

@ -193,7 +193,7 @@ def test_patch_create(mocker: MockerFixture) -> None:
diff_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.diff")
Sources.patch_create(Path("local"), "glob")
add_mock.assert_called_once_with(Path("local"), "glob")
add_mock.assert_called_once_with(Path("local"), "glob", intent_to_add=True)
diff_mock.assert_called_once_with(Path("local"))
@ -214,10 +214,11 @@ def test_push(package_ahriman: Package, mocker: MockerFixture) -> None:
commit_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.commit")
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
author = "commit author <user@host>"
local = Path("local")
Sources.push(Path("local"), package_ahriman.remote, "glob")
Sources.push(Path("local"), package_ahriman.remote, "glob", commit_author=author)
add_mock.assert_called_once_with(local, "glob")
commit_mock.assert_called_once_with(local)
commit_mock.assert_called_once_with(local, author=author)
check_output_mock.assert_called_once_with(
"git", "push", package_ahriman.remote.git_url, package_ahriman.remote.branch,
cwd=local, logger=pytest.helpers.anyvar(int))
@ -233,6 +234,21 @@ def test_add(sources: Sources, mocker: MockerFixture) -> None:
local = Path("local")
sources.add(local, "pattern1", "pattern2")
glob_mock.assert_has_calls([MockCall("pattern1"), MockCall("pattern2")])
check_output_mock.assert_called_once_with(
"git", "add", "1", "2", "1", "2", cwd=local, logger=pytest.helpers.anyvar(int)
)
def test_add_intent_to_add(sources: Sources, mocker: MockerFixture) -> None:
"""
must add files to git with --intent-to-add flag
"""
glob_mock = mocker.patch("pathlib.Path.glob", return_value=[Path("local/1"), Path("local/2")])
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
local = Path("local")
sources.add(local, "pattern1", "pattern2", intent_to_add=True)
glob_mock.assert_has_calls([MockCall("pattern1"), MockCall("pattern2")])
check_output_mock.assert_called_once_with(
"git", "add", "--intent-to-add", "1", "2", "1", "2", cwd=local, logger=pytest.helpers.anyvar(int)
)
@ -256,14 +272,30 @@ def test_commit(sources: Sources, mocker: MockerFixture) -> None:
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
local = Path("local")
commit_message = "Commit message"
sources.commit(local, commit_message=commit_message)
message = "Commit message"
sources.commit(local, message=message)
check_output_mock.assert_called_once_with(
"git", "commit", "--allow-empty", "--message", commit_message, cwd=local, logger=pytest.helpers.anyvar(int)
"git", "commit", "--allow-empty", "--message", message, cwd=local, logger=pytest.helpers.anyvar(int)
)
def test_commit_autogenerated(sources: Sources, mocker: MockerFixture) -> None:
def test_commit_author(sources: Sources, mocker: MockerFixture) -> None:
"""
must commit changes with commit author
"""
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.Sources._check_output")
local = Path("local")
message = "Commit message"
author = "commit author <user@host>"
sources.commit(Path("local"), message=message, author=author)
check_output_mock.assert_called_once_with(
"git", "commit", "--allow-empty", "--message", message, "--author", author,
cwd=local, logger=pytest.helpers.anyvar(int)
)
def test_commit_autogenerated_message(sources: Sources, mocker: MockerFixture) -> None:
"""
must commit changes with autogenerated commit message
"""

View File

@ -17,17 +17,14 @@ def test_package_update(package_ahriman: Package, mocker: MockerFixture) -> None
"""
rmtree_mock = mocker.patch("shutil.rmtree")
fetch_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.fetch")
copytree_mock = mocker.patch("shutil.copytree")
local = Path("local")
RemotePush.package_update(package_ahriman, local)
rmtree_mock.assert_has_calls([
MockCall(local / package_ahriman.base, ignore_errors=True),
MockCall(pytest.helpers.anyvar(int), onerror=pytest.helpers.anyvar(int)), # removal of the TemporaryDirectory
MockCall(local / package_ahriman.base / ".git", ignore_errors=True),
])
fetch_mock.assert_called_once_with(pytest.helpers.anyvar(int), package_ahriman.remote)
copytree_mock.assert_called_once_with(pytest.helpers.anyvar(int), local / package_ahriman.base)
def test_packages_update(result: Result, package_ahriman: Package, mocker: MockerFixture) -> None:
@ -53,7 +50,9 @@ def test_run(configuration: Configuration, result: Result, package_ahriman: Pack
runner.run(result)
fetch_mock.assert_called_once_with(pytest.helpers.anyvar(int), runner.remote_source)
push_mock.assert_called_once_with(pytest.helpers.anyvar(int), runner.remote_source, package_ahriman.base)
push_mock.assert_called_once_with(
pytest.helpers.anyvar(int), runner.remote_source, package_ahriman.base, commit_author=runner.commit_author
)
def test_run_failed(configuration: Configuration, result: Result, mocker: MockerFixture) -> None:

View File

@ -40,6 +40,7 @@ target = gitremote
target = gitremote
[gitremote]
commit_author = "user <user@host>"
push_url = https://github.com/arcan1s/repository.git
pull_url = https://github.com/arcan1s/repository.git