From 4167cc5dbd1ee46b09077ccc46f5b91060dc98a7 Mon Sep 17 00:00:00 2001 From: Imran Malik Date: Wed, 25 Jan 2017 00:07:26 -0800 Subject: [PATCH] Add depth option to git shallow-clone - Use convert xml for shallow-clone and depth Change-Id: I92d4bd2ded6db66bb608aed480e873e29e7b9474 --- jenkins_jobs/modules/scm.py | 7 +++++-- tests/macros/fixtures/scm/obj-in-scm-macro001.xml | 1 + tests/scm/fixtures/git-cloneoptions01.xml | 1 + tests/scm/fixtures/git-shallow-clone01.xml | 1 + tests/scm/fixtures/git-shallow-clone02.xml | 1 + tests/scm/fixtures/git001.xml | 1 + tests/scm/fixtures/git002.xml | 3 ++- tests/scm/fixtures/git002.yaml | 2 ++ 8 files changed, 14 insertions(+), 3 deletions(-) diff --git a/jenkins_jobs/modules/scm.py b/jenkins_jobs/modules/scm.py index 23ba7b67e..c009957e7 100644 --- a/jenkins_jobs/modules/scm.py +++ b/jenkins_jobs/modules/scm.py @@ -169,6 +169,7 @@ def git(registry, xml_parent, data): * **scm-name** (`string`) - The unique scm name for this Git SCM (optional) * **shallow-clone** (`bool`) - Perform shallow clone (default false) + * **depth** (`int`) - Set shallow clone depth (default 1) * **do-not-fetch-tags** (`bool`) - Perform a clone without tags (default false) * **sparse-checkout** (`dict`) @@ -381,8 +382,10 @@ def git(registry, xml_parent, data): ) if any(key in data for key in clone_options): clo = XML.SubElement(exts_node, impl_prefix + 'CloneOption') - XML.SubElement(clo, 'shallow').text = str( - data.get('shallow-clone', False)).lower() + clone_mapping = [ + ('shallow-clone', 'shallow', False), + ('depth', 'depth', 1)] + convert_mapping_to_xml(clo, data, clone_mapping, fail_required=True) if 'do-not-fetch-tags' in data: XML.SubElement(clo, 'noTags').text = str( data.get('do-not-fetch-tags', False)).lower() diff --git a/tests/macros/fixtures/scm/obj-in-scm-macro001.xml b/tests/macros/fixtures/scm/obj-in-scm-macro001.xml index e382ff61e..9918f252c 100644 --- a/tests/macros/fixtures/scm/obj-in-scm-macro001.xml +++ b/tests/macros/fixtures/scm/obj-in-scm-macro001.xml @@ -37,6 +37,7 @@ true + 1 false diff --git a/tests/scm/fixtures/git-cloneoptions01.xml b/tests/scm/fixtures/git-cloneoptions01.xml index 0de9fccc9..722f773a7 100644 --- a/tests/scm/fixtures/git-cloneoptions01.xml +++ b/tests/scm/fixtures/git-cloneoptions01.xml @@ -26,6 +26,7 @@ false + 1 true diff --git a/tests/scm/fixtures/git-shallow-clone01.xml b/tests/scm/fixtures/git-shallow-clone01.xml index f2ffe1c75..a5532f902 100644 --- a/tests/scm/fixtures/git-shallow-clone01.xml +++ b/tests/scm/fixtures/git-shallow-clone01.xml @@ -28,6 +28,7 @@ true + 1 diff --git a/tests/scm/fixtures/git-shallow-clone02.xml b/tests/scm/fixtures/git-shallow-clone02.xml index 416929e42..641863d87 100644 --- a/tests/scm/fixtures/git-shallow-clone02.xml +++ b/tests/scm/fixtures/git-shallow-clone02.xml @@ -27,6 +27,7 @@ false + 1 diff --git a/tests/scm/fixtures/git001.xml b/tests/scm/fixtures/git001.xml index c0f3746fc..e0ef687f2 100644 --- a/tests/scm/fixtures/git001.xml +++ b/tests/scm/fixtures/git001.xml @@ -29,6 +29,7 @@ false + 1 20 diff --git a/tests/scm/fixtures/git002.xml b/tests/scm/fixtures/git002.xml index 3f4875510..a036c0567 100644 --- a/tests/scm/fixtures/git002.xml +++ b/tests/scm/fixtures/git002.xml @@ -34,7 +34,8 @@ - false + true + 3 false 20 diff --git a/tests/scm/fixtures/git002.yaml b/tests/scm/fixtures/git002.yaml index c1d37a02a..e77d42494 100644 --- a/tests/scm/fixtures/git002.yaml +++ b/tests/scm/fixtures/git002.yaml @@ -6,6 +6,8 @@ scm: - stable browser: githubweb browser-url: http://github.com/foo/example.git + shallow-clone: true + depth: 3 timeout: 20 do-not-fetch-tags: false changelog-against: