mirror of
https://code.forgejo.org/actions/checkout.git
synced 2025-07-03 11:53:49 +03:00
Merge 6b8be4cb30
into cbb722410c
This commit is contained in:
commit
3cced7db06
8 changed files with 72 additions and 8 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue