diff --git a/src/functions/scm/git.ts b/src/functions/scm/git.ts index ac97fdbe..2b95e7fc 100644 --- a/src/functions/scm/git.ts +++ b/src/functions/scm/git.ts @@ -1,4 +1,6 @@ +import fs from 'node:fs'; import util from 'util'; +import { getFileSystem } from '#agent/agentContextLocalStorage'; import { funcClass } from '#functionSchema/functionDecorators'; import { FileSystemService } from '#functions/storage/fileSystemService'; import { logger } from '#o11y/logger'; @@ -15,6 +17,7 @@ export class Git implements VersionControlSystem { constructor(private fileSystem: FileSystemService) {} async clone(repoURL: string, commitOrBranch = ''): Promise { + await fs.promises.mkdir(getFileSystem().getWorkingDirectory(), { recursive: true }); const { exitCode, stdout, stderr } = await execCommand(`git clone ${repoURL} ${commitOrBranch}`); if (exitCode > 0) throw new Error(`${stdout}\n${stderr}`); } diff --git a/src/functions/scm/gitlab.ts b/src/functions/scm/gitlab.ts index 25c275cf..bcdd29b2 100644 --- a/src/functions/scm/gitlab.ts +++ b/src/functions/scm/gitlab.ts @@ -1,4 +1,5 @@ import { existsSync } from 'fs'; +import fs from 'node:fs'; import { join } from 'path'; import { CommitDiffSchema, @@ -192,8 +193,9 @@ export class GitLab implements SourceControlManagement { // checkExecResult(result, `Failed to pull ${path}`); } else { logger.info(`Cloning project: ${projectPathWithNamespace} to ${path}`); + await fs.promises.mkdir(path, { recursive: true }); const command = `git clone https://oauth2:${this.config().token}@${this.config().host}/${projectPathWithNamespace}.git ${path}`; - const result = await execCommand(command); + const result = await execCommand(command, { mask: this.config().token }); if (result.stderr?.includes('remote HEAD refers to nonexistent ref')) { const gitProject = await this.getProject(projectPathWithNamespace);