Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge pull request #333 from rhaendel/master
[JENKINS-14572] Add "Do not fetch tags" advanced clone option
- Loading branch information
Showing
6 changed files
with
167 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
src/main/resources/hudson/plugins/git/extensions/impl/CloneOption/help-noTags.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<div> | ||
Perform a clone without tags, saving time and disk space when you just want to access | ||
what is specified by the refspec. | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/test/java/hudson/plugins/git/extensions/impl/CloneOptionNoTagsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package hudson.plugins.git.extensions.impl; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.io.IOException; | ||
import java.util.Set; | ||
|
||
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 org.jenkinsci.plugins.gitclient.Git; | ||
import org.jenkinsci.plugins.gitclient.GitClient; | ||
import org.junit.Test; | ||
|
||
/** | ||
* @author Ronny Händel | ||
*/ | ||
public class CloneOptionNoTagsTest 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 boolean dontFetchTags = true; | ||
final String noReference = null; | ||
final Integer noTimeout = null; | ||
return new CloneOption(shallowClone, dontFetchTags, noReference, noTimeout); | ||
} | ||
|
||
@Test | ||
public void cloningShouldNotFetchTags() throws Exception { | ||
|
||
repo.commit("repo-init", repo.johnDoe, "repo0 initial commit"); | ||
repo.tag("v0.0.1", "a tag that should never be fetched"); | ||
|
||
assertTrue("scm polling should detect a change after initial commit", project.poll(listener).hasChanges()); | ||
|
||
build(project, Result.SUCCESS); | ||
|
||
assertTrue("there should no tags have been cloned from remote", allTagsInProjectWorkspace().isEmpty()); | ||
} | ||
|
||
@Test | ||
public void detectNoChangeAfterCreatingATag() throws Exception { | ||
|
||
repo.commit("repo-init", repo.johnDoe, "repo0 initial commit"); | ||
|
||
assertTrue("scm polling should detect a change after initial commit", project.poll(listener).hasChanges()); | ||
|
||
build(project, Result.SUCCESS); | ||
|
||
repo.tag("v0.0.1", "a tag that should never be fetched"); | ||
|
||
assertFalse("scm polling should not detect a change after creating a tag", project.poll(listener).hasChanges()); | ||
|
||
build(project, Result.SUCCESS); | ||
|
||
assertTrue("there should no tags have been fetched from remote", allTagsInProjectWorkspace().isEmpty()); | ||
} | ||
|
||
private Set<String> allTagsInProjectWorkspace() throws IOException, InterruptedException { | ||
GitClient git = Git.with(listener, null).in(project.getWorkspace()).getClient(); | ||
return git.getTagNames("*"); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/test/java/hudson/plugins/git/extensions/impl/CloneOptionShallowDefaultTagsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |