diff --git a/docs/genaisrc/genaiscript.d.ts b/docs/genaisrc/genaiscript.d.ts index bb39f17cce..4063c0cc95 100644 --- a/docs/genaisrc/genaiscript.d.ts +++ b/docs/genaisrc/genaiscript.d.ts @@ -1312,6 +1312,12 @@ interface Git { */ defaultBranch(): Promise + /** + * Executes a git command in the repository and returns the stdout + * @param cmd + */ + exec(args: string[] | string, options?: { label?: string }): Promise + /** * Finds specific files in the git repository. * By default, work diff --git a/genaisrc/genaiscript.d.ts b/genaisrc/genaiscript.d.ts index bb39f17cce..4063c0cc95 100644 --- a/genaisrc/genaiscript.d.ts +++ b/genaisrc/genaiscript.d.ts @@ -1312,6 +1312,12 @@ interface Git { */ defaultBranch(): Promise + /** + * Executes a git command in the repository and returns the stdout + * @param cmd + */ + exec(args: string[] | string, options?: { label?: string }): Promise + /** * Finds specific files in the git repository. * By default, work diff --git a/packages/auto/genaiscript.d.ts b/packages/auto/genaiscript.d.ts index bb39f17cce..4063c0cc95 100644 --- a/packages/auto/genaiscript.d.ts +++ b/packages/auto/genaiscript.d.ts @@ -1312,6 +1312,12 @@ interface Git { */ defaultBranch(): Promise + /** + * Executes a git command in the repository and returns the stdout + * @param cmd + */ + exec(args: string[] | string, options?: { label?: string }): Promise + /** * Finds specific files in the git repository. * By default, work diff --git a/packages/core/src/genaisrc/genaiscript.d.ts b/packages/core/src/genaisrc/genaiscript.d.ts index bb39f17cce..4063c0cc95 100644 --- a/packages/core/src/genaisrc/genaiscript.d.ts +++ b/packages/core/src/genaisrc/genaiscript.d.ts @@ -1312,6 +1312,12 @@ interface Git { */ defaultBranch(): Promise + /** + * Executes a git command in the repository and returns the stdout + * @param cmd + */ + exec(args: string[] | string, options?: { label?: string }): Promise + /** * Finds specific files in the git repository. * By default, work diff --git a/packages/core/src/git.ts b/packages/core/src/git.ts index d5608a3dad..1109379616 100644 --- a/packages/core/src/git.ts +++ b/packages/core/src/git.ts @@ -1,6 +1,7 @@ import { resolveFileContents } from "./file" import { isGlobMatch } from "./glob" import { runtimeHost } from "./host" +import { shellParse } from "./shell" import { arrayify } from "./util" export class GitClient implements Git { @@ -10,13 +11,11 @@ export class GitClient implements Git { async defaultBranch(): Promise { if (!this._defaultBranch) { const res = ( - await runtimeHost.exec( - undefined, - this.git, + await this.exec( ["symbolic-ref", "refs/remotes/origin/HEAD"], {} ) - ).stdout + ) .replace("refs/remotes/origin/", "") .trim() this._defaultBranch = res @@ -24,6 +23,19 @@ export class GitClient implements Git { return this._defaultBranch } + async exec( + args: string | string[], + options?: { label?: string } + ): Promise { + const res = await runtimeHost.exec( + undefined, + this.git, + Array.isArray(args) ? args : shellParse(args), + options + ) + return res.stdout + } + async findModifiedFiles( scope: "branch" | "staged" | "modified", options?: { @@ -49,18 +61,18 @@ export class GitClient implements Git { args.push(...paths) args.push(...excludedPaths.map((p) => ":!" + p)) } - const res = await runtimeHost.exec(undefined, this.git, args, { + const res = await this.exec(args, { label: `git list modified files in ${scope}`, }) - filenames = res.stdout.split("\n").filter((f) => f) + filenames = res.split("\n").filter((f) => f) } else { // ignore deleted files const rx = /^\s*(A|M|\?{1,2})\s+/gm const args = ["status", "--porcelain"] - const res = await runtimeHost.exec(undefined, this.git, args, { + const res = await this.exec(args, { label: `git list modified files`, }) - filenames = res.stdout + filenames = res .split("\n") .filter((f) => rx.test(f)) .map((f) => f.replace(rx, "").trim()) diff --git a/packages/core/src/types/prompt_template.d.ts b/packages/core/src/types/prompt_template.d.ts index 7e637a5a56..fd1642537b 100644 --- a/packages/core/src/types/prompt_template.d.ts +++ b/packages/core/src/types/prompt_template.d.ts @@ -1279,6 +1279,12 @@ interface Git { */ defaultBranch(): Promise + /** + * Executes a git command in the repository and returns the stdout + * @param cmd + */ + exec(args: string[] | string, options?: { label?: string }): Promise + /** * Finds specific files in the git repository. * By default, work diff --git a/packages/sample/genaisrc/blog/genaiscript.d.ts b/packages/sample/genaisrc/blog/genaiscript.d.ts index bb39f17cce..4063c0cc95 100644 --- a/packages/sample/genaisrc/blog/genaiscript.d.ts +++ b/packages/sample/genaisrc/blog/genaiscript.d.ts @@ -1312,6 +1312,12 @@ interface Git { */ defaultBranch(): Promise + /** + * Executes a git command in the repository and returns the stdout + * @param cmd + */ + exec(args: string[] | string, options?: { label?: string }): Promise + /** * Finds specific files in the git repository. * By default, work diff --git a/packages/sample/genaisrc/genaiscript.d.ts b/packages/sample/genaisrc/genaiscript.d.ts index bb39f17cce..4063c0cc95 100644 --- a/packages/sample/genaisrc/genaiscript.d.ts +++ b/packages/sample/genaisrc/genaiscript.d.ts @@ -1312,6 +1312,12 @@ interface Git { */ defaultBranch(): Promise + /** + * Executes a git command in the repository and returns the stdout + * @param cmd + */ + exec(args: string[] | string, options?: { label?: string }): Promise + /** * Finds specific files in the git repository. * By default, work diff --git a/packages/sample/genaisrc/git.genai.mts b/packages/sample/genaisrc/git.genai.mts index b08b2b9078..ae7bfa8ab0 100644 --- a/packages/sample/genaisrc/git.genai.mts +++ b/packages/sample/genaisrc/git.genai.mts @@ -1,3 +1,6 @@ +const defaultBranch = await git.defaultBranch() +console.log({ defaultBranch }) + const mods = await git.findModifiedFiles("modified", { paths: ["**/*.ts"], excludedPaths: ["**/genaiscript.d.ts"], diff --git a/packages/sample/genaisrc/node/genaiscript.d.ts b/packages/sample/genaisrc/node/genaiscript.d.ts index bb39f17cce..4063c0cc95 100644 --- a/packages/sample/genaisrc/node/genaiscript.d.ts +++ b/packages/sample/genaisrc/node/genaiscript.d.ts @@ -1312,6 +1312,12 @@ interface Git { */ defaultBranch(): Promise + /** + * Executes a git command in the repository and returns the stdout + * @param cmd + */ + exec(args: string[] | string, options?: { label?: string }): Promise + /** * Finds specific files in the git repository. * By default, work diff --git a/packages/sample/genaisrc/python/genaiscript.d.ts b/packages/sample/genaisrc/python/genaiscript.d.ts index bb39f17cce..4063c0cc95 100644 --- a/packages/sample/genaisrc/python/genaiscript.d.ts +++ b/packages/sample/genaisrc/python/genaiscript.d.ts @@ -1312,6 +1312,12 @@ interface Git { */ defaultBranch(): Promise + /** + * Executes a git command in the repository and returns the stdout + * @param cmd + */ + exec(args: string[] | string, options?: { label?: string }): Promise + /** * Finds specific files in the git repository. * By default, work diff --git a/packages/sample/genaisrc/style/genaiscript.d.ts b/packages/sample/genaisrc/style/genaiscript.d.ts index bb39f17cce..4063c0cc95 100644 --- a/packages/sample/genaisrc/style/genaiscript.d.ts +++ b/packages/sample/genaisrc/style/genaiscript.d.ts @@ -1312,6 +1312,12 @@ interface Git { */ defaultBranch(): Promise + /** + * Executes a git command in the repository and returns the stdout + * @param cmd + */ + exec(args: string[] | string, options?: { label?: string }): Promise + /** * Finds specific files in the git repository. * By default, work diff --git a/packages/sample/src/aici/genaiscript.d.ts b/packages/sample/src/aici/genaiscript.d.ts index bb39f17cce..4063c0cc95 100644 --- a/packages/sample/src/aici/genaiscript.d.ts +++ b/packages/sample/src/aici/genaiscript.d.ts @@ -1312,6 +1312,12 @@ interface Git { */ defaultBranch(): Promise + /** + * Executes a git command in the repository and returns the stdout + * @param cmd + */ + exec(args: string[] | string, options?: { label?: string }): Promise + /** * Finds specific files in the git repository. * By default, work diff --git a/packages/sample/src/errors/genaiscript.d.ts b/packages/sample/src/errors/genaiscript.d.ts index bb39f17cce..4063c0cc95 100644 --- a/packages/sample/src/errors/genaiscript.d.ts +++ b/packages/sample/src/errors/genaiscript.d.ts @@ -1312,6 +1312,12 @@ interface Git { */ defaultBranch(): Promise + /** + * Executes a git command in the repository and returns the stdout + * @param cmd + */ + exec(args: string[] | string, options?: { label?: string }): Promise + /** * Finds specific files in the git repository. * By default, work diff --git a/packages/sample/src/genaiscript.d.ts b/packages/sample/src/genaiscript.d.ts index bb39f17cce..4063c0cc95 100644 --- a/packages/sample/src/genaiscript.d.ts +++ b/packages/sample/src/genaiscript.d.ts @@ -1312,6 +1312,12 @@ interface Git { */ defaultBranch(): Promise + /** + * Executes a git command in the repository and returns the stdout + * @param cmd + */ + exec(args: string[] | string, options?: { label?: string }): Promise + /** * Finds specific files in the git repository. * By default, work diff --git a/packages/sample/src/makecode/genaiscript.d.ts b/packages/sample/src/makecode/genaiscript.d.ts index bb39f17cce..4063c0cc95 100644 --- a/packages/sample/src/makecode/genaiscript.d.ts +++ b/packages/sample/src/makecode/genaiscript.d.ts @@ -1312,6 +1312,12 @@ interface Git { */ defaultBranch(): Promise + /** + * Executes a git command in the repository and returns the stdout + * @param cmd + */ + exec(args: string[] | string, options?: { label?: string }): Promise + /** * Finds specific files in the git repository. * By default, work diff --git a/packages/sample/src/tla/genaiscript.d.ts b/packages/sample/src/tla/genaiscript.d.ts index bb39f17cce..4063c0cc95 100644 --- a/packages/sample/src/tla/genaiscript.d.ts +++ b/packages/sample/src/tla/genaiscript.d.ts @@ -1312,6 +1312,12 @@ interface Git { */ defaultBranch(): Promise + /** + * Executes a git command in the repository and returns the stdout + * @param cmd + */ + exec(args: string[] | string, options?: { label?: string }): Promise + /** * Finds specific files in the git repository. * By default, work diff --git a/packages/sample/src/vision/genaiscript.d.ts b/packages/sample/src/vision/genaiscript.d.ts index bb39f17cce..4063c0cc95 100644 --- a/packages/sample/src/vision/genaiscript.d.ts +++ b/packages/sample/src/vision/genaiscript.d.ts @@ -1312,6 +1312,12 @@ interface Git { */ defaultBranch(): Promise + /** + * Executes a git command in the repository and returns the stdout + * @param cmd + */ + exec(args: string[] | string, options?: { label?: string }): Promise + /** * Finds specific files in the git repository. * By default, work diff --git a/packages/vscode/genaisrc/genaiscript.d.ts b/packages/vscode/genaisrc/genaiscript.d.ts index bb39f17cce..4063c0cc95 100644 --- a/packages/vscode/genaisrc/genaiscript.d.ts +++ b/packages/vscode/genaisrc/genaiscript.d.ts @@ -1312,6 +1312,12 @@ interface Git { */ defaultBranch(): Promise + /** + * Executes a git command in the repository and returns the stdout + * @param cmd + */ + exec(args: string[] | string, options?: { label?: string }): Promise + /** * Finds specific files in the git repository. * By default, work diff --git a/slides/genaisrc/genaiscript.d.ts b/slides/genaisrc/genaiscript.d.ts index bb39f17cce..4063c0cc95 100644 --- a/slides/genaisrc/genaiscript.d.ts +++ b/slides/genaisrc/genaiscript.d.ts @@ -1312,6 +1312,12 @@ interface Git { */ defaultBranch(): Promise + /** + * Executes a git command in the repository and returns the stdout + * @param cmd + */ + exec(args: string[] | string, options?: { label?: string }): Promise + /** * Finds specific files in the git repository. * By default, work