aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/repository/GitCloner.java23
1 files changed, 15 insertions, 8 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 2ee5ba8834..a1c98fb928 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
@@ -62,6 +62,8 @@ public class GitCloner {
private static final Pattern GITHUB_URL = Pattern.compile(
"(?:git@|https?://)github\\.com[:/](\\w+)/(\\w+)\\.git");
+ private static final Pattern GITHUB_VERSION_FORMAT = Pattern.compile("v(\\d+\\.)*\\d+");
+
private GitCloner() {
// Only static methods in this class
}
@@ -291,18 +293,23 @@ public class GitCloner {
String repositoryName = matcher.group(2);
String downloadUrl =
"https://github.com/"
- + UrlEscapers.urlPathSegmentEscaper().escape(
- user + "/" + repositoryName + "/archive/" + descriptor.ref + ".tar.gz");
+ + UrlEscapers.urlFragmentEscaper()
+ .escape(user + "/" + repositoryName + "/archive/" + descriptor.ref + ".tar.gz");
try {
FileSystemUtils.createDirectoryAndParents(descriptor.directory);
Path tgz = downloader.download(ImmutableList.of(new URL(downloadUrl)), uncheckedSha256,
Optional.of("tar.gz"), descriptor.directory, eventHandler, clientEnvironment);
- DecompressorValue.decompress(DecompressorDescriptor.builder()
- .setArchivePath(tgz)
- // GitHub puts the contents under a directory called <repo>-<commit>.
- .setPrefix(repositoryName + "-" + descriptor.ref)
- .setRepositoryPath(descriptor.directory)
- .build());
+ String githubRef = descriptor.ref;
+ if (githubRef.startsWith("v") && GITHUB_VERSION_FORMAT.matcher(githubRef).matches()) {
+ githubRef = githubRef.substring(1);
+ }
+ DecompressorValue.decompress(
+ DecompressorDescriptor.builder()
+ .setArchivePath(tgz)
+ // GitHub puts the contents under a directory called <repo>-<commit>.
+ .setPrefix(repositoryName + "-" + githubRef)
+ .setRepositoryPath(descriptor.directory)
+ .build());
} catch (InterruptedException | IOException e) {
try {
FileSystemUtils.deleteTree(descriptor.directory);