File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ configure_credentials "$payload"
3333
3434uri=$( jq -r ' .source.uri // ""' <<< " $payload" )
3535branch=$( jq -r ' .source.branch // ""' <<< " $payload" )
36+ sparse_paths=" $( jq -r ' (.source.sparse_paths // ["."])[]' <<< " $payload" ) " # those "'s are important
3637git_config_payload=$( jq -r ' .source.git_config // []' <<< " $payload" )
3738ref=$( jq -r ' .version.ref // "HEAD"' <<< " $payload" )
3839override_branch=$( jq -r ' .version.branch // ""' <<< " $payload" )
@@ -89,15 +90,25 @@ elif [ -n "$tag_filter" ] || [ -n "$tag_regex" ] || [ "$fetch_tags" == "true" ]
8990 tagflag=" --tags"
9091fi
9192
93+ nocheckoutflag=" "
94+ if [ " $sparse_paths " != " ." ] && [ " $sparse_paths " != " " ]; then
95+ nocheckoutflag=" --no-checkout"
96+ fi
97+
9298if [ " $disable_git_lfs " == " true" ]; then
9399 # skip the fetching of LFS objects for all following git commands
94100 export GIT_LFS_SKIP_SMUDGE=1
95101fi
96102
97- git clone --single-branch $depthflag $uri $branchflag $destination $tagflag
103+ git clone --single-branch $depthflag $uri $branchflag $destination $tagflag $nocheckoutflag
98104
99105cd $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+
101112git fetch origin refs/notes/* :refs/notes/* $tagflag
102113
103114if [ " $depth " -gt 0 ]; then
Original file line number Diff line number Diff line change @@ -91,6 +91,23 @@ it_can_get_from_url_at_override_branch() {
9191 test " $( git -C $dest rev-parse HEAD) " = $ref
9292}
9393
94+ it_can_get_from_url_with_sparse_paths () {
95+ local repo=$( init_repo)
96+ local ref1=$( make_commit_to_file $repo file-a)
97+ local ref2=$( make_commit_to_file $repo file-b)
98+ local dest=$TMPDIR /destination
99+ local sparse_paths=" file-a"
100+
101+ get_uri_with_sparse $repo $dest $sparse_paths | jq -e "
102+ .version == {ref: $( echo $ref2 | jq -R .) }
103+ "
104+
105+ test -e $dest /file-a
106+ test ! -e $dest /file-b
107+
108+ test " $( git -C $dest rev-parse HEAD) " = $ref2
109+ }
110+
94111it_omits_empty_branch_in_metadata () {
95112 local repo=$( init_repo)
96113 local ref1=$( make_commit_to_branch $repo branch-a)
@@ -916,6 +933,7 @@ run it_can_get_from_url_at_ref
916933run it_can_get_from_url_at_branch
917934run it_can_get_from_url_only_single_branch
918935run it_can_get_from_url_at_override_branch
936+ run it_can_get_from_url_with_sparse_paths
919937run it_omits_empty_branch_in_metadata
920938run it_returns_branch_in_metadata
921939run it_omits_empty_tags_in_metadata
Original file line number Diff line number Diff line change @@ -1056,6 +1056,18 @@ get_uri_with_custom_timestamp() {
10561056 }" | ${resource_dir} /in " $2 " | tee /dev/stderr
10571057}
10581058
1059+ get_uri_with_sparse () {
1060+ jq -n " {
1061+ source: {
1062+ uri: $( echo $1 | jq -R .) ,
1063+ sparse_paths: $( echo " $@ " | jq -R ' . | split(" ")' )
1064+ },
1065+ params: {
1066+ short_ref_format: \" test-%s\"
1067+ }
1068+ }" | ${resource_dir} /in " $2 " | tee /dev/stderr
1069+ }
1070+
10591071put_uri () {
10601072 jq -n " {
10611073 source: {
You can’t perform that action at this time.
0 commit comments