Skip to content

Commit 0ee4f2e

Browse files
committed
Update git.ts
1 parent bd9332d commit 0ee4f2e

1 file changed

Lines changed: 91 additions & 0 deletions

File tree

src/git.ts

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ export async function init(action: ActionInterface): Promise<void | Error> {
2424
info(`Deploying using ${action.tokenType}… 🔑`)
2525
info('Configuring git…')
2626

27+
// Clear any GIT_CONFIG environment variables that might contain credentials
28+
// These can be set by actions/checkout and persist in the environment
29+
if (process.env.GIT_CONFIG_COUNT) {
30+
info('Clearing GIT_CONFIG environment variables...')
31+
delete process.env.GIT_CONFIG_COUNT
32+
// Clear all GIT_CONFIG_KEY_* and GIT_CONFIG_VALUE_* vars
33+
Object.keys(process.env).forEach(key => {
34+
if (key.startsWith('GIT_CONFIG_KEY_') || key.startsWith('GIT_CONFIG_VALUE_')) {
35+
delete process.env[key]
36+
}
37+
})
38+
info('Cleared GIT_CONFIG environment variables')
39+
}
40+
2741
/**
2842
* Ensure that the workspace is a safe directory.
2943
*/
@@ -135,6 +149,70 @@ export async function init(action: ActionInterface): Promise<void | Error> {
135149
info(`Error while checking for includeIf directives: ${extractErrorMessage(error)}`)
136150
}
137151

152+
// Also check for and clear any credential helpers that might be set
153+
try {
154+
info('Checking for credential helpers...')
155+
const credentialHelperResult = await execute(
156+
`git config --get-all credential.helper`,
157+
action.workspace,
158+
true
159+
)
160+
if (credentialHelperResult.stdout) {
161+
info(`Found credential helper: ${credentialHelperResult.stdout}`)
162+
await execute(
163+
`git config --unset-all credential.helper`,
164+
action.workspace,
165+
true
166+
)
167+
info('Removed credential helper')
168+
}
169+
} catch {
170+
info('No credential helper configured')
171+
}
172+
173+
// Clear the extraheader from global scope as well (might be set there in containers)
174+
try {
175+
await execute(
176+
`git config --global --unset-all http.https://${action.hostname}/.extraheader`,
177+
action.workspace,
178+
true
179+
)
180+
info('Removed global extraheader configuration')
181+
} catch {
182+
// Ignore - may not exist
183+
}
184+
185+
// Clear any http.extraheader configs (without the URL prefix)
186+
try {
187+
const extraHeaderCheck = await execute(
188+
`git config --get-regexp 'http.*extraheader'`,
189+
action.workspace,
190+
true
191+
)
192+
if (extraHeaderCheck.stdout) {
193+
info(`Found extraheader configs: ${extraHeaderCheck.stdout}`)
194+
// Remove each one
195+
const lines = extraHeaderCheck.stdout.trim().split('\n')
196+
for (const line of lines) {
197+
const key = line.split(' ')[0]
198+
if (key) {
199+
try {
200+
await execute(
201+
`git config --unset-all ${key}`,
202+
action.workspace,
203+
true
204+
)
205+
info(`Removed ${key}`)
206+
} catch {
207+
// Continue
208+
}
209+
}
210+
}
211+
}
212+
} catch {
213+
// Ignore
214+
}
215+
138216
try {
139217
await execute(`git remote rm origin`, action.workspace, action.silent)
140218

@@ -150,6 +228,19 @@ export async function init(action: ActionInterface): Promise<void | Error> {
150228
action.workspace,
151229
action.silent
152230
)
231+
232+
// Verify the remote was set correctly
233+
try {
234+
const remoteCheck = await execute(
235+
`git remote get-url origin`,
236+
action.workspace,
237+
true
238+
)
239+
info(`Origin remote URL configured (credentials hidden)`)
240+
} catch {
241+
info('Warning: Could not verify origin remote URL')
242+
}
243+
153244
info('Git configured… 🔧')
154245
} catch (error) {
155246
throw new Error(

0 commit comments

Comments
 (0)