mirror of
https://github.com/actions/checkout.git
synced 2024-11-12 11:18:05 +00:00
Merge 6b8be4cb30
into 6d193bf280
This commit is contained in:
commit
2184657e51
@ -29,6 +29,11 @@ Please refer to the [release page](https://github.com/actions/checkout/releases/
|
||||
# Otherwise, uses the default branch.
|
||||
ref: ''
|
||||
|
||||
# Indicates whether to checkout the default repository branch if the requested ref
|
||||
# does not exist
|
||||
# Default: false
|
||||
default-branch-checkout: ''
|
||||
|
||||
# Personal access token (PAT) used to fetch the repository. The PAT is configured
|
||||
# with the local git config, which enables your scripts to run authenticated git
|
||||
# commands. The post-job step removes the PAT.
|
||||
|
@ -815,6 +815,7 @@ async function setup(testName: string): Promise<void> {
|
||||
nestedSubmodules: false,
|
||||
persistCredentials: true,
|
||||
ref: 'refs/heads/main',
|
||||
defaultBranchCheckout: false,
|
||||
repositoryName: 'my-repo',
|
||||
repositoryOwner: 'my-org',
|
||||
repositoryPath: '',
|
||||
|
@ -80,6 +80,7 @@ describe('input-helper tests', () => {
|
||||
expect(settings.commit).toBeTruthy()
|
||||
expect(settings.commit).toBe('1234567890123456789012345678901234567890')
|
||||
expect(settings.filter).toBe(undefined)
|
||||
expect(settings.defaultBranchCheckout).toBe(false)
|
||||
expect(settings.sparseCheckout).toBe(undefined)
|
||||
expect(settings.sparseCheckoutConeMode).toBe(true)
|
||||
expect(settings.fetchDepth).toBe(1)
|
||||
|
@ -9,6 +9,9 @@ inputs:
|
||||
The branch, tag or SHA to checkout. When checking out the repository that
|
||||
triggered a workflow, this defaults to the reference or SHA for that
|
||||
event. Otherwise, uses the default branch.
|
||||
default-branch-checkout:
|
||||
description: 'Indicates whether to checkout the default repository branch if the requested ref does not exist'
|
||||
default: false
|
||||
token:
|
||||
description: >
|
||||
Personal access token (PAT) used to fetch the repository. The PAT is configured
|
||||
|
24
dist/index.js
vendored
24
dist/index.js
vendored
@ -1278,7 +1278,7 @@ function getSource(settings) {
|
||||
else if (settings.sparseCheckout) {
|
||||
fetchOptions.filter = 'blob:none';
|
||||
}
|
||||
if (settings.fetchDepth <= 0) {
|
||||
if (settings.fetchDepth <= 0 || settings.defaultBranchCheckout) {
|
||||
// Fetch all branches and tags
|
||||
let refSpec = refHelper.getRefSpecForAllHistory(settings.ref, settings.commit);
|
||||
yield git.fetch(refSpec, fetchOptions);
|
||||
@ -1298,7 +1298,22 @@ function getSource(settings) {
|
||||
core.endGroup();
|
||||
// Checkout info
|
||||
core.startGroup('Determining the checkout info');
|
||||
const checkoutInfo = yield refHelper.getCheckoutInfo(git, settings.ref, settings.commit);
|
||||
let checkoutInfo;
|
||||
try {
|
||||
checkoutInfo = yield refHelper.getCheckoutInfo(git, settings.ref, settings.commit);
|
||||
}
|
||||
catch (error) {
|
||||
if (settings.defaultBranchCheckout) {
|
||||
core.info('Could not determine the checkout info. Trying the default repository branch');
|
||||
const repositoryDefaultBranch = settings.sshKey
|
||||
? yield git.getDefaultBranch(repositoryUrl)
|
||||
: yield githubApiHelper.getDefaultBranch(settings.authToken, settings.repositoryOwner, settings.repositoryName);
|
||||
checkoutInfo = yield refHelper.getCheckoutInfo(git, repositoryDefaultBranch, settings.commit);
|
||||
}
|
||||
else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
core.endGroup();
|
||||
// LFS fetch
|
||||
// Explicit lfs-fetch to avoid slow checkout (fetches one lfs object at a time).
|
||||
@ -1763,6 +1778,11 @@ function getInputs() {
|
||||
}
|
||||
core.debug(`ref = '${result.ref}'`);
|
||||
core.debug(`commit = '${result.commit}'`);
|
||||
// Default branch checkout
|
||||
result.defaultBranchCheckout =
|
||||
(core.getInput('default-branch-checkout') || 'false').toUpperCase() ===
|
||||
'TRUE';
|
||||
core.debug(`default-branch-checkout = '${result.defaultBranchCheckout}'`);
|
||||
// Clean
|
||||
result.clean = (core.getInput('clean') || 'true').toUpperCase() === 'TRUE';
|
||||
core.debug(`clean = ${result.clean}`);
|
||||
|
@ -169,7 +169,7 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
|
||||
fetchOptions.filter = 'blob:none'
|
||||
}
|
||||
|
||||
if (settings.fetchDepth <= 0) {
|
||||
if (settings.fetchDepth <= 0 || settings.defaultBranchCheckout) {
|
||||
// Fetch all branches and tags
|
||||
let refSpec = refHelper.getRefSpecForAllHistory(
|
||||
settings.ref,
|
||||
@ -193,11 +193,34 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
|
||||
|
||||
// Checkout info
|
||||
core.startGroup('Determining the checkout info')
|
||||
const checkoutInfo = await refHelper.getCheckoutInfo(
|
||||
git,
|
||||
settings.ref,
|
||||
settings.commit
|
||||
)
|
||||
let checkoutInfo: refHelper.ICheckoutInfo
|
||||
try {
|
||||
checkoutInfo = await refHelper.getCheckoutInfo(
|
||||
git,
|
||||
settings.ref,
|
||||
settings.commit
|
||||
)
|
||||
} catch (error) {
|
||||
if (settings.defaultBranchCheckout) {
|
||||
core.info(
|
||||
'Could not determine the checkout info. Trying the default repository branch'
|
||||
)
|
||||
const repositoryDefaultBranch = settings.sshKey
|
||||
? await git.getDefaultBranch(repositoryUrl)
|
||||
: await githubApiHelper.getDefaultBranch(
|
||||
settings.authToken,
|
||||
settings.repositoryOwner,
|
||||
settings.repositoryName
|
||||
)
|
||||
checkoutInfo = await refHelper.getCheckoutInfo(
|
||||
git,
|
||||
repositoryDefaultBranch,
|
||||
settings.commit
|
||||
)
|
||||
} else {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
core.endGroup()
|
||||
|
||||
// LFS fetch
|
||||
|
@ -19,6 +19,11 @@ export interface IGitSourceSettings {
|
||||
*/
|
||||
ref: string
|
||||
|
||||
/**
|
||||
* Indicates whether to checkout the default repository branch if the requested ref does not exist
|
||||
*/
|
||||
defaultBranchCheckout: boolean
|
||||
|
||||
/**
|
||||
* The commit to checkout
|
||||
*/
|
||||
|
@ -78,6 +78,12 @@ export async function getInputs(): Promise<IGitSourceSettings> {
|
||||
core.debug(`ref = '${result.ref}'`)
|
||||
core.debug(`commit = '${result.commit}'`)
|
||||
|
||||
// Default branch checkout
|
||||
result.defaultBranchCheckout =
|
||||
(core.getInput('default-branch-checkout') || 'false').toUpperCase() ===
|
||||
'TRUE'
|
||||
core.debug(`default-branch-checkout = '${result.defaultBranchCheckout}'`)
|
||||
|
||||
// Clean
|
||||
result.clean = (core.getInput('clean') || 'true').toUpperCase() === 'TRUE'
|
||||
core.debug(`clean = ${result.clean}`)
|
||||
|
Loading…
Reference in New Issue
Block a user