mirror of
https://github.com/actions/checkout.git
synced 2026-05-23 10:05:53 +00:00
Fix checkout init for SHA-256 repositories
This commit is contained in:
parent
900f2210b1
commit
f279b42429
8 changed files with 489 additions and 7 deletions
94
dist/index.js
vendored
94
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,20 @@ function getSource(settings) {
|
|||
stateHelper.setRepositoryPath(settings.repositoryPath);
|
||||
// Initialize the repository
|
||||
if (!fsHelper.directoryExistsSync(path.join(settings.repositoryPath, '.git'))) {
|
||||
core.startGroup('Determining repository object format');
|
||||
let objectFormatResult = yield githubApiHelper.tryGetRepositoryObjectFormat(settings.authToken, settings.repositoryOwner, settings.repositoryName, settings.githubServerUrl);
|
||||
if (!objectFormatResult.succeeded) {
|
||||
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();
|
||||
}
|
||||
|
|
@ -1810,6 +1866,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.downloadRepository = downloadRepository;
|
||||
exports.getDefaultBranch = getDefaultBranch;
|
||||
exports.tryGetRepositoryObjectFormat = tryGetRepositoryObjectFormat;
|
||||
const assert = __importStar(__nccwpck_require__(9491));
|
||||
const core = __importStar(__nccwpck_require__(2186));
|
||||
const fs = __importStar(__nccwpck_require__(7147));
|
||||
|
|
@ -1911,6 +1968,37 @@ function getDefaultBranch(authToken, owner, repo, baseUrl) {
|
|||
}));
|
||||
});
|
||||
}
|
||||
function tryGetRepositoryObjectFormat(authToken, owner, repo, baseUrl) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
var _a;
|
||||
try {
|
||||
const octokit = github.getOctokit(authToken, {
|
||||
baseUrl: (0, url_helper_1.getServerApiUrl)(baseUrl)
|
||||
});
|
||||
const repository = yield octokit.rest.repos.get({ owner, repo });
|
||||
const defaultBranch = repository.data.default_branch;
|
||||
assert.ok(defaultBranch, 'default_branch cannot be empty');
|
||||
const branch = yield octokit.rest.repos.getBranch({
|
||||
owner,
|
||||
repo,
|
||||
branch: defaultBranch
|
||||
});
|
||||
const commitSha = branch.data.commit.sha;
|
||||
if (/^[0-9a-fA-F]{64}$/.test(commitSha)) {
|
||||
return { format: 'sha256', succeeded: true };
|
||||
}
|
||||
if (/^[0-9a-fA-F]{40}$/.test(commitSha)) {
|
||||
return { format: 'sha1', succeeded: true };
|
||||
}
|
||||
core.debug('Unable to determine repository object format from default branch');
|
||||
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 };
|
||||
}
|
||||
});
|
||||
}
|
||||
function downloadArchive(authToken, owner, repo, ref, commit, baseUrl) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const octokit = github.getOctokit(authToken, {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue