Search in sources :

Example 6 with VersionRef

use of org.gradle.vcs.internal.VersionRef 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

VersionRef (org.gradle.vcs.internal.VersionRef)6 URISyntaxException (java.net.URISyntaxException)3 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)3 Ref (org.eclipse.jgit.lib.Ref)3 GitVersionControlSpec (org.gradle.vcs.git.GitVersionControlSpec)3 File (java.io.File)1 Nullable (javax.annotation.Nullable)1 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)1 ModuleComponentSelector (org.gradle.api.artifacts.component.ModuleComponentSelector)1 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)1 LatestVersionSelector (org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.LatestVersionSelector)1 Version (org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.Version)1 VersionSelector (org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionSelector)1 IncludedBuildInternal (org.gradle.composite.internal.IncludedBuildInternal)1 IncludedBuildRegistry (org.gradle.composite.internal.IncludedBuildRegistry)1 NestedBuildFactory (org.gradle.initialization.NestedBuildFactory)1 Pair (org.gradle.internal.Pair)1 LocalComponentMetadata (org.gradle.internal.component.local.model.LocalComponentMetadata)1 ModuleVersionNotFoundException (org.gradle.internal.resolve.ModuleVersionNotFoundException)1 ModuleVersionResolveException (org.gradle.internal.resolve.ModuleVersionResolveException)1