Fix git_repository _error function arguments to string conversion.
Fixes #9033
Closes #9061.
PiperOrigin-RevId: 322147280
diff --git a/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/GitRepositoryBlackBoxTest.java b/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/GitRepositoryBlackBoxTest.java
index 27b0754..b3d7916 100644
--- a/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/GitRepositoryBlackBoxTest.java
+++ b/src/test/java/com/google/devtools/build/lib/blackbox/tests/workspace/GitRepositoryBlackBoxTest.java
@@ -15,12 +15,14 @@
package com.google.devtools.build.lib.blackbox.tests.workspace;
+import static com.google.common.truth.Truth.assertThat;
import static com.google.devtools.build.lib.blackbox.tests.workspace.RepoWithRuleWritingTextGenerator.callRule;
import static com.google.devtools.build.lib.blackbox.tests.workspace.RepoWithRuleWritingTextGenerator.loadRule;
import com.google.devtools.build.lib.blackbox.framework.BlackBoxTestContext;
import com.google.devtools.build.lib.blackbox.framework.BuilderRunner;
import com.google.devtools.build.lib.blackbox.framework.PathUtils;
+import com.google.devtools.build.lib.blackbox.framework.ProcessResult;
import com.google.devtools.build.lib.blackbox.junit.AbstractBlackBoxTest;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -241,6 +243,26 @@
WorkspaceTestUtils.assertLinesExactly(outPath, HELLO_FROM_BRANCH);
}
+ /** Tests that the error message is produced if the git repository does not exist. */
+ @Test
+ public void testGitRepositoryErrorMessage() throws Exception {
+ context()
+ .write(
+ "WORKSPACE",
+ "load(\"@bazel_tools//tools/build_defs/repo:git.bzl\", \"git_repository\")",
+ "git_repository(",
+ " name='ext',",
+ " remote='file:///some_path',",
+ " commit='some_hash',",
+ ")");
+
+ // This creates Bazel without MSYS, see implementation for details.
+ BuilderRunner bazel = WorkspaceTestUtils.bazel(context());
+ ProcessResult result = bazel.shouldFail().build("@ext//:write_text");
+ assertThat(result.errString()).contains("error running 'git fetch");
+ assertThat(result.errString()).contains("fatal: Could not read from remote repository.");
+ }
+
private static String setupGitRepository(BlackBoxTestContext context, Path repo)
throws Exception {
GitRepositoryHelper gitRepository = initGitRepository(context, repo);
diff --git a/tools/build_defs/repo/git_worker.bzl b/tools/build_defs/repo/git_worker.bzl
index 74caca0..228b371 100644
--- a/tools/build_defs/repo/git_worker.bzl
+++ b/tools/build_defs/repo/git_worker.bzl
@@ -75,7 +75,7 @@
shallow = shallow,
reset_ref = reset_ref,
fetch_ref = fetch_ref,
- remote = ctx.attr.remote,
+ remote = str(ctx.attr.remote),
init_submodules = ctx.attr.init_submodules,
)
@@ -178,4 +178,5 @@
)
def _error(name, command, stderr):
- fail("error running '%s' while working with @%s:\n%s" % (" ".join(command).strip(), name, stderr))
+ command_text = " ".join([str(item).strip() for item in command])
+ fail("error running '%s' while working with @%s:\n%s" % (command_text, name, stderr))