Skip to content

Commit 63b3a52

Browse files
committed
Use sparse-checkout
1 parent 5bf92cd commit 63b3a52

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

action.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@ inputs:
55
github_token:
66
description: 'GITHUB_TOKEN'
77
default: '${{ github.token }}'
8+
filter:
9+
description: >
10+
Partially clone against a given filter.
11+
default: ""
12+
use_sparse_checkout:
13+
description: >
14+
Wheter to use sparse-checkout
15+
default: false
16+
sparse_checkout:
17+
description: >
18+
Do a sparse checkout on given patterns.
19+
Each pattern should be separated with a space.
20+
default: ""
821
merge:
922
description: >
1023
Whether to actually merge the pull request or only check whether
@@ -57,6 +70,9 @@ runs:
5770
export GITHUB_TOKEN=${{ inputs.github_token }}
5871
export DEBUG=${{ inputs.debug }}
5972
export COMMENT=${{ inputs.comment }}
73+
export FILTER=${{ inputs.filter }}
74+
export USE_SPARSE_CHECKOUT=${{ inputs.use_sparse_checkout}}
75+
export SPARSE_CHECKOUT="${{ inputs.sparse_checkout }}"
6076
6177
# github.action_path is set to $REPO.
6278
if test "x${{ inputs.merge }}" = xtrue

src/fast-forward.sh

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,21 @@ case "${DEBUG:-0}" in
3434
;;
3535
esac
3636

37+
filter_string=""
38+
if [[ -n "${FILTER:-}" ]]
39+
then
40+
filter_string="--filter=${FILTER}"
41+
fi
42+
43+
case "${USE_SPARSE_CHECKOUT:-false}" in
44+
0 | false | False| FALSE) USE_SPARSE_CHECKOUT=false;;
45+
1 | true | True | TRUE) USE_SPARSE_CHECKOUT=true;;
46+
*)
47+
echo "Warning: Invalid value ('$USE_SPARSE_CHECKOUT') for USE_SPARSE_CHECKOUT." >&2;
48+
USE_SPARSE_CHECKOUT=false
49+
;;
50+
esac
51+
3752
# Set to true to post a comment to the issue.
3853
case "${COMMENT:-true}" in
3954
0 | never | false | FALSE) COMMENT=never;;
@@ -180,8 +195,18 @@ LOG=$(mktemp)
180195
} | git credential approve
181196

182197
CLONE_URL="${CLONE_URL%://*}://${GITHUB_ACTOR}@${CLONE_URL#*://}"
183-
git clone --quiet --single-branch --filter=blob:none --branch "$BASE_REF" "$CLONE_URL" .
198+
git clone --quiet ${filter_string} --no-checkout "$CLONE_URL" .
184199

200+
if [[ ${USE_SPARSE_CHECKOUT} == true ]]
201+
then
202+
echo "Initialize sparse-checkout"
203+
git sparse-checkout init
204+
if [[ -n "${SPARSE_CHECKOUT}" ]]
205+
then
206+
git sparse-checkout add ${SPARSE_CHECKOUT}
207+
fi
208+
fi
209+
git checkout "$BASE_REF"
185210
BASE_SHA="$(git rev-parse origin/$BASE_REF 2>/dev/null)"
186211
fi
187212

0 commit comments

Comments
 (0)