use of org.gradle.vcs.git.GitVersionControlSpec in project gradle by gradle.
the class GitVersionControlSystem method populate.
@Override
public File populate(File versionDir, VersionRef ref, VersionControlSpec spec) {
GitVersionControlSpec gitSpec = cast(spec);
File workingDir = new File(versionDir, gitSpec.getRepoName());
File dbDir = new File(workingDir, ".git");
LOGGER.info("Populating VCS workingDir {}/{} with ref {}", versionDir.getName(), workingDir.getName(), ref);
if (dbDir.exists() && dbDir.isDirectory()) {
updateRepo(workingDir, gitSpec, ref);
} else {
cloneRepo(workingDir, gitSpec, ref);
}
return workingDir;
}
use of org.gradle.vcs.git.GitVersionControlSpec in project gradle by gradle.
the class GitVersionControlSystem method getDefaultBranch.
@Override
public VersionRef getDefaultBranch(VersionControlSpec spec) {
GitVersionControlSpec gitSpec = cast(spec);
Collection<Ref> refs;
try {
refs = Git.lsRemoteRepository().setRemote(normalizeUri(gitSpec.getUrl())).setTags(false).call();
} catch (URISyntaxException e) {
throw wrapGitCommandException("ls-remote", gitSpec.getUrl(), null, e);
} catch (GitAPIException e) {
throw wrapGitCommandException("ls-remote", gitSpec.getUrl(), null, e);
}
for (Ref ref : refs) {
if (ref.getName().equals("refs/heads/master")) {
return GitVersionRef.from(ref);
}
}
throw new UnsupportedOperationException("Git repository has no master branch");
}
use of org.gradle.vcs.git.GitVersionControlSpec in project gradle by gradle.
the class GitVersionControlSystem method getAvailableVersions.
@Override
public Set<VersionRef> getAvailableVersions(VersionControlSpec spec) {
GitVersionControlSpec gitSpec = cast(spec);
Collection<Ref> refs;
try {
refs = Git.lsRemoteRepository().setRemote(normalizeUri(gitSpec.getUrl())).setTags(true).setHeads(false).call();
} catch (URISyntaxException e) {
throw wrapGitCommandException("ls-remote", gitSpec.getUrl(), null, e);
} catch (GitAPIException e) {
throw wrapGitCommandException("ls-remote", gitSpec.getUrl(), null, e);
}
Set<VersionRef> versions = Sets.newHashSet();
for (Ref ref : refs) {
GitVersionRef gitRef = GitVersionRef.from(ref);
versions.add(gitRef);
}
return versions;
}
use of org.gradle.vcs.git.GitVersionControlSpec in project gradle by gradle.
the class GitVersionControlSystem method getBranch.
@Nullable
@Override
public VersionRef getBranch(VersionControlSpec spec, String branch) {
GitVersionControlSpec gitSpec = cast(spec);
Collection<Ref> refs;
try {
refs = Git.lsRemoteRepository().setRemote(normalizeUri(gitSpec.getUrl())).setHeads(true).setTags(false).call();
} catch (URISyntaxException e) {
throw wrapGitCommandException("ls-remote", gitSpec.getUrl(), null, e);
} catch (GitAPIException e) {
throw wrapGitCommandException("ls-remote", gitSpec.getUrl(), null, e);
}
String refName = "refs/heads/" + branch;
for (Ref ref : refs) {
if (ref.getName().equals(refName)) {
return GitVersionRef.from(ref);
}
}
return null;
}
Aggregations