Skip to content

Commit 0da0667

Browse files
authored
support decorateContext in CloneOptionTrait
1 parent fea27bd commit 0da0667

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ public CloneOptionTrait(CloneOption extension) {
4747
super(extension);
4848
}
4949

50+
@Override
51+
protected void decorateContext(SCMSourceContext<?, ?> context) {
52+
CloneOption extension = getExtension();
53+
((GitSCMSourceContext<?, ?>) context).shallow(extension.isShallow()).depth(extension.getDepth());
54+
}
55+
5056
/**
5157
* Our {@link hudson.model.Descriptor}
5258
*/

0 commit comments

Comments
 (0)