10000 utils: fix diff so subpaths work for sparse checkouts, fixes 1455 by patricsss · Pull Request #1484 · go-git/go-git · GitHub
[go: up one dir, main page]

Skip to content

utils: fix diff so subpaths work for sparse checkouts, fixes 1455 #1484

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

Merged
merged 1 commit into from
Apr 13, 2025

Conversation

patricsss
Copy link
Contributor
@patricsss patricsss commented Apr 2, 2025

Summary

Fix for #1455

When attempting to check out anything that isn't a root directory the Sparse Checkout options do not work correctly. This is reproducible with the examples in the above issue.

Problem

"virtual" nodes are created in the tree that represent directories. The first time a file is added to the tree it's parts are split and any missing nodes (including any directories) are added to the tree.

For example, if the first added file is foo/bar/file.yaml and this file should be skipped, entries are created for foo, foo/bar, and foo/bar/file.yaml, with all three entries setting SkipWorktree to true. If foo/baz/file.yaml is subsequently added, but should not be skipped, this is the current bug. foo already exists in the tree, and had SkipWorktree set to true. Even though foo/baz and foo/baz/file.yaml will have skip to false, they will never be included in the diff because their parent foo was already marked as skipped.

Fix

This change makes it so that any existing parents are re-checked and have their SkipWorktree boolean reset when any child of that subtree has SkipWorktree set to false.

The final issue is in the addRecursive() method. It doesn't take into consideration the SkipWorktree flag via the Skip() interface. It now checks this condition and does not add any subtrees which were marked as Skip() == true

Testing

I tested the changes with the reproduction case provided as well as through a simple unit test that attempts to highlight the issue and solution.

Open to any suggestions.

@patricsss patricsss changed the title plumbing, utils: fix diff so subpaths work for sparse checkouts, fixes 1455 utils: fix diff so subpaths work for sparse checkouts, fixes 1455 Apr 2, 2025
@patricsss patricsss marked this pull request as ready for review April 2, 2025 04:04
@patricsss patricsss force-pushed the patricsss/fix-1455 branch from c183fb2 to 96914bf Compare April 3, 2025 20:30
@patricsss
Copy link
Contributor Author
patricsss commented Apr 3, 2025

@onee-only all tests pass. I re-based all the commits into a single one which I believe adheres to the comment format. Please LMK if you need anything else. Otherwise if you can r+ and merge it'd be greatly appreciated! :)

Copy link
Contributor
@onee-only onee-only left a comment

Choose a reason for hiding this comment

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

@patricsss LGTM. But I don't have any permission to merge this PR. 😅
Let's wait for maintainers to review it.

@patricsss
Copy link
Contributor Author

@patricsss LGTM. But I don't have any permission to merge this PR. 😅 Let's wait for maintainers to review it.

My mistake haha. I assumed you were one. 😂

@pjbgf
Copy link
Member
pjbgf commented Apr 13, 2025

@patricsss thank you for working on this. 👍 @onee-only thank you for the initial reviews. 🙇

@pjbgf pjbgf merged commit ea6fea4 into go-git:main Apr 13, 2025
16 checks passed
kane8n pushed a commit to kane8n/go-git that referenced this pull request Jun 6, 2025
utils: fix diff so subpaths work for sparse checkouts, fixes 1455
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

Successfully merging this pull request may close these issues.

3 participants
0