puppetlabs / puppetlabs-vcsrepo

Support for source control repositories
http://forge.puppetlabs.com/puppetlabs/vcsrepo
GNU General Public License v2.0
223 stars 284 forks source link

Enable Git Sparse Checkout #636

Open jplindquist opened 4 months ago

jplindquist commented 4 months ago

Use Case

There is a somewhat common pattern of using monorepos across a variety of orgs, and it's not always necessary (or desirable) to have all of the code checked out for each component. Git allows for sparse checkouts where you can specific files, paths, etc to checkout and track vs. the entire repo.

Describe the Solution You Would Like

I would love for the vcsrepo git type to suppport sparse checkouts. I saw that the feature is enabled for svn currently. The git documentation to use the specific subcommand would require a newer version of git (>= 2.25 iirc), but supports other methods of accomplishing this in earlier versions of the client.

Describe Alternatives You've Considered

We can checkout the full repo as is if needed, but it is undesirable in certain scenarios where multiple applications might share a single repo when they're deployed to different places or in different ways.

Additional Context

Samples:

With a directory structure such as the following:

  mymodules/
   python-module/
     __init__.py
     module.py
   go-module/
     main.go
     go.mod
     go.sum

If I wanted to clone only the python-module directory, I would do the following:

Using Newer Version of Git

mkdir python-module && cd python-module
git clone --depth 1 --no-checkout git@github.com:myorg/mymodules.git ./
git sparse-checkout init --no-cone
git sparse-checkout set python-module/
git checkout main

Using Older Version of Git

mkdir python-module && cd python-module
git clone --depth 1 --no-checkout git@github.com:myorg/mymodules.git ./
git config core.sparsecheckout true
echo 'python-module/' >> .git/info/sparse-checkout
git checkout main

My directory structure would now look like this:

  ../python-module/
    .git/
    python-module/
      __init__.py
      module.py

There are a variety of other options obviously and ways to check out root files (--cone vs. --no-cone) , but this is the gist of it