Skip to content
Permalink
Browse files

[JENKINS-43507] Future-proof for if we implement TagSCMHead discovery

  • Loading branch information...
stephenc committed Jun 13, 2017
1 parent a2afab2 commit 1f0d0e15e0dd91db6819d4b38fb371c1908f2392
@@ -50,6 +50,7 @@
import java.util.TreeMap;
import jenkins.scm.api.SCMHead;
import jenkins.scm.api.SCMRevision;
import jenkins.scm.api.mixin.TagSCMHead;
import jenkins.scm.api.trait.SCMBuilder;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jgit.transport.RefSpec;
@@ -499,7 +500,8 @@ public GitSCM build() {
}
if (!foundClone) {
// assume honour refspecs unless the clone option is added
extensions.add(new GitSCMSourceDefaults());
// TODO revisit once we have support for TagSCMHead implemented as may need to check refspec handling then
extensions.add(new GitSCMSourceDefaults(head() instanceof TagSCMHead));
}
SCMRevision revision = revision();
if (revision instanceof AbstractGitSCMSource.SCMRevisionImpl) {
@@ -32,6 +32,7 @@
import hudson.plugins.git.extensions.GitSCMExtension;
import java.io.IOException;
import java.util.List;
import jenkins.scm.api.mixin.TagSCMHead;
import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.transport.RemoteConfig;
import org.jenkinsci.plugins.gitclient.CloneCommand;
@@ -43,18 +44,26 @@
* Does not have a descriptor as we do not expect this extension to be user-visible.
* With this extension, we anticipate:
* <ul>
* <li>tags will not be cloned or fetched</li>
* <li>refspecs will be honoured on clone</li>
* <li>tags will not be cloned or fetched</li>
* <li>refspecs will be honoured on clone</li>
* </ul>
*
* @since 3.4.0
*/
public class GitSCMSourceDefaults extends GitSCMExtension {

/**
* Determines whether tags should be fetched... only relevant if we implement support for {@link TagSCMHead}.
*/
private final boolean includeTags;

/**
* Constructor.
*
* @param includeTags
*/
public GitSCMSourceDefaults() {
public GitSCMSourceDefaults(boolean includeTags) {
this.includeTags = includeTags;
}

/**
@@ -65,23 +74,31 @@ public boolean equals(Object o) {
if (this == o) {
return true;
}
return o != null && getClass() == o.getClass();
if (o == null || getClass() != o.getClass()) {
return false;
}

GitSCMSourceDefaults that = (GitSCMSourceDefaults) o;

return includeTags == that.includeTags;
}

/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return getClass().hashCode();
return (includeTags ? 1 : 0);
}

/**
* {@inheritDoc}
*/
@Override
public String toString() {
return "GitSCMSourceDefaults{}";
return "GitSCMSourceDefaults{" +
"includeTags=" + includeTags +
'}';
}

/**
@@ -90,17 +107,22 @@ public String toString() {
@Override
public void decorateCloneCommand(GitSCM scm, Run<?, ?> build, GitClient git, TaskListener listener,
CloneCommand cmd) throws IOException, InterruptedException, GitException {
listener.getLogger().println("Cloning with configured refspecs honoured and without tags");
listener.getLogger()
.printf("Cloning with configured refspecs honoured and %s tags%n", includeTags ? "with" : "without");
RemoteConfig rc = scm.getRepositories().get(0);
List<RefSpec> refspecs = rc.getFetchRefSpecs();
cmd.refspecs(refspecs);
cmd.tags(false);
cmd.tags(includeTags);
}

/**
* {@inheritDoc}
*/
@Override
public void decorateFetchCommand(GitSCM scm, GitClient git, TaskListener listener, FetchCommand cmd)
throws IOException, InterruptedException, GitException {
listener.getLogger().println("Fetching without tags");
cmd.tags(false);
listener.getLogger()
.printf("Fetching %s tags%n", includeTags ? "with" : "without");
cmd.tags(includeTags);
}
}

0 comments on commit 1f0d0e1

Please sign in to comment.
You can’t perform that action at this time.