From da6948ab89429a1fe0dea6095a5d0050e59fbf00 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Tue, 20 Aug 2024 15:05:07 -0600 Subject: [PATCH] Add sparseCheckout symbol for Pipeline (#1638) Includes a test that confirms the sparseCheckout syntax works as expected. Tested interactively to confirm that the new symbol behaves the same as the old syntax behaved. Does not include detailed functional testing that the sparseCheckout symbol works as expected, since there are already tests of sparse checkout in other tests. --- README.adoc | 12 +++++++++++- .../git/extensions/impl/SparseCheckoutPaths.java | 4 +++- .../plugins/git/CredentialsUserRemoteConfigTest.java | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/README.adoc b/README.adoc index 548b5924fa..2477ae8fee 100644 --- a/README.adoc +++ b/README.adoc @@ -159,7 +159,7 @@ This removes remote tracking branches and tags from the local workspace if they ---- checkout scmGit( branches: [[name: 'master']], - extensions: [pruneStaleBranch(), pruneTags(true)], + extensions: [ pruneStaleBranch(), pruneTags(true) ], userRemoteConfigs: [[url: 'https://github.com/jenkinsci/ws-cleanup-plugin']]) ---- @@ -1058,6 +1058,16 @@ Path:: File or directory to be included in the checkout +[source,groovy] +---- +checkout scmGit( + branches: [[name: 'master']], + extensions: [ + sparseCheckout(sparseCheckoutPaths: [[path: 'src'], [path: 'Makefile']]) + ], + userRemoteConfigs: [[url: 'https://github.com/jenkinsci/git-plugin.git']]) +---- + [#git-lfs-pull-after-checkout] ==== Git LFS pull after checkout diff --git a/src/main/java/hudson/plugins/git/extensions/impl/SparseCheckoutPaths.java b/src/main/java/hudson/plugins/git/extensions/impl/SparseCheckoutPaths.java index 0a8796f1d7..c5a326a837 100644 --- a/src/main/java/hudson/plugins/git/extensions/impl/SparseCheckoutPaths.java +++ b/src/main/java/hudson/plugins/git/extensions/impl/SparseCheckoutPaths.java @@ -13,6 +13,7 @@ import org.jenkinsci.plugins.gitclient.GitClient; import org.jenkinsci.plugins.gitclient.UnsupportedCommand; import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted; +import org.jenkinsci.Symbol; import org.kohsuke.stapler.DataBoundConstructor; import edu.umd.cs.findbugs.annotations.NonNull; @@ -52,10 +53,11 @@ public void determineSupportForJGit(GitSCM scm, @NonNull UnsupportedCommand cmd) } @Extension + @Symbol("sparseCheckout") public static class DescriptorImpl extends GitSCMExtensionDescriptor { @Override public String getDisplayName() { - return "Sparse Checkout paths"; + return "Sparse checkout paths"; } } diff --git a/src/test/java/hudson/plugins/git/CredentialsUserRemoteConfigTest.java b/src/test/java/hudson/plugins/git/CredentialsUserRemoteConfigTest.java index 5e198345db..7efa4bb3ae 100644 --- a/src/test/java/hudson/plugins/git/CredentialsUserRemoteConfigTest.java +++ b/src/test/java/hudson/plugins/git/CredentialsUserRemoteConfigTest.java @@ -163,6 +163,7 @@ private String randomPipelineExtensions() { "pruneTags()", "pruneTags(false)", "pruneTags(true)", + "sparseCheckout(sparseCheckoutPaths: [[path: 'src'], [path: 'Makefile']])", "submodule(disableSubmodules: true)", "submodule(depth: 1, shallow: true)", "submodule(parentCredentials: true, recursiveSubmodules: true, threads: 13)",