mirror of
https://code.forgejo.org/actions/checkout.git
synced 2025-04-24 12:25:34 +00:00
Default branch checkout option
This commit is contained in:
parent
e72243fb91
commit
5bbdf118df
5 changed files with 48 additions and 77 deletions
45
dist/index.js
vendored
45
dist/index.js
vendored
|
@ -1226,17 +1226,6 @@ function getSource(settings) {
|
|||
core.startGroup('Setting up auth');
|
||||
yield authHelper.configureAuth();
|
||||
core.endGroup();
|
||||
if (settings.defaultRefOnError && settings.defaultRefOnError === true) {
|
||||
// Configure default branch
|
||||
core.startGroup('Setting up default branch');
|
||||
if (settings.sshKey) {
|
||||
settings.defaultBranch = yield git.getDefaultBranch(repositoryUrl);
|
||||
}
|
||||
else {
|
||||
settings.defaultBranch = yield githubApiHelper.getDefaultBranch(settings.authToken, settings.repositoryOwner, settings.repositoryName);
|
||||
}
|
||||
core.endGroup();
|
||||
}
|
||||
// Determine the default branch
|
||||
if (!settings.ref && !settings.commit) {
|
||||
core.startGroup('Determining the default branch');
|
||||
|
@ -1261,8 +1250,7 @@ function getSource(settings) {
|
|||
else if (settings.sparseCheckout) {
|
||||
fetchOptions.filter = 'blob:none';
|
||||
}
|
||||
if (settings.fetchDepth <= 0 ||
|
||||
(settings.defaultRefOnError && settings.defaultRefOnError === true)) {
|
||||
if (settings.fetchDepth <= 0 || settings.defaultBranchCheckout) {
|
||||
// Fetch all branches and tags
|
||||
let refSpec = refHelper.getRefSpecForAllHistory(settings.ref, settings.commit);
|
||||
yield git.fetch(refSpec, fetchOptions);
|
||||
|
@ -1283,18 +1271,21 @@ function getSource(settings) {
|
|||
// Checkout info
|
||||
core.startGroup('Determining the checkout info');
|
||||
let checkoutInfo;
|
||||
if (settings.defaultRefOnError && settings.defaultRefOnError === true) {
|
||||
try {
|
||||
checkoutInfo = yield refHelper.getCheckoutInfo(git, settings.ref, settings.commit);
|
||||
}
|
||||
catch (error) {
|
||||
core.info('Could not determine the checkout info. Trying the default repo branch');
|
||||
checkoutInfo = yield refHelper.getCheckoutInfo(git, settings.defaultBranch, settings.commit);
|
||||
}
|
||||
}
|
||||
else {
|
||||
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).
|
||||
|
@ -1748,10 +1739,10 @@ function getInputs() {
|
|||
}
|
||||
core.debug(`ref = '${result.ref}'`);
|
||||
core.debug(`commit = '${result.commit}'`);
|
||||
// Default ref on error
|
||||
result.defaultRefOnError =
|
||||
(core.getInput('default-ref-on-error') || 'true').toUpperCase() === 'TRUE';
|
||||
core.debug(`default-ref-on-error = '${result.defaultRefOnError}'`);
|
||||
// Default branch checkout
|
||||
result.defaultBranchCheckout =
|
||||
(core.getInput('default-branch-checkout') || 'true').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