/** * Converts the ref spec templates into {@link RefSpec} instances. * * @return the list of {@link RefSpec} instances. */ @NonNull public final List<RefSpec> asRefSpecs() { List<RefSpec> result = new ArrayList<>(Math.max(refSpecs.size(), 1)); for (String template : refSpecs()) { result.add(new RefSpec( template.replaceAll(AbstractGitSCMSource.REF_SPEC_REMOTE_NAME_PLACEHOLDER, remoteName()) )); } return result; }
@Override public Set<String> run(GitClient client, String remoteName) throws IOException, InterruptedException { Set<String> revisions = new HashSet<String>(); if (context.wantBranches()) { for (Branch branch : client.getRemoteBranches()) { revisions.add(branch.getName().replaceFirst( "^" + Pattern.quote(context.remoteName()) + "/", "" )); } } if (context.wantTags()) { revisions.addAll(client.getTagNames("*")); } return revisions; } },
/** * Constructor. * * @param source the source. * @param context the context. * @param listener the (optional) {@link TaskListener}. */ public GitSCMSourceRequest(@NonNull SCMSource source, @NonNull GitSCMSourceContext<?, ?> context, TaskListener listener) { super(source, context, listener); fetchBranches = context.wantBranches(); fetchTags = context.wantTags(); remoteName = context.remoteName(); gitTool = context.gitTool(); refSpecs = Collections.unmodifiableList(context.asRefSpecs()); }
@Override public SCMRevision run(GitClient client, String remoteName) throws IOException, InterruptedException { String hash; try { hash = client.revParse(revision).name(); } catch (GitException x) { // Try prepending remote name in case it was a branch. try { hash = client.revParse(context.remoteName() + "/" + revision).name(); } catch (GitException x2) { listener.getLogger().println(x.getMessage()); listener.getLogger().println(x2.getMessage()); return null; } } return new SCMRevisionImpl(new SCMHead(revision), hash); } },
client.init(); String remoteName = context.remoteName(); listener.getLogger().println("Setting " + remoteName + " to " + getRemote()); client.setRemoteUrl(remoteName, getRemote());