Skip to content

Commit

Permalink
Add Git CloneOption for honorRefspec
Browse files Browse the repository at this point in the history
This helps fix issues with shallow clones on Gerrit repositories.
  • Loading branch information
docwhat committed Oct 7, 2016
1 parent 2676d6e commit f41a9c3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand All @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class GitExtensionContext extends AbstractExtensibleContext {
if (context.timeout != null) {
timeout(context.timeout)
}
honorRefspec(context.honorRefspec)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
Expand All @@ -285,6 +286,7 @@ class ScmContextSpec extends Specification {
shallow()
reference('/foo')
timeout(40)
honorRefspec()
}
}
}
Expand All @@ -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')
}
Expand Down

0 comments on commit f41a9c3

Please sign in to comment.