Compare commits

..

1 Commits

Author SHA1 Message Date
Marcus Wirtz
7b15ecdc92
Merge a0eb51f8ea into 0c366fd6a8 2026-04-21 09:33:30 +00:00

View File

@ -44,13 +44,13 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
if (git) {
authHelper = gitAuthHelper.createAuthHelper(git, settings)
if (settings.setSafeDirectory) {
await addSafeDirectory(settings.repositoryPath, git, authHelper)
await addSafeDirectory(settings.repositoryPath, git)
const containerPath = getContainerRepositoryPath(
settings.repositoryPath,
settings.githubWorkspacePath
)
if (containerPath && containerPath !== settings.repositoryPath) {
await addSafeDirectory(containerPath, git, authHelper)
await addSafeDirectory(containerPath, git)
}
stateHelper.setSafeDirectory()
@ -327,7 +327,18 @@ export async function cleanup(repositoryPath: string): Promise<void> {
const authHelper = gitAuthHelper.createAuthHelper(git)
try {
if (stateHelper.PostSetSafeDirectory) {
await addSafeDirectory(repositoryPath, git, authHelper)
// Setup the repository path as a safe directory, so if we pass this into a container job with a different user it doesn't fail
// Otherwise all git commands we run in a container fail
await authHelper.configureTempGlobalConfig()
core.info(
`Adding repository directory to the temporary git global config as a safe directory`
)
await git
.config('safe.directory', repositoryPath, true, true)
.catch(error => {
core.info(`Failed to initialize safe directory with error: ${error}`)
})
}
await authHelper.removeAuth()
@ -359,10 +370,8 @@ async function getGitCommandManager(
async function addSafeDirectory(
safeDirectory: string,
git: IGitCommandManager,
authHelper: gitAuthHelper.IGitAuthHelper
git: IGitCommandManager
): Promise<void> {
await authHelper.configureTempGlobalConfig()
core.info(`Adding '${safeDirectory}' to the git global config as a safe directory`)
await git.config('safe.directory', safeDirectory, true, true).catch(error => {
core.info(`Failed to initialize safe directory with error: ${error}`)