Sitelet https://github.com/actions/checkout/pull/2552/files
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,16 @@ jobs:
run: __test__/verify-sparse-checkout-non-cone-mode.sh

# LFS
# First check out without LFS so the reused worktree is left holding LFS
# pointer files; the `lfs: true` checkout below must then materialize them
# rather than leave the stale pointers in place (#270).
- name: Checkout LFS pointers (reused worktree setup)
uses: ./
with:
repository: actions/checkout # hardcoded, otherwise doesn't work from a fork
ref: test-data/v2/lfs
path: lfs
lfs: false
- name: Checkout LFS
uses: ./
with:
Expand Down
1 change: 1 addition & 0 deletions __test__/git-auth-helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,7 @@ async function setup(testName: string): Promise<void> {
getWorkingDirectory: jest.fn(() => workspace),
init: jest.fn(),
isDetached: jest.fn(),
lfsCheckout: jest.fn(),
lfsFetch: jest.fn(),
lfsInstall: jest.fn(),
log1: jest.fn(),
Expand Down
1 change: 1 addition & 0 deletions __test__/git-directory-helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ async function setup(testName: string): Promise<void> {
getWorkingDirectory: jest.fn(() => repositoryPath),
init: jest.fn(),
isDetached: jest.fn(),
lfsCheckout: jest.fn(),
lfsFetch: jest.fn(),
lfsInstall: jest.fn(),
log1: jest.fn(),
Expand Down
5 changes: 5 additions & 0 deletions __test__/verify-lfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ if [ ! -f "./lfs/lfs-file.bin" ]; then
echo "Expected lfs file does not exist"
exit 1
fi

if head -n 1 "./lfs/lfs-file.bin" | grep -q "git-lfs.github.com/spec"; then
echo "Expected lfs file to be materialized, but it is still an LFS pointer"
exit 1
fi
13 changes: 13 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35816,6 +35816,9 @@ class GitCommandManager {
const output = await this.execGit(['rev-parse', '--symbolic-full-name', '--verify', '--quiet', 'HEAD'], true);
return !output.stdout.trim().startsWith('refs/heads/');
}
async lfsCheckout() {
await this.execGit(['lfs', 'checkout']);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

In case the input parameter submodules is true or recursive, I would expect that also the LFS files of the submodules are checked out. Maybe we should also add a command like:

git submodule foreach [--recursive] git lfs checkout

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

makes sense, added a git.submoduleForeach

}
async lfsFetch(ref) {
const args = ['lfs', 'fetch', 'origin', ref];
const that = this;
Expand Down Expand Up @@ -41879,6 +41882,11 @@ async function getSource(settings) {
startGroup('Checking out the ref');
await git.checkout(checkoutInfo.ref, checkoutInfo.startPoint);
endGroup();
if (settings.lfs && !settings.sparseCheckout) {
startGroup('Checking out LFS objects');
await git.lfsCheckout();
endGroup();
}
// Submodules
if (settings.submodules) {
// Temporarily override global config
Expand All @@ -41891,6 +41899,11 @@ async function getSource(settings) {
await git.submoduleUpdate(settings.fetchDepth, settings.nestedSubmodules);
await git.submoduleForeach('git config --local gc.auto 0', settings.nestedSubmodules);
endGroup();
if (settings.lfs) {
startGroup('Checking out submodule LFS objects');
await git.submoduleForeach('git lfs checkout', settings.nestedSubmodules);
endGroup();
}
// Persist credentials
if (settings.persistCredentials) {
startGroup('Persisting credentials for submodules');
Expand Down
5 changes: 5 additions & 0 deletions src/git-command-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface IGitCommandManager {
getWorkingDirectory(): string
init(objectFormat?: string): Promise<void>
isDetached(): Promise<boolean>
lfsCheckout(): Promise<void>
lfsFetch(ref: string): Promise<void>
lfsInstall(): Promise<void>
log1(format?: string): Promise<string>
Expand Down Expand Up @@ -383,6 +384,10 @@ class GitCommandManager {
return !output.stdout.trim().startsWith('refs/heads/')
}

async lfsCheckout(): Promise<void> {
await this.execGit(['lfs', 'checkout'])
}

async lfsFetch(ref: string): Promise<void> {
const args = ['lfs', 'fetch', 'origin', ref]

Expand Down
15 changes: 15 additions & 0 deletions src/git-source-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,12 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
await git.checkout(checkoutInfo.ref, checkoutInfo.startPoint)
core.endGroup()

if (settings.lfs && !settings.sparseCheckout) {
core.startGroup('Checking out LFS objects')
await git.lfsCheckout()
core.endGroup()
}

// Submodules
if (settings.submodules) {
// Temporarily override global config
Expand All @@ -288,6 +294,15 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
)
core.endGroup()

if (settings.lfs) {
core.startGroup('Checking out submodule LFS objects')
await git.submoduleForeach(
'git lfs checkout',
settings.nestedSubmodules
)
core.endGroup()
}

// Persist credentials
if (settings.persistCredentials) {
core.startGroup('Persisting credentials for submodules')
Expand Down