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

BUG: Spare checkout would checkout all files. #1072

Open
wethura opened this issue Apr 7, 2024 · 0 comments
Open

BUG: Spare checkout would checkout all files. #1072

wethura opened this issue Apr 7, 2024 · 0 comments

Comments

@wethura
Copy link

wethura commented Apr 7, 2024

Backgrounp: I try to clone the sub-dir in a git repo, and i found Chekout with SparseCheckoutDirectories fit me. But when i use it to achive my goal, i found it's useless. i found it work to checkout the specify dirs only when i clone with NoCheckout=false and checkout the same tag/branch like clone.

Reproduce:

code-01:

        fs := memfs.New()
	r, err := gitv5.Clone(memory.NewStorage(), fs, &gitv5.CloneOptions{
		URL: "{{repo url}}",
		ReferenceName:   plumbing.NewTagReferenceName(tag),
	})
	require.NoError(t, err)

	worktree, err := r.Worktree()
	require.NoError(t, err)

	err = worktree.Checkout(&gitv5.CheckoutOptions{
		SparseCheckoutDirectories: []string{"test"},
		Branch:                    plumbing.NewBranchReferenceName(branch),
	})

	require.NoError(t, err) // you can found all files are checkouted.

code-02:

        fs := memfs.New()
	r, err := gitv5.Clone(memory.NewStorage(), fs, &gitv5.CloneOptions{
		URL: "{{repo url}}",
		ReferenceName:   plumbing.NewTagReferenceName(tag),
                NoCheckout: true,
	})
	require.NoError(t, err)

	worktree, err := r.Worktree()
	require.NoError(t, err)

	err = worktree.Checkout(&gitv5.CheckoutOptions{
		SparseCheckoutDirectories: []string{"test"},
		Branch:                    plumbing.NewTagReferenceName(tag),
	})

	require.NoError(t, err) // you can found all files are checkouted.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant