Skip to content

Commit 698ae68

Browse files
committed
CloneOption.honorRefspec can also be useful
1 parent 10623dd commit 698ae68

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/main/resources/org/jenkinsci/plugins/workflow/libs/SCMBasedRetriever/help-clone.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
If checked, every build performs a fresh clone of the SCM rather than locking and updating a common copy.
33
No changelog will be computed.
44
For Git, you are advised to add <b>Advanced clone behaviors</b>
5-
and then check <b>Shallow clone</b> and uncheck <b>Fetch tags</b>
5+
and then check <b>Shallow clone</b> and <b>Honor refspec on initial clone</b> and uncheck <b>Fetch tags</b>
66
to make the clone much faster.
77
You may still enable <b>Cache fetched versions on controller for quick retrieval</b> if you prefer.
88
</div>

src/test/java/org/jenkinsci/plugins/workflow/libs/SCMSourceRetrieverTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import static hudson.ExtensionList.lookupSingleton;
6363
import hudson.plugins.git.extensions.impl.CloneOption;
6464
import jenkins.plugins.git.traits.CloneOptionTrait;
65+
import jenkins.plugins.git.traits.RefSpecsSCMSourceTrait;
6566
import jenkins.scm.api.trait.SCMSourceTrait;
6667
import static org.hamcrest.Matchers.contains;
6768
import static org.hamcrest.Matchers.containsInAnyOrder;
@@ -379,7 +380,9 @@ public static class BasicSCMSource extends SCMSource {
379380
sampleRepo.git("add", ".");
380381
sampleRepo.git("commit", "--message=init");
381382
GitSCMSource src = new GitSCMSource(sampleRepo.toString());
382-
src.setTraits(List.<SCMSourceTrait>of(new CloneOptionTrait(new CloneOption(true, true, null, null))));
383+
CloneOption cloneOption = new CloneOption(true, true, null, null);
384+
cloneOption.setHonorRefspec(true);
385+
src.setTraits(List.<SCMSourceTrait>of(new CloneOptionTrait(cloneOption), new RefSpecsSCMSourceTrait("+refs/heads/master:refs/remotes/origin/master")));
383386
SCMSourceRetriever scm = new SCMSourceRetriever(src);
384387
LibraryConfiguration lc = new LibraryConfiguration("echoing", scm);
385388
lc.setIncludeInChangesets(false);
@@ -392,6 +395,7 @@ public static class BasicSCMSource extends SCMSource {
392395
r.assertLogContains("something special", b);
393396
r.assertLogContains("Using shallow clone with depth 1", b);
394397
r.assertLogContains("Avoid fetching tags", b);
398+
r.assertLogNotContains("+refs/heads/*:refs/remotes/origin/*", b);
395399
// Fails to reproduce presence of *.jar.tmp@tmp; probably specific to use of GIT_ASKPASS:
396400
assertThat(new File(b.getRootDir(), "libs").list(), arrayContaining(matchesPattern("[0-9a-f]{64}[.]jar")));
397401
}

0 commit comments

Comments
 (0)