Browse Source

Add depth option to git shallow-clone

- Use convert xml for shallow-clone and depth

Change-Id: I92d4bd2ded6db66bb608aed480e873e29e7b9474
tags/2.0.10
Imran Malik 2 years ago
parent
commit
4167cc5dbd

+ 5
- 2
jenkins_jobs/modules/scm.py View File

@@ -169,6 +169,7 @@ def git(registry, xml_parent, data):
169 169
         * **scm-name** (`string`) - The unique scm name for this Git SCM
170 170
             (optional)
171 171
         * **shallow-clone** (`bool`) - Perform shallow clone (default false)
172
+        * **depth** (`int`) - Set shallow clone depth (default 1)
172 173
         * **do-not-fetch-tags** (`bool`) - Perform a clone without tags
173 174
             (default false)
174 175
         * **sparse-checkout** (`dict`)
@@ -381,8 +382,10 @@ def git(registry, xml_parent, data):
381 382
     )
382 383
     if any(key in data for key in clone_options):
383 384
         clo = XML.SubElement(exts_node, impl_prefix + 'CloneOption')
384
-        XML.SubElement(clo, 'shallow').text = str(
385
-            data.get('shallow-clone', False)).lower()
385
+        clone_mapping = [
386
+            ('shallow-clone', 'shallow', False),
387
+            ('depth', 'depth', 1)]
388
+        convert_mapping_to_xml(clo, data, clone_mapping, fail_required=True)
386 389
         if 'do-not-fetch-tags' in data:
387 390
             XML.SubElement(clo, 'noTags').text = str(
388 391
                 data.get('do-not-fetch-tags', False)).lower()

+ 1
- 0
tests/macros/fixtures/scm/obj-in-scm-macro001.xml View File

@@ -37,6 +37,7 @@
37 37
       <hudson.plugins.git.extensions.impl.CleanBeforeCheckout/>
38 38
       <hudson.plugins.git.extensions.impl.CloneOption>
39 39
         <shallow>true</shallow>
40
+        <depth>1</depth>
40 41
       </hudson.plugins.git.extensions.impl.CloneOption>
41 42
       <hudson.plugins.git.extensions.impl.SubmoduleOption>
42 43
         <disableSubmodules>false</disableSubmodules>

+ 1
- 0
tests/scm/fixtures/git-cloneoptions01.xml View File

@@ -26,6 +26,7 @@
26 26
     <extensions>
27 27
       <hudson.plugins.git.extensions.impl.CloneOption>
28 28
         <shallow>false</shallow>
29
+        <depth>1</depth>
29 30
         <noTags>true</noTags>
30 31
       </hudson.plugins.git.extensions.impl.CloneOption>
31 32
       <hudson.plugins.git.extensions.impl.WipeWorkspace/>

+ 1
- 0
tests/scm/fixtures/git-shallow-clone01.xml View File

@@ -28,6 +28,7 @@
28 28
       <hudson.plugins.git.extensions.impl.CleanCheckout/>
29 29
       <hudson.plugins.git.extensions.impl.CloneOption>
30 30
         <shallow>true</shallow>
31
+        <depth>1</depth>
31 32
       </hudson.plugins.git.extensions.impl.CloneOption>
32 33
       <hudson.plugins.git.extensions.impl.WipeWorkspace/>
33 34
     </extensions>

+ 1
- 0
tests/scm/fixtures/git-shallow-clone02.xml View File

@@ -27,6 +27,7 @@
27 27
       <hudson.plugins.git.extensions.impl.CleanCheckout/>
28 28
       <hudson.plugins.git.extensions.impl.CloneOption>
29 29
         <shallow>false</shallow>
30
+        <depth>1</depth>
30 31
       </hudson.plugins.git.extensions.impl.CloneOption>
31 32
       <hudson.plugins.git.extensions.impl.WipeWorkspace/>
32 33
     </extensions>

+ 1
- 0
tests/scm/fixtures/git001.xml View File

@@ -29,6 +29,7 @@
29 29
     <extensions>
30 30
       <hudson.plugins.git.extensions.impl.CloneOption>
31 31
         <shallow>false</shallow>
32
+        <depth>1</depth>
32 33
         <timeout>20</timeout>
33 34
       </hudson.plugins.git.extensions.impl.CloneOption>
34 35
       <hudson.plugins.git.extensions.impl.CheckoutOption>

+ 2
- 1
tests/scm/fixtures/git002.xml View File

@@ -34,7 +34,8 @@
34 34
         </options>
35 35
       </hudson.plugins.git.extensions.impl.ChangelogToBranch>
36 36
       <hudson.plugins.git.extensions.impl.CloneOption>
37
-        <shallow>false</shallow>
37
+        <shallow>true</shallow>
38
+        <depth>3</depth>
38 39
         <noTags>false</noTags>
39 40
         <timeout>20</timeout>
40 41
       </hudson.plugins.git.extensions.impl.CloneOption>

+ 2
- 0
tests/scm/fixtures/git002.yaml View File

@@ -6,6 +6,8 @@ scm:
6 6
         - stable
7 7
       browser: githubweb
8 8
       browser-url: http://github.com/foo/example.git
9
+      shallow-clone: true
10
+      depth: 3
9 11
       timeout: 20
10 12
       do-not-fetch-tags: false
11 13
       changelog-against:

Loading…
Cancel
Save