1
0
Fork 0
mirror of https://code.forgejo.org/actions/checkout.git synced 2026-03-09 14:35:48 +00:00

feat: override fetch-depth to 0 when reference-cache is active

When reference-cache is enabled, shallow fetches (fetch-depth > 0) are
counterproductive because objects are served from the local cache.
Shallow negotiation only adds network latency without saving bandwidth.

If fetch-depth was not explicitly set by the user, it is automatically
overridden to 0. If explicitly set, a warning is emitted explaining
the performance impact.

Signed-off-by: Michael Wyraz <mw@brick4u.de>
This commit is contained in:
Michael Wyraz 2026-03-05 15:54:36 +01:00
parent 9ddd3f4b35
commit ed69f3bbdd
6 changed files with 153 additions and 2 deletions

26
dist/index.js vendored
View file

@ -1581,6 +1581,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getSource = getSource;
exports.cleanup = cleanup;
exports.adjustFetchDepthForCache = adjustFetchDepthForCache;
const core = __importStar(__nccwpck_require__(2186));
const fsHelper = __importStar(__nccwpck_require__(7219));
const gitAuthHelper = __importStar(__nccwpck_require__(2565));
@ -1841,6 +1842,9 @@ function getSource(settings) {
if (settings.lfs) {
yield git.lfsInstall();
}
// When using reference cache, fetch-depth > 0 is counterproductive:
// objects are served from the local cache, so shallow negotiation only adds latency.
adjustFetchDepthForCache(settings);
// Fetch
core.startGroup('Fetching the repository');
const fetchOptions = {};
@ -2014,6 +2018,24 @@ function getGitCommandManager(settings) {
}
});
}
/**
* Adjusts fetchDepth when reference-cache is active.
* Shallow fetches are counterproductive with a local cache because
* objects are served from disk, making shallow negotiation pure overhead.
*/
function adjustFetchDepthForCache(settings) {
if (settings.referenceCache && settings.fetchDepth > 0) {
if (settings.fetchDepthExplicit) {
core.warning(`'fetch-depth: ${settings.fetchDepth}' is set with reference-cache enabled. ` +
`This may slow down checkout because shallow negotiation bypasses the local cache. ` +
`Consider using 'fetch-depth: 0' for best performance with reference-cache.`);
}
else {
core.info(`Overriding fetch-depth from ${settings.fetchDepth} to 0 because reference-cache is enabled`);
settings.fetchDepth = 0;
}
}
}
/***/ }),
@ -2374,7 +2396,9 @@ function getInputs() {
(core.getInput('sparse-checkout-cone-mode') || 'true').toUpperCase() ===
'TRUE';
// Fetch depth
result.fetchDepth = Math.floor(Number(core.getInput('fetch-depth') || '1'));
const fetchDepthInput = core.getInput('fetch-depth');
result.fetchDepthExplicit = fetchDepthInput !== '';
result.fetchDepth = Math.floor(Number(fetchDepthInput || '1'));
if (isNaN(result.fetchDepth) || result.fetchDepth < 0) {
result.fetchDepth = 0;
}