From f41a9c3bf2671724191de2ec6a490224a5318da2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ho=CC=88ltje?= Date: Fri, 7 Oct 2016 14:11:15 -0400 Subject: [PATCH] Add Git CloneOption for honorRefspec This helps fix issues with shallow clones on Gerrit repositories. --- .../jobdsl/dsl/helpers/scm/GitCloneOptionsContext.groovy | 8 ++++++++ .../jobdsl/dsl/helpers/scm/GitExtensionContext.groovy | 1 + .../javaposse/jobdsl/dsl/helpers/ScmContextSpec.groovy | 7 +++++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/scm/GitCloneOptionsContext.groovy b/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/scm/GitCloneOptionsContext.groovy index 1f7ec1747..3804e1ed5 100644 --- a/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/scm/GitCloneOptionsContext.groovy +++ b/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/scm/GitCloneOptionsContext.groovy @@ -6,6 +6,7 @@ class GitCloneOptionsContext implements Context { boolean shallow String reference Integer timeout + boolean honorRefspec /** * Perform shallow clone, so that Git will not download history of the project. Defaults to {@code false}. @@ -27,4 +28,11 @@ class GitCloneOptionsContext implements Context { void timeout(Integer timeout) { this.timeout = timeout } + + /** + * Honor refspec on initial clone. + */ + void honorRefspec(boolean honorRefspec = true) { + this.honorRefspec = honorRefspec + } } diff --git a/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/scm/GitExtensionContext.groovy b/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/scm/GitExtensionContext.groovy index f0894073d..8c44d9c6c 100644 --- a/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/scm/GitExtensionContext.groovy +++ b/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/scm/GitExtensionContext.groovy @@ -70,6 +70,7 @@ class GitExtensionContext extends AbstractExtensibleContext { if (context.timeout != null) { timeout(context.timeout) } + honorRefspec(context.honorRefspec) } } diff --git a/job-dsl-core/src/test/groovy/javaposse/jobdsl/dsl/helpers/ScmContextSpec.groovy b/job-dsl-core/src/test/groovy/javaposse/jobdsl/dsl/helpers/ScmContextSpec.groovy index 084cf3204..528a3875f 100644 --- a/job-dsl-core/src/test/groovy/javaposse/jobdsl/dsl/helpers/ScmContextSpec.groovy +++ b/job-dsl-core/src/test/groovy/javaposse/jobdsl/dsl/helpers/ScmContextSpec.groovy @@ -267,9 +267,10 @@ class ScmContextSpec extends Specification { with(context.scmNodes[0]) { extensions.size() == 1 extensions[0].children().size() == 1 - extensions[0].'hudson.plugins.git.extensions.impl.CloneOption'[0].children().size() == 2 + extensions[0].'hudson.plugins.git.extensions.impl.CloneOption'[0].children().size() == 3 extensions[0].'hudson.plugins.git.extensions.impl.CloneOption'[0].reference[0].value() == '' extensions[0].'hudson.plugins.git.extensions.impl.CloneOption'[0].shallow[0].value() == false + extensions[0].'hudson.plugins.git.extensions.impl.CloneOption'[0].honorRefspec[0].value() == false } 1 * mockJobManagement.requireMinimumPluginVersion('git', '2.2.6') } @@ -285,6 +286,7 @@ class ScmContextSpec extends Specification { shallow() reference('/foo') timeout(40) + honorRefspec() } } } @@ -294,10 +296,11 @@ class ScmContextSpec extends Specification { with(context.scmNodes[0]) { extensions.size() == 1 extensions[0].children().size() == 1 - extensions[0].'hudson.plugins.git.extensions.impl.CloneOption'[0].children().size() == 3 + extensions[0].'hudson.plugins.git.extensions.impl.CloneOption'[0].children().size() == 4 extensions[0].'hudson.plugins.git.extensions.impl.CloneOption'[0].reference[0].value() == '/foo' extensions[0].'hudson.plugins.git.extensions.impl.CloneOption'[0].shallow[0].value() == true extensions[0].'hudson.plugins.git.extensions.impl.CloneOption'[0].timeout[0].value() == 40 + extensions[0].'hudson.plugins.git.extensions.impl.CloneOption'[0].honorRefspec[0].value() == true } 1 * mockJobManagement.requireMinimumPluginVersion('git', '2.2.6') }