Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit a more informative error message if git is not installed at startup #454

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion it/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ def osbenchmark(cfg, command_line):
This method should be used for benchmark invocations of the all commands besides test_execution.
These commands may have different CLI options than test_execution.
"""
err, retcode = process.run_subprocess_with_stderr(osbenchmark_command_line_for(cfg, command_line))
cmd = osbenchmark_command_line_for(cfg, command_line)
print("\nInvoking OSB:", cmd)
err, retcode = process.run_subprocess_with_stderr(cmd)
if retcode != 0:
print(err)
return retcode
Expand Down
5 changes: 2 additions & 3 deletions osbenchmark/utils/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@

def probed(f):
def probe(src, *args, **kwargs):
# Probe for -C
try:
out, _, status = process.run_subprocess_with_out_and_err(
"git -C {} --version".format(io.escape_path(src)))
out, _, status = process.run_subprocess_with_out_and_err("git --version")
except FileNotFoundError:
status = 1
if status != 0:
Expand All @@ -58,6 +56,7 @@ def is_working_copy(src):
return os.path.exists(src) and os.path.exists(os.path.join(src, ".git"))


@probed
def clone(src, remote):
io.ensure_dir(src)
# Don't swallow subprocess output, user might need to enter credentials...
Expand Down
12 changes: 8 additions & 4 deletions tests/utils/git_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ def test_version_too_old(self, run_subprocess_with_out_and_err):
git.head_revision("/src")
self.assertEqual("OpenSearch Benchmark requires at least version 2 of git. You have git version 1.4.0. Please update git.",
ctx.exception.args[0])
run_subprocess_with_out_and_err.assert_called_with("git -C /src --version")
run_subprocess_with_out_and_err.assert_called_with("git --version")

@mock.patch("osbenchmark.utils.io.ensure_dir")
@mock.patch("osbenchmark.utils.process.run_subprocess_with_out_and_err")
@mock.patch("osbenchmark.utils.process.run_subprocess_with_logging")
def test_clone_successful(self, run_subprocess_with_logging, ensure_dir):
def test_clone_successful(self, run_subprocess_with_logging, run_subprocess_with_out_and_err, ensure_dir):
run_subprocess_with_logging.return_value = 0
run_subprocess_with_out_and_err.return_value = ("git version 2.0.0", "", 0)
src = "/src"
remote = "http://github.com/some/project"

Expand All @@ -59,9 +61,11 @@ def test_clone_successful(self, run_subprocess_with_logging, ensure_dir):
run_subprocess_with_logging.assert_called_with("git clone http://github.com/some/project /src")

@mock.patch("osbenchmark.utils.io.ensure_dir")
@mock.patch("osbenchmark.utils.process.run_subprocess_with_out_and_err")
@mock.patch("osbenchmark.utils.process.run_subprocess_with_logging")
def test_clone_with_error(self, run_subprocess_with_logging, ensure_dir):
def test_clone_with_error(self, run_subprocess_with_logging, run_subprocess_with_out_and_err, ensure_dir):
run_subprocess_with_logging.return_value = 128
run_subprocess_with_out_and_err.return_value = ("git version 2.0.0", "", 0)
src = "/src"
remote = "http://github.com/some/project"

Expand Down Expand Up @@ -128,7 +132,7 @@ def test_pull(self, run_subprocess_with_out_and_err, run_subprocess_with_logging
git.pull("/src", remote="my-origin", branch="feature-branch")
run_subprocess_with_out_and_err.assert_has_calls([
# pull, fetch, rebase, checkout
mock.call("git -C /src --version")
mock.call("git --version")
] * 4)
calls = [
mock.call("git -C /src fetch --prune --tags my-origin"),
Expand Down
Loading