Skip to content

Commit

Permalink
JENKINS-24728 Added UI Elements for shallow clone depth
Browse files Browse the repository at this point in the history
Use @DataBoundSetter instead of extending the constructor as was done
in the original pull request.  The DataBoundSetter annotation simplifies
the change.

Original concept by Nicholas Jasieniecki, with changes by Mark Waite.

Add help to shallow clone depth setting.

Add shallow and shallow depth to fetch command options.  The previous
implementation only set depth on the clone arguments, not on the fetch
arguments.  Without the depth on the fetch arguments, fetch retrieves
history additively, rather than retaining the depth at the originally
specified value.  That caused the history in a repository which is being
reused to grow each time new commits are detected and built by the job.
This change now keeps the history at the specified depth even with
incremental updates of the repository by new commits.
  • Loading branch information
Nicholas Jasieniecki authored and MarkEWaite committed Feb 18, 2016
1 parent 2553827 commit d96318d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
Expand Up @@ -13,6 +13,7 @@
import org.jenkinsci.plugins.gitclient.FetchCommand;
import org.jenkinsci.plugins.gitclient.GitClient;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;

import java.io.IOException;

Expand All @@ -24,6 +25,7 @@ public class CloneOption extends GitSCMExtension {
private final boolean noTags;
private final String reference;
private final Integer timeout;
private int depth = 1;

public CloneOption(boolean shallow, String reference, Integer timeout) {
this(shallow, false, reference, timeout);
Expand Down Expand Up @@ -53,11 +55,24 @@ public Integer getTimeout() {
return timeout;
}

@DataBoundSetter
public void setDepth(int depth) {
this.depth = depth;
}

public int getDepth() {
return depth;
}

@Override
public void decorateCloneCommand(GitSCM scm, Run<?, ?> build, GitClient git, TaskListener listener, CloneCommand cmd) throws IOException, InterruptedException, GitException {
if (shallow) {
listener.getLogger().println("Using shallow clone");
cmd.shallow();
if (depth > 1) {
listener.getLogger().println("shallow clone depth " + depth);
cmd.depth(depth);
}
}
if (noTags) {
listener.getLogger().println("Avoid fetching tags");
Expand All @@ -66,9 +81,13 @@ public void decorateCloneCommand(GitSCM scm, Run<?, ?> build, GitClient git, Tas
cmd.timeout(timeout);
cmd.reference(build.getEnvironment(listener).expand(reference));
}

@Override
public void decorateFetchCommand(GitSCM scm, GitClient git, TaskListener listener, FetchCommand cmd) throws IOException, InterruptedException, GitException {
cmd.shallow(shallow);
if (shallow && depth > 1) {
cmd.depth(depth);
}
cmd.tags(!noTags);
cmd.timeout(timeout);
}
Expand Down
Expand Up @@ -5,6 +5,9 @@ def f = namespace(lib.FormTagLib);
f.entry(title:_("Shallow clone"), field:"shallow") {
f.checkbox()
}
f.entry(title:_("Shallow clone depth"), field:"depth") {
f.textbox()
}
f.entry(title:_("Do not fetch tags"), field:"noTags") {
f.checkbox()
}
Expand Down
@@ -0,0 +1,4 @@
<div>
Set shallow clone depth, so that git will only download recent history of the project,
saving time and disk space when you just want to access the latest version of a repository.
</div>

0 comments on commit d96318d

Please sign in to comment.