Skip to content

Conversation

@kane8n
Copy link
Contributor

@kane8n kane8n commented Jan 7, 2026

Description

Problem

When cloning a repository with SparseCheckoutDirectories option, the sparse checkout setting was not preserved when calling SwitchBranch(). This caused a full checkout of all files instead of only the specified directories.

Root Cause

The SwitchBranch() method in client.go did not pass SparseCheckoutDirectories to wt.Checkout(), unlike the clone functions in clone.go which correctly handle this option.

Solution

  • Added sparseCheckoutDirectories field to the Client struct to store the sparse checkout configuration
  • Store the sparse checkout directories during clone operations (cloneBranch, cloneTag, cloneCommit, cloneSemVer)
  • Pass the stored sparseCheckoutDirectories to wt.Checkout() in SwitchBranch()

Changes

  • git/gogit/client.go: Added sparseCheckoutDirectories field to Client struct and updated SwitchBranch() to use it
  • git/gogit/clone.go: Store SparseCheckoutDirectories from clone options into the client
  • git/gogit/client_test.go: Added test case to verify sparse checkout is preserved after branch switch

@kane8n kane8n force-pushed the fix-switch-branch-with-sparsecheckout branch from 1a9cd37 to cd53ba1 Compare January 7, 2026 11:19
@stefanprodan stefanprodan added the area/git Git and SSH related issues and pull requests label Jan 7, 2026
Copy link
Member

@stefanprodan stefanprodan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Thanks @kane8n

Copy link
Member

@matheuscscp matheuscscp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@stefanprodan stefanprodan merged commit 8a0d2b6 into fluxcd:main Jan 7, 2026
11 checks passed
@matheuscscp
Copy link
Member

Thanks @kane8n! git/gogit/v0.43.0 is tagged, can you please implement this in source-controller and image-automation-controller? Thanks!

@stefanprodan
Copy link
Member

I don't think we switch branches in SC, this is an IAC only feature

@kane8n
Copy link
Contributor Author

kane8n commented Jan 8, 2026

@matheuscscp
Created a PR in image-automation-controller to bump git/gogit to v0.43.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/git Git and SSH related issues and pull requests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants