mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-06-28 06:41:43 +00:00
feat: add ability to suppress git hints
It can be done by setting options in command. The commit author/email is also now using this logic
This commit is contained in:
@ -74,7 +74,7 @@ def test_fetch_empty(remote_source: RemoteSource, mocker: MockerFixture) -> None
|
||||
check_output_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_fetch_existing(remote_source: RemoteSource, mocker: MockerFixture) -> None:
|
||||
def test_fetch_existing(sources: Sources, remote_source: RemoteSource, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must fetch new package via fetch command
|
||||
"""
|
||||
@ -86,18 +86,19 @@ def test_fetch_existing(remote_source: RemoteSource, mocker: MockerFixture) -> N
|
||||
head_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.head", return_value="sha")
|
||||
|
||||
local = Path("local")
|
||||
assert Sources.fetch(local, remote_source) == "sha"
|
||||
assert sources.fetch(local, remote_source) == "sha"
|
||||
fetch_mock.assert_called_once_with(local, branch=remote_source.branch)
|
||||
check_output_mock.assert_has_calls([
|
||||
MockCall("git", "checkout", "--force", remote_source.branch, cwd=local, logger=pytest.helpers.anyvar(int)),
|
||||
MockCall("git", "reset", "--quiet", "--hard", f"origin/{remote_source.branch}",
|
||||
MockCall(*sources.git(), "checkout", "--force", remote_source.branch,
|
||||
cwd=local, logger=pytest.helpers.anyvar(int)),
|
||||
MockCall(*sources.git(), "reset", "--quiet", "--hard", f"origin/{remote_source.branch}",
|
||||
cwd=local, logger=pytest.helpers.anyvar(int)),
|
||||
])
|
||||
move_mock.assert_called_once_with(local.resolve(), local)
|
||||
head_mock.assert_called_once_with(local)
|
||||
|
||||
|
||||
def test_fetch_new(remote_source: RemoteSource, mocker: MockerFixture) -> None:
|
||||
def test_fetch_new(sources: Sources, remote_source: RemoteSource, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must fetch new package via clone command
|
||||
"""
|
||||
@ -107,19 +108,21 @@ def test_fetch_new(remote_source: RemoteSource, mocker: MockerFixture) -> None:
|
||||
head_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.head", return_value="sha")
|
||||
|
||||
local = Path("local")
|
||||
assert Sources.fetch(local, remote_source) == "sha"
|
||||
assert sources.fetch(local, remote_source) == "sha"
|
||||
check_output_mock.assert_has_calls([
|
||||
MockCall("git", "clone", "--quiet", "--depth", "1", "--branch", remote_source.branch, "--single-branch",
|
||||
remote_source.git_url, str(local), cwd=local.parent, logger=pytest.helpers.anyvar(int)),
|
||||
MockCall("git", "checkout", "--force", remote_source.branch, cwd=local, logger=pytest.helpers.anyvar(int)),
|
||||
MockCall("git", "reset", "--quiet", "--hard", f"origin/{remote_source.branch}",
|
||||
MockCall(*sources.git(), "clone", "--quiet", "--depth", "1", "--branch", remote_source.branch,
|
||||
"--single-branch", remote_source.git_url, str(local),
|
||||
cwd=local.parent, logger=pytest.helpers.anyvar(int)),
|
||||
MockCall(*sources.git(), "checkout", "--force", remote_source.branch,
|
||||
cwd=local, logger=pytest.helpers.anyvar(int)),
|
||||
MockCall(*sources.git(), "reset", "--quiet", "--hard", f"origin/{remote_source.branch}",
|
||||
cwd=local, logger=pytest.helpers.anyvar(int))
|
||||
])
|
||||
move_mock.assert_called_once_with(local.resolve(), local)
|
||||
head_mock.assert_called_once_with(local)
|
||||
|
||||
|
||||
def test_fetch_new_without_remote(mocker: MockerFixture) -> None:
|
||||
def test_fetch_new_without_remote(sources: Sources, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must fetch nothing in case if no remote set
|
||||
"""
|
||||
@ -129,10 +132,11 @@ def test_fetch_new_without_remote(mocker: MockerFixture) -> None:
|
||||
head_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.head", return_value="sha")
|
||||
|
||||
local = Path("local")
|
||||
assert Sources.fetch(local, RemoteSource(source=PackageSource.Archive)) == "sha"
|
||||
assert sources.fetch(local, RemoteSource(source=PackageSource.Archive)) == "sha"
|
||||
check_output_mock.assert_has_calls([
|
||||
MockCall("git", "checkout", "--force", Sources.DEFAULT_BRANCH, cwd=local, logger=pytest.helpers.anyvar(int)),
|
||||
MockCall("git", "reset", "--quiet", "--hard", f"origin/{Sources.DEFAULT_BRANCH}",
|
||||
MockCall(*sources.git(), "checkout", "--force", sources.DEFAULT_BRANCH,
|
||||
cwd=local, logger=pytest.helpers.anyvar(int)),
|
||||
MockCall(*sources.git(), "reset", "--quiet", "--hard", f"origin/{sources.DEFAULT_BRANCH}",
|
||||
cwd=local, logger=pytest.helpers.anyvar(int))
|
||||
])
|
||||
move_mock.assert_called_once_with(local.resolve(), local)
|
||||
@ -153,15 +157,15 @@ def test_fetch_relative(remote_source: RemoteSource, mocker: MockerFixture) -> N
|
||||
head_mock.assert_called_once_with(local)
|
||||
|
||||
|
||||
def test_has_remotes(mocker: MockerFixture) -> None:
|
||||
def test_has_remotes(sources: Sources, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must ask for remotes
|
||||
"""
|
||||
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.check_output", return_value="origin")
|
||||
|
||||
local = Path("local")
|
||||
assert Sources.has_remotes(local)
|
||||
check_output_mock.assert_called_once_with("git", "remote", cwd=local, logger=pytest.helpers.anyvar(int))
|
||||
assert sources.has_remotes(local)
|
||||
check_output_mock.assert_called_once_with(*sources.git(), "remote", cwd=local, logger=pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
def test_has_remotes_empty(mocker: MockerFixture) -> None:
|
||||
@ -172,7 +176,7 @@ def test_has_remotes_empty(mocker: MockerFixture) -> None:
|
||||
assert not Sources.has_remotes(Path("local"))
|
||||
|
||||
|
||||
def test_init(mocker: MockerFixture) -> None:
|
||||
def test_init(sources: Sources, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must create empty repository at the specified path
|
||||
"""
|
||||
@ -183,9 +187,9 @@ def test_init(mocker: MockerFixture) -> None:
|
||||
commit_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.commit")
|
||||
|
||||
local = Path("local")
|
||||
Sources.init(local)
|
||||
check_output_mock.assert_called_once_with("git", "init", "--quiet", "--initial-branch", Sources.DEFAULT_BRANCH,
|
||||
cwd=local, logger=pytest.helpers.anyvar(int))
|
||||
sources.init(local)
|
||||
check_output_mock.assert_called_once_with(*sources.git(), "init", "--quiet", "--initial-branch",
|
||||
sources.DEFAULT_BRANCH, cwd=local, logger=pytest.helpers.anyvar(int))
|
||||
add_mock.assert_called_once_with(local, "PKGBUILD", ".SRCINFO", "local")
|
||||
commit_mock.assert_called_once_with(local)
|
||||
|
||||
@ -267,7 +271,7 @@ def test_patch_create_with_newline(mocker: MockerFixture) -> None:
|
||||
assert Sources.patch_create(Path("local"), "glob").endswith("\n")
|
||||
|
||||
|
||||
def test_push(package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
def test_push(package_ahriman: Package, sources: Sources, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must correctly push files to remote repository
|
||||
"""
|
||||
@ -277,11 +281,11 @@ def test_push(package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
|
||||
commit_author = ("commit author", "user@host")
|
||||
local = Path("local")
|
||||
Sources.push(local, package_ahriman.remote, "glob", commit_author=commit_author)
|
||||
sources.push(local, package_ahriman.remote, "glob", commit_author=commit_author)
|
||||
add_mock.assert_called_once_with(local, "glob")
|
||||
commit_mock.assert_called_once_with(local, commit_author=commit_author)
|
||||
check_output_mock.assert_called_once_with(
|
||||
"git", "push", "--quiet", package_ahriman.remote.git_url, package_ahriman.remote.branch,
|
||||
*sources.git(), "push", "--quiet", package_ahriman.remote.git_url, package_ahriman.remote.branch,
|
||||
cwd=local, logger=pytest.helpers.anyvar(int))
|
||||
|
||||
|
||||
@ -308,7 +312,7 @@ def test_add(sources: Sources, mocker: MockerFixture) -> None:
|
||||
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=sources.logger
|
||||
*sources.git(), "add", "1", "2", "1", "2", cwd=local, logger=sources.logger
|
||||
)
|
||||
|
||||
|
||||
@ -323,7 +327,7 @@ def test_add_intent_to_add(sources: Sources, mocker: MockerFixture) -> None:
|
||||
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=sources.logger
|
||||
*sources.git(), "add", "--intent-to-add", "1", "2", "1", "2", cwd=local, logger=sources.logger
|
||||
)
|
||||
|
||||
|
||||
@ -350,13 +354,8 @@ def test_commit(sources: Sources, mocker: MockerFixture) -> None:
|
||||
user, email = sources.DEFAULT_COMMIT_AUTHOR
|
||||
assert sources.commit(local, message=message)
|
||||
check_output_mock.assert_called_once_with(
|
||||
"git", "commit", "--quiet", "--message", message,
|
||||
cwd=local, logger=sources.logger, environment={
|
||||
"GIT_AUTHOR_NAME": user,
|
||||
"GIT_AUTHOR_EMAIL": email,
|
||||
"GIT_COMMITTER_NAME": user,
|
||||
"GIT_COMMITTER_EMAIL": email,
|
||||
}
|
||||
*sources.git(), "-c", f"user.email=\"{email}\"", "-c", f"user.name=\"{user}\"",
|
||||
"commit", "--quiet", "--message", message, cwd=local, logger=sources.logger
|
||||
)
|
||||
|
||||
|
||||
@ -383,13 +382,8 @@ def test_commit_author(sources: Sources, mocker: MockerFixture) -> None:
|
||||
user, email = author = ("commit author", "user@host")
|
||||
assert sources.commit(Path("local"), message=message, commit_author=author)
|
||||
check_output_mock.assert_called_once_with(
|
||||
"git", "commit", "--quiet", "--message", message,
|
||||
cwd=local, logger=sources.logger, environment={
|
||||
"GIT_AUTHOR_NAME": user,
|
||||
"GIT_AUTHOR_EMAIL": email,
|
||||
"GIT_COMMITTER_NAME": user,
|
||||
"GIT_COMMITTER_EMAIL": email,
|
||||
}
|
||||
*sources.git(), "-c", f"user.email=\"{email}\"", "-c", f"user.name=\"{user}\"",
|
||||
"commit", "--quiet", "--message", message, cwd=local, logger=sources.logger
|
||||
)
|
||||
|
||||
|
||||
@ -404,13 +398,8 @@ def test_commit_autogenerated_message(sources: Sources, mocker: MockerFixture) -
|
||||
assert sources.commit(Path("local"))
|
||||
user, email = sources.DEFAULT_COMMIT_AUTHOR
|
||||
check_output_mock.assert_called_once_with(
|
||||
"git", "commit", "--quiet", "--message", pytest.helpers.anyvar(str, strict=True),
|
||||
cwd=local, logger=sources.logger, environment={
|
||||
"GIT_AUTHOR_NAME": user,
|
||||
"GIT_AUTHOR_EMAIL": email,
|
||||
"GIT_COMMITTER_NAME": user,
|
||||
"GIT_COMMITTER_EMAIL": email,
|
||||
}
|
||||
*sources.git(), "-c", f"user.email=\"{email}\"", "-c", f"user.name=\"{user}\"",
|
||||
"commit", "--quiet", "--message", pytest.helpers.anyvar(str, strict=True), cwd=local, logger=sources.logger
|
||||
)
|
||||
|
||||
|
||||
@ -422,7 +411,7 @@ def test_diff(sources: Sources, mocker: MockerFixture) -> None:
|
||||
|
||||
local = Path("local")
|
||||
assert sources.diff(local)
|
||||
check_output_mock.assert_called_once_with("git", "diff", cwd=local, logger=sources.logger)
|
||||
check_output_mock.assert_called_once_with(*sources.git(), "diff", cwd=local, logger=sources.logger)
|
||||
|
||||
|
||||
def test_diff_specific(sources: Sources, mocker: MockerFixture) -> None:
|
||||
@ -433,7 +422,7 @@ def test_diff_specific(sources: Sources, mocker: MockerFixture) -> None:
|
||||
|
||||
local = Path("local")
|
||||
assert sources.diff(local, "hash")
|
||||
check_output_mock.assert_called_once_with("git", "diff", "hash", cwd=local, logger=sources.logger)
|
||||
check_output_mock.assert_called_once_with(*sources.git(), "diff", "hash", cwd=local, logger=sources.logger)
|
||||
|
||||
|
||||
def test_fetch_until(sources: Sources, mocker: MockerFixture) -> None:
|
||||
@ -450,10 +439,12 @@ def test_fetch_until(sources: Sources, mocker: MockerFixture) -> None:
|
||||
local = Path("local")
|
||||
sources.fetch_until(local, branch="master", commit_sha="sha")
|
||||
check_output_mock.assert_has_calls([
|
||||
MockCall("git", "fetch", "--quiet", "--depth", "1", "origin", "master", cwd=local, logger=sources.logger),
|
||||
MockCall("git", "cat-file", "-e", "sha", cwd=local, logger=sources.logger),
|
||||
MockCall("git", "fetch", "--quiet", "--depth", "2", "origin", "master", cwd=local, logger=sources.logger),
|
||||
MockCall("git", "cat-file", "-e", "sha", cwd=local, logger=sources.logger),
|
||||
MockCall(*sources.git(), "fetch", "--quiet", "--depth", "1", "origin", "master",
|
||||
cwd=local, logger=sources.logger),
|
||||
MockCall(*sources.git(), "cat-file", "-e", "sha", cwd=local, logger=sources.logger),
|
||||
MockCall(*sources.git(), "fetch", "--quiet", "--depth", "2", "origin", "master",
|
||||
cwd=local, logger=sources.logger),
|
||||
MockCall(*sources.git(), "cat-file", "-e", "sha", cwd=local, logger=sources.logger),
|
||||
])
|
||||
|
||||
|
||||
@ -466,8 +457,9 @@ def test_fetch_until_first(sources: Sources, mocker: MockerFixture) -> None:
|
||||
local = Path("local")
|
||||
sources.fetch_until(local, branch="master")
|
||||
check_output_mock.assert_has_calls([
|
||||
MockCall("git", "fetch", "--quiet", "--depth", "1", "origin", "master", cwd=local, logger=sources.logger),
|
||||
MockCall("git", "cat-file", "-e", "HEAD", cwd=local, logger=sources.logger),
|
||||
MockCall(*sources.git(), "fetch", "--quiet", "--depth", "1", "origin", "master",
|
||||
cwd=local, logger=sources.logger),
|
||||
MockCall(*sources.git(), "cat-file", "-e", "HEAD", cwd=local, logger=sources.logger),
|
||||
])
|
||||
|
||||
|
||||
@ -480,11 +472,27 @@ def test_fetch_until_all_branches(sources: Sources, mocker: MockerFixture) -> No
|
||||
local = Path("local")
|
||||
sources.fetch_until(local)
|
||||
check_output_mock.assert_has_calls([
|
||||
MockCall("git", "fetch", "--quiet", "--depth", "1", cwd=local, logger=sources.logger),
|
||||
MockCall("git", "cat-file", "-e", "HEAD", cwd=local, logger=sources.logger),
|
||||
MockCall(*sources.git(), "fetch", "--quiet", "--depth", "1", cwd=local, logger=sources.logger),
|
||||
MockCall(*sources.git(), "cat-file", "-e", "HEAD", cwd=local, logger=sources.logger),
|
||||
])
|
||||
|
||||
|
||||
def test_git(sources: Sources) -> None:
|
||||
"""
|
||||
must correctly generate git command
|
||||
"""
|
||||
assert sources.git() == ["git", "-c", "init.defaultBranch=\"master\""]
|
||||
|
||||
|
||||
def test_git_overrides(sources: Sources) -> None:
|
||||
"""
|
||||
must correctly generate git command with additional settings
|
||||
"""
|
||||
assert sources.git({"user.email": "ahriman@localhost"}) == [
|
||||
"git", "-c", "init.defaultBranch=\"master\"", "-c", "user.email=\"ahriman@localhost\""
|
||||
]
|
||||
|
||||
|
||||
def test_has_changes(sources: Sources, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must correctly identify if there are changes
|
||||
@ -493,12 +501,12 @@ def test_has_changes(sources: Sources, mocker: MockerFixture) -> None:
|
||||
|
||||
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.check_output", return_value="M a.txt")
|
||||
assert sources.has_changes(local)
|
||||
check_output_mock.assert_called_once_with("git", "diff", "--cached", "--name-only",
|
||||
check_output_mock.assert_called_once_with(*sources.git(), "diff", "--cached", "--name-only",
|
||||
cwd=local, logger=sources.logger)
|
||||
|
||||
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.check_output", return_value="")
|
||||
assert not sources.has_changes(local)
|
||||
check_output_mock.assert_called_once_with("git", "diff", "--cached", "--name-only",
|
||||
check_output_mock.assert_called_once_with(*sources.git(), "diff", "--cached", "--name-only",
|
||||
cwd=local, logger=sources.logger)
|
||||
|
||||
|
||||
@ -510,7 +518,7 @@ def test_head(sources: Sources, mocker: MockerFixture) -> None:
|
||||
local = Path("local")
|
||||
|
||||
assert sources.head(local) == "sha"
|
||||
check_output_mock.assert_called_once_with("git", "rev-parse", "HEAD", cwd=local, logger=sources.logger)
|
||||
check_output_mock.assert_called_once_with(*sources.git(), "rev-parse", "HEAD", cwd=local, logger=sources.logger)
|
||||
|
||||
|
||||
def test_head_specific(sources: Sources, mocker: MockerFixture) -> None:
|
||||
@ -521,7 +529,7 @@ def test_head_specific(sources: Sources, mocker: MockerFixture) -> None:
|
||||
local = Path("local")
|
||||
|
||||
assert sources.head(local, "master") == "sha"
|
||||
check_output_mock.assert_called_once_with("git", "rev-parse", "master", cwd=local, logger=sources.logger)
|
||||
check_output_mock.assert_called_once_with(*sources.git(), "rev-parse", "master", cwd=local, logger=sources.logger)
|
||||
|
||||
|
||||
def test_move(sources: Sources, mocker: MockerFixture) -> None:
|
||||
@ -554,7 +562,7 @@ def test_patch_apply(sources: Sources, mocker: MockerFixture) -> None:
|
||||
local = Path("local")
|
||||
sources.patch_apply(local, patch)
|
||||
check_output_mock.assert_called_once_with(
|
||||
"git", "apply", "--ignore-space-change", "--ignore-whitespace",
|
||||
*sources.git(), "apply", "--ignore-space-change", "--ignore-whitespace",
|
||||
cwd=local, input_data=patch.value, logger=sources.logger
|
||||
)
|
||||
|
||||
|
Reference in New Issue
Block a user