Skip to content

Commit 98f43e3

Browse files
committed
support decorateContext in CloneOptionTrait
1 parent fea27bd commit 98f43e3

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

src/main/java/jenkins/plugins/git/AbstractGitSCMSource.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ private <T, C extends GitSCMSourceContext<C, R>, R extends GitSCMSourceRequest>
404404
fetch.tags(context.wantTags());
405405
}
406406
fetch = fetch.prune(prune);
407+
fetch = fetch.shallow(context.wantShallow()).depth(context.depth());
407408

408409
URIish remoteURI = null;
409410
try {

src/main/java/jenkins/plugins/git/GitSCMSourceContext.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ public class GitSCMSourceContext<C extends GitSCMSourceContext<C, R>, R extends
9494
*/
9595
@NonNull
9696
private String remoteName = AbstractGitSCMSource.DEFAULT_REMOTE_NAME;
97+
/**
98+
* Perform shallow clone
99+
*/
100+
private boolean shallow;
101+
/**
102+
* Shallow clone depth
103+
*/
104+
private Integer depth;
97105

98106
/**
99107
* Constructor.
@@ -192,6 +200,24 @@ public final String remoteName() {
192200
return remoteName;
193201
}
194202

203+
/**
204+
* Returns {@code true} if perform shallow clone
205+
*
206+
* @return {@code true} if perform shallow clone
207+
*/
208+
public final boolean wantShallow() {
209+
return shallow;
210+
}
211+
212+
/**
213+
* Returns shallow clone depth
214+
*
215+
* @return shallow clone depth
216+
*/
217+
public final Integer depth() {
218+
return depth;
219+
}
220+
195221
/**
196222
* Adds a requirement for branch details to any {@link GitSCMSourceRequest} for this context.
197223
*
@@ -358,6 +384,32 @@ public final List<RefSpec> asRefSpecs() {
358384
return result;
359385
}
360386

387+
/**
388+
* Configures perform shallow clone
389+
*
390+
* @param shallow {@code true} to perform shallow clone
391+
* @return {@code this} for method chaining.
392+
*/
393+
@SuppressWarnings("unchecked")
394+
@NonNull
395+
public final C shallow(boolean shallow) {
396+
this.shallow = shallow;
397+
return (C) this;
398+
}
399+
400+
/**
401+
* Configures shallow clone depth
402+
*
403+
* @param depth count atest commits of a repository
404+
* @return {@code this} for method chaining.
405+
*/
406+
@SuppressWarnings("unchecked")
407+
@NonNull
408+
public final C depth(Integer depth) {
409+
this.depth = depth;
410+
return (C) this;
411+
}
412+
361413
/**
362414
* {@inheritDoc}
363415
*/

src/main/java/jenkins/plugins/git/traits/CloneOptionTrait.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
import hudson.Extension;
2929
import hudson.plugins.git.extensions.impl.CloneOption;
30+
import jenkins.plugins.git.GitSCMSourceContext;
31+
import jenkins.scm.api.trait.SCMSourceContext;
3032
import jenkins.scm.api.trait.SCMSourceTrait;
3133
import org.jenkinsci.Symbol;
3234
import org.kohsuke.stapler.DataBoundConstructor;
@@ -47,6 +49,12 @@ public CloneOptionTrait(CloneOption extension) {
4749
super(extension);
4850
}
4951

52+
@Override
53+
protected void decorateContext(SCMSourceContext<?, ?> context) {
54+
CloneOption extension = getExtension();
55+
((GitSCMSourceContext<?, ?>) context).shallow(extension.isShallow()).depth(extension.getDepth());
56+
}
57+
5058
/**
5159
* Our {@link hudson.model.Descriptor}
5260
*/

0 commit comments

Comments
 (0)