Skip to content

Commit 05da202

Browse files
add ability to perform a sparse checkout
Signed-off-by: Casey Braithwaite <casey.braithwaite@capgemini.com>
1 parent 702bf5a commit 05da202

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

assets/in

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ configure_credentials "$payload"
3333

3434
uri=$(jq -r '.source.uri // ""' <<< "$payload")
3535
branch=$(jq -r '.source.branch // ""' <<< "$payload")
36+
sparse_paths="$(jq -r '(.source.sparse_paths // ["."])[]' <<< "$payload")" # those "'s are important
3637
git_config_payload=$(jq -r '.source.git_config // []' <<< "$payload")
3738
ref=$(jq -r '.version.ref // "HEAD"' <<< "$payload")
3839
override_branch=$(jq -r '.version.branch // ""' <<< "$payload")
@@ -89,15 +90,25 @@ elif [ -n "$tag_filter" ] || [ -n "$tag_regex" ] || [ "$fetch_tags" == "true" ]
8990
tagflag="--tags"
9091
fi
9192

93+
nocheckoutflag=""
94+
if [ "$sparse_paths" != "." ] && [ "$sparse_paths" != "" ]; then
95+
nocheckoutflag=" --no-checkout"
96+
fi
97+
9298
if [ "$disable_git_lfs" == "true" ]; then
9399
# skip the fetching of LFS objects for all following git commands
94100
export GIT_LFS_SKIP_SMUDGE=1
95101
fi
96102

97-
git clone --single-branch $depthflag $uri $branchflag $destination $tagflag
103+
git clone --single-branch $depthflag $uri $branchflag $destination $tagflag $nocheckoutflag
98104

99105
cd $destination
100106

107+
if [ "$sparse_paths" != "." ] && [ "$sparse_paths" != "" ]; then
108+
git config core.sparseCheckout true
109+
echo "$sparse_paths" >> ./.git/info/sparse-checkout
110+
fi
111+
101112
git fetch origin refs/notes/*:refs/notes/* $tagflag
102113

103114
if [ "$depth" -gt 0 ]; then

0 commit comments

Comments
 (0)