From 122cf7516b482d0520b90117992aa3034d9890f6 Mon Sep 17 00:00:00 2001 From: lucasew Date: Fri, 21 Nov 2025 08:48:08 -0300 Subject: [PATCH] fix: double auth with checkout v6 Signed-off-by: lucasew --- dist/index.js | 11 +++++++++++ src/git-command-manager.ts | 2 ++ src/git-config-helper.ts | 21 +++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/dist/index.js b/dist/index.js index 75ae3c2f..c5d33bc4 100644 --- a/dist/index.js +++ b/dist/index.js @@ -738,6 +738,7 @@ class GitCommandManager { const output = yield this.exec([ 'config', globalConfig ? '--global' : '--local', + '--includes', // Detect configs from included files (e.g., checkout@v6) '--name-only', '--get-regexp', configKey, @@ -820,6 +821,7 @@ class GitCommandManager { const output = yield this.exec([ 'config', '--local', + '--includes', // Get configs from included files (e.g., checkout@v6) '--get-regexp', configKey, configValue @@ -1205,6 +1207,15 @@ class GitConfigHelper { const basicCredential = Buffer.from(`x-access-token:${token}`, 'utf8').toString('base64'); core.setSecret(basicCredential); const extraheaderConfigValue = `AUTHORIZATION: basic ${basicCredential}`; + // Check if the same token is already configured (e.g., by checkout@v6) + // If so, skip reconfiguration to avoid duplicate headers + if (yield this.git.configExists(this.extraheaderConfigKey, this.extraheaderConfigValueRegex)) { + const existingValue = yield this.git.getConfigValue(this.extraheaderConfigKey, this.extraheaderConfigValueRegex); + if (existingValue === extraheaderConfigValue) { + core.info('Git credentials already configured with the same token, skipping reconfiguration'); + return; + } + } yield this.setExtraheaderConfig(extraheaderConfigValue); }); } diff --git a/src/git-command-manager.ts b/src/git-command-manager.ts index 6270f193..61c1df5e 100644 --- a/src/git-command-manager.ts +++ b/src/git-command-manager.ts @@ -115,6 +115,7 @@ export class GitCommandManager { [ 'config', globalConfig ? '--global' : '--local', + '--includes', // Detect configs from included files (e.g., checkout@v6) '--name-only', '--get-regexp', configKey, @@ -212,6 +213,7 @@ export class GitCommandManager { const output = await this.exec([ 'config', '--local', + '--includes', // Get configs from included files (e.g., checkout@v6) '--get-regexp', configKey, configValue diff --git a/src/git-config-helper.ts b/src/git-config-helper.ts index f5f484b8..ce5159c3 100644 --- a/src/git-config-helper.ts +++ b/src/git-config-helper.ts @@ -144,6 +144,27 @@ export class GitConfigHelper { ).toString('base64') core.setSecret(basicCredential) const extraheaderConfigValue = `AUTHORIZATION: basic ${basicCredential}` + + // Check if the same token is already configured (e.g., by checkout@v6) + // If so, skip reconfiguration to avoid duplicate headers + if ( + await this.git.configExists( + this.extraheaderConfigKey, + this.extraheaderConfigValueRegex + ) + ) { + const existingValue = await this.git.getConfigValue( + this.extraheaderConfigKey, + this.extraheaderConfigValueRegex + ) + if (existingValue === extraheaderConfigValue) { + core.info( + 'Git credentials already configured with the same token, skipping reconfiguration' + ) + return + } + } + await this.setExtraheaderConfig(extraheaderConfigValue) }