Search in sources :

Example 1 with GitVersionControlSpec

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;
}
Also used : GitVersionControlSpec(org.gradle.vcs.git.GitVersionControlSpec) File(java.io.File)

Example 2 with GitVersionControlSpec

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");
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) VersionRef(org.gradle.vcs.internal.VersionRef) Ref(org.eclipse.jgit.lib.Ref) GitVersionControlSpec(org.gradle.vcs.git.GitVersionControlSpec) URISyntaxException(java.net.URISyntaxException)

Example 3 with GitVersionControlSpec

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;
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) VersionRef(org.gradle.vcs.internal.VersionRef) VersionRef(org.gradle.vcs.internal.VersionRef) Ref(org.eclipse.jgit.lib.Ref) GitVersionControlSpec(org.gradle.vcs.git.GitVersionControlSpec) URISyntaxException(java.net.URISyntaxException)

Example 4 with GitVersionControlSpec

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;
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) VersionRef(org.gradle.vcs.internal.VersionRef) Ref(org.eclipse.jgit.lib.Ref) GitVersionControlSpec(org.gradle.vcs.git.GitVersionControlSpec) URISyntaxException(java.net.URISyntaxException) Nullable(javax.annotation.Nullable)

Aggregations

GitVersionControlSpec (org.gradle.vcs.git.GitVersionControlSpec)4 URISyntaxException (java.net.URISyntaxException)3 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)3 Ref (org.eclipse.jgit.lib.Ref)3 VersionRef (org.gradle.vcs.internal.VersionRef)3 File (java.io.File)1 Nullable (javax.annotation.Nullable)1