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

Implement Sparse Checkout for GitRepository #1774

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dipti-pai
Copy link
Member

@dipti-pai dipti-pai commented Apr 10, 2025

Sparse Checkout Directories in GitRepositories.

  • Add .spec.sparseCheckout and .status.observedSparseCheckout fields to GitRepository.
  • Add controller support to send the sparse checkout directories to go-git via pkg methods.
  • Add tests for testing the observed sparse checkout behavior.
  • Add docs describing the new fields.

Fixes: #1707

Current behavior worth calling out.

  1. If .spec.sparseCheckout directory list includes a directory that does not exist, the underlying go-git checkout method does not return an error and silently continues. See SparseCheckoutDirectories behavior when directory path does not exist go-git/go-git#1500
  2. If .spec.sparseCheckout directory list includes directory with more than one level of nesting, sparse checkout is not honored and all directories at top-level are checked out. Will be fixed by SparseCheckoutDirectories works only for 1st level directory. go-git/go-git#1455
  3. If .spec.sparseCheckout uses relative path beginning with a ./, the path is ignored and nothing is checked out and no errors are thrown. See SparseCheckoutDirectories ignores relative paths beginning with (./) while checking out git repository go-git/go-git#1506 . This is being handled in source-controller.
    4.. If .spec.sparseCheckout includes an empty directory, the entire repository is checked out (Expected)

@dipti-pai dipti-pai marked this pull request as draft April 10, 2025 22:25
@dipti-pai dipti-pai force-pushed the git-sparse-checkout branch 3 times, most recently from 72d3852 to 7035a58 Compare April 10, 2025 23:27
@stefanprodan stefanprodan changed the title Sparse Checkout Directories in GitRepositories. Implement Sparse Checkout for GitRepository Apr 11, 2025
@stefanprodan stefanprodan added area/git Git related issues and pull requests area/api API related issues and pull requests labels Apr 11, 2025
@stefanprodan
Copy link
Member

If .spec.sparseCheckout uses relative path beginning with a ./, the path is ignored and nothing is checked out and no errors are thrown.

@dipti-pai I think we should handle this on our own. We could trim ./ by prefix, before passing the array to the Git client.

    - Add `.spec.sparseCheckout` and `.status.observedSparseCheckout` fields to `GitRepository`.
    - Add controller support to send the sparse checkout directories to go-git via pkg methods.
    - Add tests for testing the observed sparse checkout behavior.
    - Add docs describing the new fields.

Signed-off-by: Dipti Pai <[email protected]>
@dipti-pai dipti-pai force-pushed the git-sparse-checkout branch from 7035a58 to 7565fa8 Compare April 11, 2025 17:23
@dipti-pai dipti-pai marked this pull request as ready for review April 11, 2025 17:41
@pjbgf
Copy link
Member

pjbgf commented Apr 13, 2025

From the abnormal behaviours called out, #2 was the only one which there would not be a way to work around straight from the controller. That is now fixed and merged into main.

I'd agree with @stefanprodan on #3, and the fix LGTM.

For #1, we could workaround by adding a os.Lstat after the clone operation to confirm the dir exists - only when sparse checkout is used. @stefanprodan WDYT?

@stefanprodan
Copy link
Member

we could workaround by adding a os.Lstat after the clone operation to confirm the dir exists - only when sparse checkout is used

Yes we could verify the dirs and error out in the controller 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api API related issues and pull requests area/git Git related issues and pull requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for sparse checkout to GitRepository API
3 participants