This commit is contained in:
Alexander Cranga 2024-11-14 08:40:48 -08:00 committed by GitHub
commit 3cced7db06
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 72 additions and 8 deletions

View file

@ -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

View file

@ -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
*/

View file

@ -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}`)