Skip to content

Commit

Permalink
[JENKINS-14572] Add a test case for clone option's default 'fetch tag…
Browse files Browse the repository at this point in the history
…s' behaviour

Even with shallow clones "fetch all tags" is the default. Just added a
missing test case and found a true/false bug in my previous commit which
toggled the default to the not backwards compatible value.
  • Loading branch information
rhaendel committed Jun 27, 2015
1 parent bfeda3e commit 24fb7f3
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
Expand Up @@ -26,7 +26,7 @@ public class CloneOption extends GitSCMExtension {
private final Integer timeout;

public CloneOption(boolean shallow, String reference, Integer timeout) {
this(shallow, true, reference, timeout);
this(shallow, false, reference, timeout);
}

@DataBoundConstructor
Expand Down
@@ -0,0 +1,58 @@
package hudson.plugins.git.extensions.impl;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import hudson.model.Result;
import hudson.model.FreeStyleProject;
import hudson.plugins.git.TestGitRepo;
import hudson.plugins.git.extensions.GitSCMExtensionTest;
import hudson.plugins.git.extensions.GitSCMExtension;

import java.io.IOException;
import java.util.Set;

import org.jenkinsci.plugins.gitclient.Git;
import org.jenkinsci.plugins.gitclient.GitClient;
import org.junit.Test;

/**
* @author Ronny Händel
*/
public class CloneOptionShallowDefaultTagsTest extends GitSCMExtensionTest {

FreeStyleProject project;
TestGitRepo repo;

@Override
public void before() throws Exception {
repo = new TestGitRepo("repo", tmp.newFolder(), listener);
project = setupBasicProject(repo);
}

@Override
protected GitSCMExtension getExtension() {
final boolean shallowClone = true;
final String noReference = null;
final Integer noTimeout = null;
return new CloneOption(shallowClone, noReference, noTimeout);
}

@Test
public void evenShallowCloningFetchesTagsByDefault() throws Exception {
final String tagName = "v0.0.1";

repo.commit("repo-init", repo.johnDoe, "repo0 initial commit");
repo.tag(tagName, "a tag that should be fetched by default");

assertTrue("scm polling should detect a change after initial commit", project.poll(listener).hasChanges());

build(project, Result.SUCCESS);

assertEquals("tag " + tagName + " should have been cloned from remote", 1, tagsInProjectWorkspaceWithName(tagName).size());
}

private Set<String> tagsInProjectWorkspaceWithName(String tagPattern) throws IOException, InterruptedException {
GitClient git = Git.with(listener, null).in(project.getWorkspace()).getClient();
return git.getTagNames(tagPattern);
}
}

0 comments on commit 24fb7f3

Please sign in to comment.