feature request: support sparse checkout
https://github.blog/2020-01-13-highlights-from-git-2-25/ git supports sparse checkout. in my case, i'd like to clone (checkout) a subfolder out of a large git repo for now it seems can not be done with go-git.
thanks
this will be a great addition 🙌
We really need this feature, is there a roadmap or something we can do for helping you ? We could pay in ETHW :smile:
Hey folks, I am trying to contribute to ArgoCD (and potentially FluxCD) by adding sparse checkout: https://github.com/argoproj/argo-cd/pull/14272
But it seems it is not supported. Any opportunity to make the issue a priority?
@yordis AFAICT, sparse checkout is supported. You can see it in this test: https://github.com/go-git/go-git/blob/809f9df1b76258a311a20c76d346e86aca0a08f8/repository_test.go#L291-L320
That being said, I'm trying to use this and it doesn't appear to working. After the checkout, I seem to have all dirs in the worktree, not just the sparse dirs. If you get it working, let me know! Thanks!
I removed the usage of the package btw!
@yordis @antonosmond
What did not work?
It looks to be working in my simple test: https://github.com/emirot/test-go-git/tree/main
To help us keep things tidy and focus on the active tasks, we've introduced a stale bot to spot issues/PRs that haven't had any activity in a while.
This particular issue hasn't had any updates or activity in the past 90 days, so it's been labeled as 'stale'. If it remains inactive for the next 30 days, it'll be automatically closed.
We understand everyone's busy, but if this issue is still important to you, please feel free to add a comment or make an update to keep it active.
Thanks for your understanding and cooperation!
We would appreciate this feature as well!
I also am having trouble using SparseCheckoutDirectories (with go-git v5.11.0). My case may be slightly strange, though. I want to get a sparse checkout from a particular commit. My code, in brief:
# sha -> 40 character SHA
# path -> subfolder in my repo, ala "src/app/config"
# repo -> git form of my repo, ala "[email protected]:myorg/myrepo.git"
tempDir, _ := os.MkdirTemp("", "source-*")
fs := osfs.New(tempDir)
dot, _ := fs.Chroot(".git")
s := filesystem.NewStorage(dot, cache.NewObjectLRUDefault())
refspec := config.RefSpec(fmt.Sprintf("+%s:refs/remotes/origin/%s", sha, sha))
r, _ := gogit.Init(s, fs)
r.CreateRemote(&config.RemoteConfig{
Fetch: []config.RefSpec{refspec},
Name: "origin",
URLs: []string{repo},
})
w, _ := r.Worktree()
r.Fetch(&gogit.FetchOptions{
Depth: 1,
InsecureSkipTLS: false,
Tags: gogit.NoTags,
})
w.Checkout(&gogit.CheckoutOptions{
Hash: plumbing.NewHash(sha),
SparseCheckoutDirectories: []string{path},
})
While the sample code above does not show error checking, it is present in my actual code, and no errors are coming back.
I have also tried setting path as just "src" (instead of "src/app/cfg") to match the test mentioned above, but same behavior. Also same if I add a Force: true to the CheckoutOptions.
@yordis @antonosmond
What did not work?
It looks to be working in my simple test: https://github.com/emirot/test-go-git/tree/main
@emirot for you this works, because your example doesn't have NoCheckout: true, in git.CloneOptions of git.PlainClone
Would also love this feature!