fix: issue with failing checkout

This commit is contained in:
James Ives
2025-12-09 14:53:25 -05:00
parent 83e989fe86
commit 8cd0b7f619
3 changed files with 11 additions and 8 deletions

View File

@@ -54,7 +54,7 @@ describe('git', () => {
})
await init(action)
expect(execute).toHaveBeenCalledTimes(9)
expect(execute).toHaveBeenCalledTimes(10)
})
it('should catch when a function throws an error', async () => {
@@ -101,7 +101,7 @@ describe('git', () => {
})
await init(action)
expect(execute).toHaveBeenCalledTimes(9)
expect(execute).toHaveBeenCalledTimes(10)
})
it('should not unset git config if a user is using ssh', async () => {
@@ -144,7 +144,7 @@ describe('git', () => {
})
await init(action)
expect(execute).toHaveBeenCalledTimes(9)
expect(execute).toHaveBeenCalledTimes(10)
})
it('should remove includeIf git config sections when present', async () => {
@@ -168,6 +168,7 @@ describe('git', () => {
})
.mockImplementationOnce(() => ({stdout: '', stderr: ''})) // remove-section includeIf --local
.mockImplementationOnce(() => ({stdout: '', stderr: ''})) // git config --global --get-regexp includeIf
.mockImplementationOnce(() => ({stdout: '', stderr: ''})) // git config --system --get-regexp includeIf
.mockImplementationOnce(() => ({stdout: '', stderr: ''})) // git remote rm
.mockImplementationOnce(() => ({stdout: '', stderr: ''})) // git remote add

View File

@@ -53,7 +53,7 @@ describe('main', () => {
debug: true
})
await run(action)
expect(execute).toHaveBeenCalledTimes(21)
expect(execute).toHaveBeenCalledTimes(22)
expect(rmRF).toHaveBeenCalledTimes(1)
expect(exportVariable).toHaveBeenCalledTimes(1)
})
@@ -73,7 +73,7 @@ describe('main', () => {
isTest: TestFlag.HAS_CHANGED_FILES
})
await run(action)
expect(execute).toHaveBeenCalledTimes(24)
expect(execute).toHaveBeenCalledTimes(25)
expect(rmRF).toHaveBeenCalledTimes(1)
expect(exportVariable).toHaveBeenCalledTimes(1)
})

View File

@@ -78,12 +78,14 @@ export async function init(action: ActionInterface): Promise<void | Error> {
// Remove includeIf directives that point to credential files (actions/checkout@v6+)
try {
if ((process.env.CI && !action.sshKey) || action.isTest) {
// Always try to remove includeIf credentials when not using SSH key
// This is necessary because actions/checkout@v6+ uses includeIf to inject credentials
if (!action.sshKey || action.isTest) {
/* actions/checkout@v6+ uses includeIf directives to inject credentials.
We need to remove these to ensure the provided token/SSH key is used instead.
Check both local and global scopes as containers may configure differently.
Check local, global, and system scopes as containers may configure differently.
*/
for (const scope of ['--local', '--global']) {
for (const scope of ['--local', '--global', '--system']) {
try {
const includeIfResult = await execute(
`git config ${scope} --get-regexp 'includeIf\\..*\\.path'`,