Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request: support sparse checkout #90

Open
missedone opened this issue Jun 10, 2020 · 11 comments · May be fixed by #1101
Open

feature request: support sparse checkout #90

missedone opened this issue Jun 10, 2020 · 11 comments · May be fixed by #1101
Labels
enhancement New feature or request help wanted Extra attention is needed no-autoclose Issues/PRs to be ignored by stale bot

Comments

@missedone
Copy link

missedone commented Jun 10, 2020

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

@c4milo
Copy link

c4milo commented Jun 24, 2020

this will be a great addition 🙌

@GridexX
Copy link

GridexX commented Sep 22, 2022

We really need this feature, is there a roadmap or something we can do for helping you ?
We could pay in ETHW 😄

mgoltzsche added a commit to mgoltzsche/khelm that referenced this issue Oct 12, 2022
This is meant to be compatible with the [helm-git](https://github.com/aslafy-z/helm-git) plugin.
The plugin has been reimplemented here since khelm does not work well with it since the it relies on other helm commands (that khelm does not support) and since it doesn't build git charts as effectively as khelm.
It uses go-git to keep the image small and self-contained: the git binary would increase the container image size by 15m while go-git is already among the transitive dependencies.
However currently [go-git does not support sparse checkouts](go-git/go-git#90).
mgoltzsche added a commit to mgoltzsche/khelm that referenced this issue Oct 12, 2022
This is meant to be compatible with the [helm-git](https://github.com/aslafy-z/helm-git) plugin.
The plugin has been reimplemented here since it relies on unsupported helm commands and since it doesn't build git charts as effective as khelm.
It uses go-git to keep the image small and self-contained: the git binary would increase the container image size by 15m while go-git is already among the transitive dependencies.
However currently [go-git does not support sparse checkouts](go-git/go-git#90).
mgoltzsche added a commit to mgoltzsche/khelm that referenced this issue Oct 12, 2022
This is meant to be compatible with the [helm-git](https://github.com/aslafy-z/helm-git) plugin.
The plugin has been reimplemented here since it relies on unsupported helm commands and since it doesn't build git charts as effective as khelm.
khelm uses go-git to keep the image small and self-contained: the git binary would increase the container image size by 15m while go-git is already among the transitive dependencies.
However currently [go-git does not support sparse checkouts](go-git/go-git#90).
mgoltzsche added a commit to mgoltzsche/khelm that referenced this issue Oct 12, 2022
This is meant to be compatible with the [helm-git](https://github.com/aslafy-z/helm-git) plugin.
The plugin has been reimplemented here since it relies on unsupported helm commands and since it doesn't build git charts as effective as khelm.
khelm uses go-git to keep the image small and self-contained: the git binary would increase the container image size by 15m while using go-git increases the size by 3m only.
However currently [go-git does not support sparse checkouts](go-git/go-git#90).
mgoltzsche added a commit to mgoltzsche/khelm that referenced this issue Oct 12, 2022
This is meant to be compatible with the [helm-git](https://github.com/aslafy-z/helm-git) plugin.
The plugin has been reimplemented here since it relies on unsupported helm commands and since it doesn't build git charts as effective as khelm.
khelm uses go-git to keep the image small and self-contained: the git binary would increase the container image size by 15m while using go-git increases the size by 3m only.
However currently [go-git does not support sparse checkouts](go-git/go-git#90).
mgoltzsche added a commit to mgoltzsche/khelm that referenced this issue Oct 12, 2022
This is meant to be compatible with the [helm-git](https://github.com/aslafy-z/helm-git) plugin.
The plugin has been reimplemented here since it relies on unsupported helm commands and since it doesn't build git charts as effective as khelm.
khelm uses go-git to keep the image small and self-contained: the git binary would increase the container image size by 15m while using go-git increases the size by 3m only.
However currently [go-git does not support sparse checkouts](go-git/go-git#90).
mgoltzsche added a commit to mgoltzsche/khelm that referenced this issue Oct 12, 2022
This is meant to be compatible with the [helm-git](https://github.com/aslafy-z/helm-git) plugin.
The plugin has been reimplemented here since it relies on unsupported helm commands and since it doesn't build git charts as effective as khelm.
khelm uses go-git to keep the image small and self-contained: the git binary would increase the container image size by 15m while using go-git increases the size by 3m only.
However currently [go-git does not support sparse checkouts](go-git/go-git#90).
mgoltzsche added a commit to mgoltzsche/khelm that referenced this issue Oct 13, 2022
This is meant to be compatible with the [helm-git](https://github.com/aslafy-z/helm-git) plugin.
The plugin has been reimplemented here since it relies on unsupported helm commands and since it doesn't build git charts as effective as khelm.
khelm uses go-git to keep the image small and self-contained: the git binary would increase the container image size by 15m while using go-git increases the size by 3m only.
However currently [go-git does not support sparse checkouts](go-git/go-git#90).
mgoltzsche added a commit to mgoltzsche/khelm that referenced this issue Oct 13, 2022
This is meant to be compatible with the [helm-git](https://github.com/aslafy-z/helm-git) plugin.
The plugin has been reimplemented here since it relies on unsupported helm commands and since it doesn't build git charts as effective as khelm.
khelm uses go-git to keep the image small and self-contained: the git binary would increase the container image size by 15m while using go-git increases the size by 3m only.
However currently [go-git does not support sparse checkouts](go-git/go-git#90).
mgoltzsche added a commit to mgoltzsche/khelm that referenced this issue Oct 17, 2022
This is meant to be compatible with the [helm-git](https://github.com/aslafy-z/helm-git) plugin.
The plugin has been reimplemented here since it relies on unsupported helm commands and since it doesn't build git charts as effective as khelm.
khelm uses go-git to keep the image small and self-contained: the git binary would increase the container image size by 15m while using go-git increases the size by 3m only.
However currently [go-git does not support sparse checkouts](go-git/go-git#90).
mgoltzsche added a commit to mgoltzsche/khelm that referenced this issue Oct 17, 2022
This is meant to be compatible with the [helm-git](https://github.com/aslafy-z/helm-git) plugin.
The plugin has been reimplemented here since it relies on unsupported helm commands and since it doesn't build git charts as effective as khelm.
khelm uses go-git to keep the image small and self-contained: the git binary would increase the container image size by 15m while using go-git increases the size by 3m only.
However currently [go-git does not support sparse checkouts](go-git/go-git#90).
mgoltzsche added a commit to mgoltzsche/khelm that referenced this issue Oct 30, 2022
This is meant to be compatible with the [helm-git](https://github.com/aslafy-z/helm-git) plugin.
The plugin has been reimplemented here since it relies on unsupported helm commands and since it doesn't build git charts as effective as khelm.
khelm uses go-git to keep the image small and self-contained: the git binary would increase the container image size by 15m while using go-git increases the size by 3m only.
However currently [go-git does not support sparse checkouts](go-git/go-git#90).
@yordis
Copy link

yordis commented Aug 25, 2023

Hey folks, I am trying to contribute to ArgoCD (and potentially FluxCD) by adding sparse checkout: argoproj/argo-cd#14272

But it seems it is not supported. Any opportunity to make the issue a priority?

@antonosmond
Copy link

@yordis AFAICT, sparse checkout is supported. You can see it in this test:

go-git/repository_test.go

Lines 291 to 320 in 809f9df

func (s *RepositorySuite) TestCloneSparse(c *C) {
fs := memfs.New()
r, err := Clone(memory.NewStorage(), fs, &CloneOptions{
URL: s.GetBasicLocalRepositoryURL(),
})
c.Assert(err, IsNil)
w, err := r.Worktree()
c.Assert(err, IsNil)
sparseCheckoutDirectories := []string{"go", "json", "php"}
c.Assert(w.Checkout(&CheckoutOptions{
Branch: "refs/heads/master",
SparseCheckoutDirectories: sparseCheckoutDirectories,
}), IsNil)
fis, err := fs.ReadDir(".")
c.Assert(err, IsNil)
for _, fi := range fis {
c.Assert(fi.IsDir(), Equals, true)
var oneOfSparseCheckoutDirs bool
for _, sparseCheckoutDirectory := range sparseCheckoutDirectories {
if strings.HasPrefix(fi.Name(), sparseCheckoutDirectory) {
oneOfSparseCheckoutDirs = true
}
}
c.Assert(oneOfSparseCheckoutDirs, Equals, true)
}
}

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!

@yordis
Copy link

yordis commented Sep 18, 2023

I removed the usage of the package btw!

@emirot
Copy link

emirot commented Oct 14, 2023

@yordis @antonosmond

What did not work?

It looks to be working in my simple test: https://github.com/emirot/test-go-git/tree/main

Copy link

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!

@github-actions github-actions bot added the stale Issues/PRs that are marked for closure due to inactivity label Jan 18, 2024
@jberger-dynatrace
Copy link

We would appreciate this feature as well!

@github-actions github-actions bot removed the stale Issues/PRs that are marked for closure due to inactivity label Feb 9, 2024
@object88
Copy link

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 "git@github.com: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.

@wilstdu
Copy link

wilstdu commented May 8, 2024

@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

@pjbgf pjbgf added the no-autoclose Issues/PRs to be ignored by stale bot label May 20, 2024
@wandergeek
Copy link

Would also love this feature!

onee-only added a commit to onee-only/go-git that referenced this issue May 28, 2024
@onee-only onee-only linked a pull request May 28, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed no-autoclose Issues/PRs to be ignored by stale bot
Projects
None yet
Development

Successfully merging a pull request may close this issue.