mirror of
https://data.forgejo.org/actions/checkout
synced 2026-08-15 00:46:04 +00:00
Fix checkout init for SHA-256 repositories
This commit is contained in:
parent
900f2210b1
commit
fe86d6d213
6 changed files with 296 additions and 7 deletions
59
dist/index.js
vendored
59
dist/index.js
vendored
|
|
@ -896,9 +896,14 @@ class GitCommandManager {
|
|||
getWorkingDirectory() {
|
||||
return this.workingDirectory;
|
||||
}
|
||||
init() {
|
||||
init(objectFormat) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
yield this.execGit(['init', this.workingDirectory]);
|
||||
const args = ['init'];
|
||||
if (objectFormat === 'sha256') {
|
||||
args.push('--object-format=sha256');
|
||||
}
|
||||
args.push(this.workingDirectory);
|
||||
yield this.execGit(args);
|
||||
});
|
||||
}
|
||||
isDetached() {
|
||||
|
|
@ -1056,6 +1061,45 @@ class GitCommandManager {
|
|||
return stdout;
|
||||
});
|
||||
}
|
||||
tryGetObjectFormat(repositoryUrl) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
var _a;
|
||||
try {
|
||||
const output = yield this.execGit([
|
||||
'-c',
|
||||
'protocol.version=2',
|
||||
'ls-remote',
|
||||
'--quiet',
|
||||
'--exit-code',
|
||||
'--symref',
|
||||
repositoryUrl,
|
||||
'HEAD'
|
||||
], true, true);
|
||||
if (output.exitCode !== 0) {
|
||||
core.debug(`Unable to determine repository object format: git ls-remote exited with ${output.exitCode}`);
|
||||
return { format: '', succeeded: false };
|
||||
}
|
||||
for (const line of output.stdout.trim().split('\n')) {
|
||||
const [oid, ref] = line.split('\t');
|
||||
if (ref !== 'HEAD') {
|
||||
continue;
|
||||
}
|
||||
if (/^[0-9a-fA-F]{64}$/.test(oid)) {
|
||||
return { format: 'sha256', succeeded: true };
|
||||
}
|
||||
if (/^[0-9a-fA-F]{40}$/.test(oid)) {
|
||||
return { format: 'sha1', succeeded: true };
|
||||
}
|
||||
}
|
||||
core.debug('Unable to determine repository object format from HEAD');
|
||||
return { format: '', succeeded: false };
|
||||
}
|
||||
catch (err) {
|
||||
core.debug(`Unable to determine repository object format: ${(_a = err === null || err === void 0 ? void 0 : err.message) !== null && _a !== void 0 ? _a : err}`);
|
||||
return { format: '', succeeded: false };
|
||||
}
|
||||
});
|
||||
}
|
||||
tryGetConfigValues(configKey, globalConfig, configFile) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const args = ['config'];
|
||||
|
|
@ -1486,8 +1530,17 @@ function getSource(settings) {
|
|||
stateHelper.setRepositoryPath(settings.repositoryPath);
|
||||
// Initialize the repository
|
||||
if (!fsHelper.directoryExistsSync(path.join(settings.repositoryPath, '.git'))) {
|
||||
core.startGroup('Determining repository object format');
|
||||
const objectFormatResult = yield git.tryGetObjectFormat(repositoryUrl);
|
||||
const objectFormat = objectFormatResult.succeeded
|
||||
? objectFormatResult.format
|
||||
: '';
|
||||
if (objectFormat === 'sha256') {
|
||||
core.info('Detected SHA-256 repository object format');
|
||||
}
|
||||
core.endGroup();
|
||||
core.startGroup('Initializing the repository');
|
||||
yield git.init();
|
||||
yield git.init(objectFormat);
|
||||
yield git.remoteAdd('origin', repositoryUrl);
|
||||
core.endGroup();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue