From 99fc22de1fbeab661d12d5a67e59b2397a301949 Mon Sep 17 00:00:00 2001 From: Finley Garton Date: Fri, 30 Jun 2023 17:12:38 +0100 Subject: [PATCH 1/8] added filter option & tests --- .github/workflows/test.yml | 11 +++++++++++ __test__/input-helper.test.ts | 1 + __test__/verify-fetch-filter.sh | 15 +++++++++++++++ action.yml | 3 +++ src/git-source-provider.ts | 8 +++++++- src/git-source-settings.ts | 5 +++++ src/input-helper.ts | 4 ++++ 7 files changed, 46 insertions(+), 1 deletion(-) create mode 100755 __test__/verify-fetch-filter.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d8b0b6d58..bfd9dccca 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -72,6 +72,17 @@ jobs: shell: bash run: __test__/verify-side-by-side.sh + # Filter + - name: Fetch filter + uses: ./ + with: + filter: 'blob:none' + path: fetch-filter + + - name: Verify fetch filter + run: __test__/verify-fetch-filter.sh + + # Sparse checkout - name: Sparse checkout uses: ./ diff --git a/__test__/input-helper.test.ts b/__test__/input-helper.test.ts index 069fda4be..5a74b1cd3 100644 --- a/__test__/input-helper.test.ts +++ b/__test__/input-helper.test.ts @@ -79,6 +79,7 @@ describe('input-helper tests', () => { expect(settings.clean).toBe(true) expect(settings.commit).toBeTruthy() expect(settings.commit).toBe('1234567890123456789012345678901234567890') + expect(settings.filter).toBe(undefined) expect(settings.sparseCheckout).toBe(undefined) expect(settings.sparseCheckoutConeMode).toBe(true) expect(settings.fetchDepth).toBe(1) diff --git a/__test__/verify-fetch-filter.sh b/__test__/verify-fetch-filter.sh new file mode 100755 index 000000000..fa6eaf1d0 --- /dev/null +++ b/__test__/verify-fetch-filter.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# Verify .git folder +if [ ! -d "./fetch-filter/.git" ]; then + echo "Expected ./fetch-filter/.git folder to exist" + exit 1 +fi + +# Verify .git/config contains partialclonefilter + +CLONE_FILTER=$(git config --local --get remote.origin.partialclonefilter) + +if [ "$CLONE_FILTER" != "blob:none" ]; then + echo "Expected ./fetch-filter/.git/config to have 'remote.origin.partialclonefilter' set to 'blob:none'" +fi diff --git a/action.yml b/action.yml index e562b569f..4d44d67b3 100644 --- a/action.yml +++ b/action.yml @@ -53,6 +53,9 @@ inputs: clean: description: 'Whether to execute `git clean -ffdx && git reset --hard HEAD` before fetching' default: true + filter: + description: 'Partially clone against a given filter.' + default: null sparse-checkout: description: > Do a sparse checkout on given patterns. diff --git a/src/git-source-provider.ts b/src/git-source-provider.ts index 8f9d63f55..19fe5647e 100644 --- a/src/git-source-provider.ts +++ b/src/git-source-provider.ts @@ -154,7 +154,13 @@ export async function getSource(settings: IGitSourceSettings): Promise { // Fetch core.startGroup('Fetching the repository') const fetchOptions: {filter?: string; fetchDepth?: number} = {} - if (settings.sparseCheckout) fetchOptions.filter = 'blob:none' + + if (settings.filter) { + fetchOptions.filter = settings.filter + } else if (settings.sparseCheckout) { + fetchOptions.filter = 'blob:none' + } + if (settings.fetchDepth <= 0) { // Fetch all branches and tags let refSpec = refHelper.getRefSpecForAllHistory( diff --git a/src/git-source-settings.ts b/src/git-source-settings.ts index 3272e638c..f5f38794e 100644 --- a/src/git-source-settings.ts +++ b/src/git-source-settings.ts @@ -29,6 +29,11 @@ export interface IGitSourceSettings { */ clean: boolean + /** + * The filter determining which objects to include + */ + filter: string | undefined + /** * The array of folders to make the sparse checkout */ diff --git a/src/input-helper.ts b/src/input-helper.ts index 410e48032..8d6d13ac7 100644 --- a/src/input-helper.ts +++ b/src/input-helper.ts @@ -82,6 +82,10 @@ export async function getInputs(): Promise { result.clean = (core.getInput('clean') || 'true').toUpperCase() === 'TRUE' core.debug(`clean = ${result.clean}`) + // Filter + result.filter = core.getInput('filter') + core.debug(`filter = ${result.filter}`) + // Sparse checkout const sparseCheckout = core.getMultilineInput('sparse-checkout') if (sparseCheckout.length) { From 7e6f3d7a1e62cbf215fb77516921cd9c01342083 Mon Sep 17 00:00:00 2001 From: Finley Garton Date: Fri, 30 Jun 2023 17:15:03 +0100 Subject: [PATCH 2/8] added build file --- README.md | 4 ++++ dist/index.js | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5427a500a..87066a6ba 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,10 @@ When Git 2.18 or higher is not in your PATH, falls back to the REST API to downl # Default: true clean: '' + # Partially clone against a given filter. + # Default: null + filter: '' + # Do a sparse checkout on given patterns. Each pattern should be separated with # new lines # Default: null diff --git a/dist/index.js b/dist/index.js index 455629582..6d278ed8e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1241,8 +1241,12 @@ function getSource(settings) { // Fetch core.startGroup('Fetching the repository'); const fetchOptions = {}; - if (settings.sparseCheckout) + if (settings.filter) { + fetchOptions.filter = settings.filter; + } + else if (settings.sparseCheckout) { fetchOptions.filter = 'blob:none'; + } if (settings.fetchDepth <= 0) { // Fetch all branches and tags let refSpec = refHelper.getRefSpecForAllHistory(settings.ref, settings.commit); @@ -1719,6 +1723,9 @@ function getInputs() { // Clean result.clean = (core.getInput('clean') || 'true').toUpperCase() === 'TRUE'; core.debug(`clean = ${result.clean}`); + // Filter + result.filter = core.getInput('filter'); + core.debug(`filter = ${result.filter}`); // Sparse checkout const sparseCheckout = core.getMultilineInput('sparse-checkout'); if (sparseCheckout.length) { From 299846e624fc46617c47234d5cf47789df0b30d6 Mon Sep 17 00:00:00 2001 From: Finley Garton Date: Fri, 30 Jun 2023 17:30:43 +0100 Subject: [PATCH 3/8] fix test oversight --- __test__/git-auth-helper.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/__test__/git-auth-helper.test.ts b/__test__/git-auth-helper.test.ts index fec657394..7ed368642 100644 --- a/__test__/git-auth-helper.test.ts +++ b/__test__/git-auth-helper.test.ts @@ -802,6 +802,7 @@ async function setup(testName: string): Promise { authToken: 'some auth token', clean: true, commit: '', + filter: undefined, sparseCheckout: [], sparseCheckoutConeMode: true, fetchDepth: 1, From 573932dbdda76b2055415af22b663867dae9bdc3 Mon Sep 17 00:00:00 2001 From: Finley Garton Date: Wed, 26 Jul 2023 10:02:46 +0100 Subject: [PATCH 4/8] added exit 1 --- __test__/verify-fetch-filter.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/__test__/verify-fetch-filter.sh b/__test__/verify-fetch-filter.sh index fa6eaf1d0..6d021eee4 100755 --- a/__test__/verify-fetch-filter.sh +++ b/__test__/verify-fetch-filter.sh @@ -12,4 +12,5 @@ CLONE_FILTER=$(git config --local --get remote.origin.partialclonefilter) if [ "$CLONE_FILTER" != "blob:none" ]; then echo "Expected ./fetch-filter/.git/config to have 'remote.origin.partialclonefilter' set to 'blob:none'" + exit 1 fi From 26d044865990e15712fb05d767ad3b4bb6e64aaa Mon Sep 17 00:00:00 2001 From: Finley Garton Date: Fri, 8 Sep 2023 17:20:25 +0100 Subject: [PATCH 5/8] updated docs to specify override --- .github/workflows/test.yml | 1 - README.md | 33 +++++++++++++++++++-------------- action.yml | 6 ++++-- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 21c426570..15996ee7e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -81,7 +81,6 @@ jobs: - name: Verify fetch filter run: __test__/verify-fetch-filter.sh - # Sparse checkout - name: Sparse checkout diff --git a/README.md b/README.md index de8fe48d9..e0af45361 100644 --- a/README.md +++ b/README.md @@ -75,12 +75,12 @@ When Git 2.18 or higher is not in your PATH, falls back to the REST API to downl # Default: true clean: '' - # Partially clone against a given filter. + # Partially clone against a given filter. Overrides sparse-checkout if set. # Default: null filter: '' # Do a sparse checkout on given patterns. Each pattern should be separated with - # new lines + # new lines. # Default: null sparse-checkout: '' @@ -128,18 +128,23 @@ When Git 2.18 or higher is not in your PATH, falls back to the REST API to downl # Scenarios -- [Fetch only the root files](#Fetch-only-the-root-files) -- [Fetch only the root files and `.github` and `src` folder](#Fetch-only-the-root-files-and-github-and-src-folder) -- [Fetch only a single file](#Fetch-only-a-single-file) -- [Fetch all history for all tags and branches](#Fetch-all-history-for-all-tags-and-branches) -- [Checkout a different branch](#Checkout-a-different-branch) -- [Checkout HEAD^](#Checkout-HEAD) -- [Checkout multiple repos (side by side)](#Checkout-multiple-repos-side-by-side) -- [Checkout multiple repos (nested)](#Checkout-multiple-repos-nested) -- [Checkout multiple repos (private)](#Checkout-multiple-repos-private) -- [Checkout pull request HEAD commit instead of merge commit](#Checkout-pull-request-HEAD-commit-instead-of-merge-commit) -- [Checkout pull request on closed event](#Checkout-pull-request-on-closed-event) -- [Push a commit using the built-in token](#Push-a-commit-using-the-built-in-token) +- [Checkout V4](#checkout-v4) +- [What's new](#whats-new) +- [Usage](#usage) +- [Scenarios](#scenarios) + - [Fetch only the root files](#fetch-only-the-root-files) + - [Fetch only the root files and `.github` and `src` folder](#fetch-only-the-root-files-and-github-and-src-folder) + - [Fetch only a single file](#fetch-only-a-single-file) + - [Fetch all history for all tags and branches](#fetch-all-history-for-all-tags-and-branches) + - [Checkout a different branch](#checkout-a-different-branch) + - [Checkout HEAD^](#checkout-head) + - [Checkout multiple repos (side by side)](#checkout-multiple-repos-side-by-side) + - [Checkout multiple repos (nested)](#checkout-multiple-repos-nested) + - [Checkout multiple repos (private)](#checkout-multiple-repos-private) + - [Checkout pull request HEAD commit instead of merge commit](#checkout-pull-request-head-commit-instead-of-merge-commit) + - [Checkout pull request on closed event](#checkout-pull-request-on-closed-event) + - [Push a commit using the built-in token](#push-a-commit-using-the-built-in-token) +- [License](#license) ## Fetch only the root files diff --git a/action.yml b/action.yml index 77ea8c7ca..5aa90a738 100644 --- a/action.yml +++ b/action.yml @@ -54,12 +54,14 @@ inputs: description: 'Whether to execute `git clean -ffdx && git reset --hard HEAD` before fetching' default: true filter: - description: 'Partially clone against a given filter.' + description: > + Partially clone against a given filter. + Overrides sparse-checkout if set. default: null sparse-checkout: description: > Do a sparse checkout on given patterns. - Each pattern should be separated with new lines + Each pattern should be separated with new lines. default: null sparse-checkout-cone-mode: description: > From 2f8a3343163fa0f8e7c1a5093601f950dd70096f Mon Sep 17 00:00:00 2001 From: Finley Garton Date: Fri, 8 Sep 2023 17:22:52 +0100 Subject: [PATCH 6/8] undo unneeded readme change --- README.md | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index e0af45361..92bc78443 100644 --- a/README.md +++ b/README.md @@ -128,23 +128,18 @@ When Git 2.18 or higher is not in your PATH, falls back to the REST API to downl # Scenarios -- [Checkout V4](#checkout-v4) -- [What's new](#whats-new) -- [Usage](#usage) -- [Scenarios](#scenarios) - - [Fetch only the root files](#fetch-only-the-root-files) - - [Fetch only the root files and `.github` and `src` folder](#fetch-only-the-root-files-and-github-and-src-folder) - - [Fetch only a single file](#fetch-only-a-single-file) - - [Fetch all history for all tags and branches](#fetch-all-history-for-all-tags-and-branches) - - [Checkout a different branch](#checkout-a-different-branch) - - [Checkout HEAD^](#checkout-head) - - [Checkout multiple repos (side by side)](#checkout-multiple-repos-side-by-side) - - [Checkout multiple repos (nested)](#checkout-multiple-repos-nested) - - [Checkout multiple repos (private)](#checkout-multiple-repos-private) - - [Checkout pull request HEAD commit instead of merge commit](#checkout-pull-request-head-commit-instead-of-merge-commit) - - [Checkout pull request on closed event](#checkout-pull-request-on-closed-event) - - [Push a commit using the built-in token](#push-a-commit-using-the-built-in-token) -- [License](#license) +- [Fetch only the root files](#Fetch-only-the-root-files) +- [Fetch only the root files and `.github` and `src` folder](#Fetch-only-the-root-files-and-github-and-src-folder) +- [Fetch only a single file](#Fetch-only-a-single-file) +- [Fetch all history for all tags and branches](#Fetch-all-history-for-all-tags-and-branches) +- [Checkout a different branch](#Checkout-a-different-branch) +- [Checkout HEAD^](#Checkout-HEAD) +- [Checkout multiple repos (side by side)](#Checkout-multiple-repos-side-by-side) +- [Checkout multiple repos (nested)](#Checkout-multiple-repos-nested) +- [Checkout multiple repos (private)](#Checkout-multiple-repos-private) +- [Checkout pull request HEAD commit instead of merge commit](#Checkout-pull-request-HEAD-commit-instead-of-merge-commit) +- [Checkout pull request on closed event](#Checkout-pull-request-on-closed-event) +- [Push a commit using the built-in token](#Push-a-commit-using-the-built-in-token) ## Fetch only the root files From 47dd1f74bf5f8bb2ec9d2ec67566f0b04ed1c30a Mon Sep 17 00:00:00 2001 From: Finley Garton Date: Fri, 8 Sep 2023 17:37:52 +0100 Subject: [PATCH 7/8] set to undefined rather than empty string --- dist/index.js | 5 ++++- src/input-helper.ts | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 52f21e454..ddf2b3d89 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1728,7 +1728,10 @@ function getInputs() { result.clean = (core.getInput('clean') || 'true').toUpperCase() === 'TRUE'; core.debug(`clean = ${result.clean}`); // Filter - result.filter = core.getInput('filter'); + const filter = core.getInput('filter'); + if (filter) { + result.filter = filter; + } core.debug(`filter = ${result.filter}`); // Sparse checkout const sparseCheckout = core.getMultilineInput('sparse-checkout'); diff --git a/src/input-helper.ts b/src/input-helper.ts index 6626979cf..e546c196d 100644 --- a/src/input-helper.ts +++ b/src/input-helper.ts @@ -83,7 +83,11 @@ export async function getInputs(): Promise { core.debug(`clean = ${result.clean}`) // Filter - result.filter = core.getInput('filter') + const filter = core.getInput('filter') + if (filter) { + result.filter = filter + } + core.debug(`filter = ${result.filter}`) // Sparse checkout From d8b9bab5dc3a9a66232fce6f8d4151fcaa1f73aa Mon Sep 17 00:00:00 2001 From: Finley Garton Date: Fri, 22 Sep 2023 10:48:02 +0100 Subject: [PATCH 8/8] run git config in correct di --- __test__/verify-fetch-filter.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__test__/verify-fetch-filter.sh b/__test__/verify-fetch-filter.sh index 6d021eee4..4fc9d9e38 100755 --- a/__test__/verify-fetch-filter.sh +++ b/__test__/verify-fetch-filter.sh @@ -8,7 +8,7 @@ fi # Verify .git/config contains partialclonefilter -CLONE_FILTER=$(git config --local --get remote.origin.partialclonefilter) +CLONE_FILTER=$(git -C fetch-filter config --local --get remote.origin.partialclonefilter) if [ "$CLONE_FILTER" != "blob:none" ]; then echo "Expected ./fetch-filter/.git/config to have 'remote.origin.partialclonefilter' set to 'blob:none'"