aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools
diff options
context:
space:
mode:
authorGravatar David Chen <dzc@google.com>2016-01-22 11:41:43 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2016-01-22 15:56:43 +0000
commit8bc64e1d0c9a4a0ff81db56f72f45b7fd91f5fdf (patch)
treebd3ec4851077f6f221cef683b1e5724959e1b489 /src/main/java/com/google/devtools
parent16444baf21780c4bff00b9736b268e97157e6bc2 (diff)
Clearer error message if git repository cannot be cloned. Minor style cleanup.
Currently, if an error occurs when cloning a git repository, resulting in a GitAPIException being thrown, the error message printed is not very clear. One example of this is if the repository is being cloned over SSH since cloning over SSH is not currently supported. -- MOS_MIGRATED_REVID=112770885
Diffstat (limited to 'src/main/java/com/google/devtools')
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/repository/GitCloner.java41
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/repository/GitRepositoryFunction.java2
2 files changed, 18 insertions, 25 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/GitCloner.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/GitCloner.java
index 5fd74fd13c..c4a98c5818 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/repository/GitCloner.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/GitCloner.java
@@ -58,11 +58,10 @@ public class GitCloner {
}
Repository repository = null;
try {
- repository =
- new FileRepositoryBuilder()
- .setGitDir(descriptor.directory.getChild(Constants.DOT_GIT).getPathFile())
- .setMustExist(true)
- .build();
+ repository = new FileRepositoryBuilder()
+ .setGitDir(descriptor.directory.getChild(Constants.DOT_GIT).getPathFile())
+ .setMustExist(true)
+ .build();
ObjectId head = repository.resolve(Constants.HEAD);
ObjectId checkout = repository.resolve(descriptor.checkout);
if (head != null && checkout != null && head.equals(checkout)) {
@@ -127,16 +126,14 @@ public class GitCloner {
throw new RepositoryFunctionException(e, Transience.TRANSIENT);
}
}
- git =
- Git.cloneRepository()
- .setURI(descriptor.remote)
- .setCredentialsProvider(new NetRCCredentialsProvider())
- .setDirectory(descriptor.directory.getPathFile())
- .setCloneSubmodules(false)
- .setNoCheckout(true)
- .setProgressMonitor(
- new GitProgressMonitor("Cloning " + descriptor.remote, eventHandler))
- .call();
+ git = Git.cloneRepository()
+ .setURI(descriptor.remote)
+ .setCredentialsProvider(new NetRCCredentialsProvider())
+ .setDirectory(descriptor.directory.getPathFile())
+ .setCloneSubmodules(false)
+ .setNoCheckout(true)
+ .setProgressMonitor(new GitProgressMonitor("Cloning " + descriptor.remote, eventHandler))
+ .call();
git.checkout()
.setCreateBranch(true)
.setName("bazel-checkout")
@@ -150,29 +147,27 @@ public class GitCloner {
// loop if submodules are cloned recursively. For now, limit submodules to only
// the first level.
if (descriptor.initSubmodules && !git.submoduleInit().call().isEmpty()) {
- git
- .submoduleUpdate()
+ git.submoduleUpdate()
.setProgressMonitor(
- new GitProgressMonitor("Cloning submodules for " + descriptor.remote, eventHandler))
+ new GitProgressMonitor(
+ "Cloning submodules for " + descriptor.remote, eventHandler))
.call();
}
} catch (InvalidRemoteException e) {
throw new RepositoryFunctionException(
- new IOException("Invalid Git repository URI: " + e.getMessage()),
- Transience.PERSISTENT);
+ new IOException("Invalid Git repository URI: " + e.getMessage()), Transience.PERSISTENT);
} catch (RefNotFoundException | InvalidRefNameException e) {
throw new RepositoryFunctionException(
new IOException("Invalid branch, tag, or commit: " + e.getMessage()),
Transience.PERSISTENT);
} catch (GitAPIException e) {
throw new RepositoryFunctionException(
- new IOException(e.getMessage()), Transience.TRANSIENT);
+ new IOException("Error cloning repository: " + e.getMessage()), Transience.PERSISTENT);
} catch (JGitInternalException e) {
// This is a lame catch-all for jgit throwing RuntimeExceptions all over the place because,
// as the docs put it, "a lot of exceptions are so low-level that is is unlikely that the
// caller of the command can handle them effectively." Thanks, jgit.
- throw new RepositoryFunctionException(
- new IOException(e.getMessage()), Transience.PERSISTENT);
+ throw new RepositoryFunctionException(new IOException(e.getMessage()), Transience.PERSISTENT);
} finally {
if (git != null) {
git.close();
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/GitRepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/GitRepositoryFunction.java
index 5b95fd186d..66ef6bcb14 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/repository/GitRepositoryFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/GitRepositoryFunction.java
@@ -41,9 +41,7 @@ public class GitRepositoryFunction extends RepositoryFunction {
public SkyValue fetch(Rule rule, Path outputDirectory, Environment env)
throws SkyFunctionException {
createDirectory(outputDirectory, rule);
-
GitCloner.clone(rule, outputDirectory, env.getListener());
-
return RepositoryValue.create(outputDirectory);
}