-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Add support for sparse checkouts #1369
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/bin/sh | ||
|
||
# Verify .git folder | ||
if [ ! -d "./sparse-checkout-non-cone-mode/.git" ]; then | ||
echo "Expected ./sparse-checkout-non-cone-mode/.git folder to exist" | ||
exit 1 | ||
fi | ||
|
||
# Verify sparse-checkout (non-cone-mode) | ||
cd sparse-checkout-non-cone-mode | ||
|
||
ENABLED=$(git config --local --get-all core.sparseCheckout) | ||
|
||
if [ "$?" != "0" ]; then | ||
echo "Failed to verify that sparse-checkout is enabled" | ||
exit 1 | ||
fi | ||
|
||
# Check that sparse-checkout is enabled | ||
if [ "$ENABLED" != "true" ]; then | ||
echo "Expected sparse-checkout to be enabled (is: $ENABLED)" | ||
exit 1 | ||
fi | ||
|
||
SPARSE_CHECKOUT_FILE=$(git rev-parse --git-path info/sparse-checkout) | ||
|
||
if [ "$?" != "0" ]; then | ||
echo "Failed to validate sparse-checkout" | ||
exit 1 | ||
fi | ||
|
||
# Check that sparse-checkout list is not empty | ||
if [ ! -f "$SPARSE_CHECKOUT_FILE" ]; then | ||
echo "Expected sparse-checkout file to exist" | ||
exit 1 | ||
fi | ||
|
||
# Check that all folders from sparse-checkout exists | ||
for pattern in $(cat "$SPARSE_CHECKOUT_FILE") | ||
do | ||
if [ ! -d "${pattern#/}" ]; then | ||
echo "Expected directory '${pattern#/}' to exist" | ||
exit 1 | ||
fi | ||
done | ||
|
||
# Verify that the root directory is not checked out | ||
if [ -f README.md ]; then | ||
echo "Expected top-level files not to exist" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/bin/sh | ||
|
||
# Verify .git folder | ||
if [ ! -d "./sparse-checkout/.git" ]; then | ||
echo "Expected ./sparse-checkout/.git folder to exist" | ||
exit 1 | ||
fi | ||
|
||
# Verify sparse-checkout | ||
cd sparse-checkout | ||
|
||
SPARSE=$(git sparse-checkout list) | ||
|
||
if [ "$?" != "0" ]; then | ||
echo "Failed to validate sparse-checkout" | ||
exit 1 | ||
fi | ||
|
||
# Check that sparse-checkout list is not empty | ||
if [ -z "$SPARSE" ]; then | ||
echo "Expected sparse-checkout list to not be empty" | ||
exit 1 | ||
fi | ||
|
||
# Check that all folders of the sparse checkout exist | ||
for pattern in $SPARSE | ||
do | ||
if [ ! -d "$pattern" ]; then | ||
echo "Expected directory '$pattern' to exist" | ||
exit 1 | ||
fi | ||
done | ||
|
||
checkSparse () { | ||
if [ ! -d "./$1" ]; then | ||
echo "Expected directory '$1' to exist" | ||
exit 1 | ||
fi | ||
|
||
for file in $(git ls-tree -r --name-only HEAD $1) | ||
do | ||
if [ ! -f "$file" ]; then | ||
echo "Expected file '$file' to exist" | ||
exit 1 | ||
fi | ||
done | ||
} | ||
|
||
# Check that all folders and their children have been checked out | ||
checkSparse __test__ | ||
checkSparse .github | ||
checkSparse dist | ||
|
||
# Check that only sparse-checkout folders have been checked out | ||
for pattern in $(git ls-tree --name-only HEAD) | ||
do | ||
if [ -d "$pattern" ]; then | ||
if [[ "$pattern" != "__test__" && "$pattern" != ".github" && "$pattern" != "dist" ]]; then | ||
echo "Expected directory '$pattern' to not exist" | ||
exit 1 | ||
fi | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you might provide another example for fetch single file that is not on the root dir? ex: few directory deep, etc.
also, maybe some examples of using glob pattern, ex checkout all
*.md
files? 😄There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's sounds great! 🚀
And maybe it has sense to add an example with
lfs
? In order to let know that the fetch oflfs
can be reduced with thesparse-checkout
option to 🤔There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would require non-cone mode, which is deprecated by the Git project: https://git-scm.com/docs/git-sparse-checkout#_internalscone_pattern_set
Seeing as it is deprecated, I would like to avoid encouraging users to use it. Read: I do not want to add documentation how to do this, giving users the impression that they should use this.
The first part would be easy, by adding another LFS step that simply uses
sparse-checkout: .
.However, the second part would be a bit tricky because this test requires a branch with LFS objects, and it uses the
test-data/v2/lfs
branch ofactions/checkout
itself. As you can see here, there is only one LFS file, in the root directory. Therefore, even in sparse checkout mode "all the LFS files" are fetched, i.e. that single one.It would require adding another branch to the repository, with an additional LFS file in a subdirectory, and then we would still need to figure out a robust way to verify that it was not fetched, most likely relying on implementation details such as the location of the LFS cache (
.git/lfs/objects
) and the cache files' names, which would be fragile because implementation details are not guaranteed to remain unchanged.So I don't know whether it is worth the effort.