1
0
Fork 0
mirror of https://code.forgejo.org/actions/checkout.git synced 2025-07-05 16:38:05 +02:00

Add objectFormat setting to allow init()ing a repo with sha256

This commit is contained in:
Yang Zhao 2024-08-23 00:23:06 -07:00
parent eef61447b9
commit 68a03db899
8 changed files with 120 additions and 39 deletions

View file

@ -42,7 +42,7 @@ export interface IGitCommandManager {
): Promise<void>
getDefaultBranch(repositoryUrl: string): Promise<string>
getWorkingDirectory(): string
init(): Promise<void>
init(options?: { objectFormat?: string }): Promise<void>
isDetached(): Promise<boolean>
lfsFetch(ref: string): Promise<void>
lfsInstall(): Promise<void>
@ -327,8 +327,12 @@ class GitCommandManager {
return this.workingDirectory
}
async init(): Promise<void> {
await this.execGit(['init', this.workingDirectory])
async init(options?: { objectFormat?: string }): Promise<void> {
await this.execGit([
'init',
...(options?.objectFormat ? [`--object-format=${options.objectFormat}`] : []),
this.workingDirectory
])
}
async isDetached(): Promise<boolean> {

View file

@ -110,7 +110,7 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
!fsHelper.directoryExistsSync(path.join(settings.repositoryPath, '.git'))
) {
core.startGroup('Initializing the repository')
await git.init()
await git.init({ objectFormat: settings.objectFormat })
await git.remoteAdd('origin', repositoryUrl)
core.endGroup()
}

View file

@ -118,4 +118,9 @@ export interface IGitSourceSettings {
* User override on the GitHub Server/Host URL that hosts the repository to be cloned
*/
githubServerUrl: string | undefined
/**
* Object format used for the repo, if it is not default
*/
objectFormat: 'sha1' | 'sha256' | undefined
}

View file

@ -161,5 +161,14 @@ export async function getInputs(): Promise<IGitSourceSettings> {
result.githubServerUrl = core.getInput('github-server-url')
core.debug(`GitHub Host URL = ${result.githubServerUrl}`)
// Object format
const objectFormat = core.getInput('object-format')
if (objectFormat) {
if (objectFormat != 'sha1' && objectFormat != 'sha256') {
throw Error(`Invalid object format '${objectFormat}'`)
}
result.objectFormat = objectFormat
}
return result
}