Skip to content

Commit 488933c

Browse files
committed
Add support for SHA256 repositories
New input parameter to specify the git object format when initializing a git repository.
1 parent 85e6279 commit 488933c

8 files changed

+37
-8
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ Please refer to the [release page](https://github.com/actions/checkout/releases/
126126
# running from unless specified. Example URLs are https://github.com or
127127
# https://my-ghes-server.example.com
128128
github-server-url: ''
129+
130+
# Specify the Git object format for repository initialization (sha1, sha256).
131+
object-format: ''
129132
```
130133
<!-- end usage -->
131134

__test__/git-auth-helper.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,8 @@ async function setup(testName: string): Promise<void> {
824824
sshUser: '',
825825
workflowOrganizationId: 123456,
826826
setSafeDirectory: true,
827-
githubServerUrl: githubServerUrl
827+
githubServerUrl: githubServerUrl,
828+
objectFormat: undefined
828829
}
829830
}
830831

action.yml

+3
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ inputs:
9898
github-server-url:
9999
description: The base URL for the GitHub instance that you are trying to clone from, will use environment defaults to fetch from the same instance that the workflow is running from unless specified. Example URLs are https://github.com or https://my-ghes-server.example.com
100100
required: false
101+
object-format:
102+
description: 'Specify the Git object format for repository initialization (sha1, sha256).'
103+
required: false
101104
outputs:
102105
ref:
103106
description: 'The branch, tag or SHA that was checked out'

dist/index.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -709,9 +709,14 @@ class GitCommandManager {
709709
getWorkingDirectory() {
710710
return this.workingDirectory;
711711
}
712-
init() {
712+
init(objectFormat) {
713713
return __awaiter(this, void 0, void 0, function* () {
714-
yield this.execGit(['init', this.workingDirectory]);
714+
const args = ['init'];
715+
if (objectFormat) {
716+
args.push(`--object-format=${objectFormat}`);
717+
}
718+
args.push(this.workingDirectory);
719+
yield this.execGit(args);
715720
});
716721
}
717722
isDetached() {
@@ -1236,7 +1241,7 @@ function getSource(settings) {
12361241
// Initialize the repository
12371242
if (!fsHelper.directoryExistsSync(path.join(settings.repositoryPath, '.git'))) {
12381243
core.startGroup('Initializing the repository');
1239-
yield git.init();
1244+
yield git.init(settings.objectFormat);
12401245
yield git.remoteAdd('origin', repositoryUrl);
12411246
core.endGroup();
12421247
}
@@ -1831,6 +1836,9 @@ function getInputs() {
18311836
// Determine the GitHub URL that the repository is being hosted from
18321837
result.githubServerUrl = core.getInput('github-server-url');
18331838
core.debug(`GitHub Host URL = ${result.githubServerUrl}`);
1839+
// Retrieve the Git object format for initializing a Git repository.
1840+
result.objectFormat = core.getInput('object-format');
1841+
core.debug(`git object format = ${result.objectFormat}`);
18341842
return result;
18351843
});
18361844
}

src/git-command-manager.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export interface IGitCommandManager {
4242
): Promise<void>
4343
getDefaultBranch(repositoryUrl: string): Promise<string>
4444
getWorkingDirectory(): string
45-
init(): Promise<void>
45+
init(objectFormat?: string): Promise<void>
4646
isDetached(): Promise<boolean>
4747
lfsFetch(ref: string): Promise<void>
4848
lfsInstall(): Promise<void>
@@ -327,8 +327,13 @@ class GitCommandManager {
327327
return this.workingDirectory
328328
}
329329

330-
async init(): Promise<void> {
331-
await this.execGit(['init', this.workingDirectory])
330+
async init(objectFormat?: string): Promise<void> {
331+
const args = ['init']
332+
if (objectFormat) {
333+
args.push(`--object-format=${objectFormat}`)
334+
}
335+
args.push(this.workingDirectory)
336+
await this.execGit(args)
332337
}
333338

334339
async isDetached(): Promise<boolean> {

src/git-source-provider.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
110110
!fsHelper.directoryExistsSync(path.join(settings.repositoryPath, '.git'))
111111
) {
112112
core.startGroup('Initializing the repository')
113-
await git.init()
113+
await git.init(settings.objectFormat)
114114
await git.remoteAdd('origin', repositoryUrl)
115115
core.endGroup()
116116
}

src/git-source-settings.ts

+5
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,9 @@ export interface IGitSourceSettings {
118118
* User override on the GitHub Server/Host URL that hosts the repository to be cloned
119119
*/
120120
githubServerUrl: string | undefined
121+
122+
/**
123+
* Specify the Git object format for repository initialization (sha1, sha256).
124+
*/
125+
objectFormat: string | undefined
121126
}

src/input-helper.ts

+4
Original file line numberDiff line numberDiff line change
@@ -161,5 +161,9 @@ export async function getInputs(): Promise<IGitSourceSettings> {
161161
result.githubServerUrl = core.getInput('github-server-url')
162162
core.debug(`GitHub Host URL = ${result.githubServerUrl}`)
163163

164+
// Retrieve the Git object format for initializing a Git repository.
165+
result.objectFormat = core.getInput('object-format')
166+
core.debug(`git object format = ${result.objectFormat}`)
167+
164168
return result
165169
}

0 commit comments

Comments
 (0)