-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-14572] Add "Do not fetch tags" advanced clone option
- Loading branch information
Showing
5 changed files
with
109 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("*"); | ||
} | ||
} |