Hi Mark

On Sat, Jan 11, 2025 at 3:16 PM Mark Waite <mark.earl.wa...@gmail.com> wrote:
>
>
>
> On Saturday, January 11, 2025 at 4:22:58 AM UTC-7 Michael wrote:
>
> Hi all
>
> Is it possible to use git clone from sh context but then populate as I
> had clone using gitscm?
>
>
> Not really.  Maybe you could approximate it by calling checkout scm with 
> parameters that try to duplicate your git clone parameters and use the return 
> value from checkout scm.
>

Right now what I'm trying to do is something like this and change groovy library

-        def git_opts = history ? '--filter=tree:0' : '--depth 1'
+        def depth = history ? 0 : 1
         def updateRepository = {
-            if (context.fileExists(directory)) {
-                context.dir(directory) {
-                    context.sh """
-                        git remote remove origin
-                        git remote add origin ${url}
-                        git remote set-branches --add origin ${branch}
-                        git fetch origin ${branch} ${git_opts}
-                        git reset --hard FETCH_HEAD
-                    """
-                }
-            } else {
-                context.sh "git clone ${git_opts} --branch ${branch}
${url} ${directory}"
-            }
+            context.checkout(
+                changelog: true,
+                poll: false,
+                scm: [
+                    $class: 'GitSCM',
+                    branches: [[name: "*/${branch}"]],
+                    extensions: [
+                        [$class: 'cleanAfterCheckout',
deleteUntrackedNestedRepositories: true],
+                        [$class: 'RelativeTargetDirectory',
relativeTargetDir: "${directory}"],
+                        [$class: 'CloneOption', depth: "${depth}",
honorRefspec: true, noTags: false, \
+                                 reference: "${directory}", shallow:
depth > 0 ? true : false
+                        ]
+                    ],
+                    userRemoteConfigs: [
+                        [credentialsId: "${credentials}", url: "${url}"]
+                    ]
+                ]
+            )
         }


This is not exactly the same (by the way needs to be tested) but using
gitscm I have a lot more features. Would be nice to allow
gitscm to re-evaluate some already checkout or already .git on
filesystem to calculate the data. Looking at several plugins does not
sound very easy. The reason that I'm moving to using gitscm is to
integrate plugins like git-forensic etc. I have found gitSCM really
nice
but could be a bit limited if you are trying to have more git
flexibility. Like in this case I can not use --filter=tree:0'

Michael


> Mark Waite
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Jenkins Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to jenkinsci-dev+unsubscr...@googlegroups.com.
> To view this discussion visit 
> https://groups.google.com/d/msgid/jenkinsci-dev/ea47d6bd-097f-41b2-a223-ae42d1277853n%40googlegroups.com.



-- 
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
mich...@amarulasolutions.com
__________________________________

Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
i...@amarulasolutions.com
www.amarulasolutions.com

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-dev+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/jenkinsci-dev/CAOf5uwm%3D9GRa6Ctdspo698rt%2Bj7NfKom-JXPAb5fodE%3D1gPquQ%40mail.gmail.com.

Reply via email to