Skip to content
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 partial checkout filters #1396

Merged
merged 9 commits into from Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/test.yml
Expand Up @@ -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: ./
Expand Down
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions __test__/git-auth-helper.test.ts
Expand Up @@ -802,6 +802,7 @@ async function setup(testName: string): Promise<void> {
authToken: 'some auth token',
clean: true,
commit: '',
filter: undefined,
sparseCheckout: [],
sparseCheckoutConeMode: true,
fetchDepth: 1,
Expand Down
1 change: 1 addition & 0 deletions __test__/input-helper.test.ts
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions __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'"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you miss exit 1 here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, good spot 😳

fi
3 changes: 3 additions & 0 deletions action.yml
Expand Up @@ -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.
Expand Down
9 changes: 8 additions & 1 deletion dist/index.js
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 7 additions & 1 deletion src/git-source-provider.ts
Expand Up @@ -154,7 +154,13 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
// 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(
Expand Down
5 changes: 5 additions & 0 deletions src/git-source-settings.ts
Expand Up @@ -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
*/
Expand Down
4 changes: 4 additions & 0 deletions src/input-helper.ts
Expand Up @@ -82,6 +82,10 @@ export async function getInputs(): Promise<IGitSourceSettings> {
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) {
Expand Down