gitchef-infragit-sparse-checkout

Git checkout single directory through Chef


Is there a way of doing an sparse checkout with Chef and its git resource? Or what is the best way to accomplish the equivalent of that?

As doing a sparse checkout requires modifying a file in the .git folder before doing the pull, I don't find a way of having the git resource configure the repository but not attempting to pull before I can edit that file. If I wait until the end of the git resource execution, then the total number of files of the tip of the branch will be already downloaded.

For reference this is what I'd otherwise do if I were doing a bash script:

git init <my_repo>
cd <my_repo>
git remote add origin <my_repos_url>
git config core.sparsecheckout true
echo "my_directory/*" >> .git/info/sparse-checkout
git pull --depth=1 origin master

Question also posted here: https://discourse.chef.io/t/sparse-checkout-with-git-resource/11834


Solution

  • This is not supported really. Your best bet is probably to use an execute/bash resource do everything except the actual pull, and then put a normal git resource after that since it should obey the settings once set up.