@synstack/git
Version:
Git utilities for AI prompting and automation
1 lines • 2.45 kB
Source Map (JSON)
{"version":3,"sources":["../src/git.index.ts","../src/git.lib.ts"],"sourcesContent":["export * from \"./git.lib.ts\";\nexport * as git from \"./git.lib.ts\";\n","import { execa } from \"execa\";\nimport { execPipe, filter, flatMap } from \"iter-tools-es\";\n\n/**\n * Lists all files in a Git repository, including tracked, modified, and untracked files.\n * Respects .gitignore rules.\n *\n * @param cwd - The working directory to execute the git command from\n * @returns A sorted array of file paths\n *\n * @example\n * ```ts\n * const files = await ls('./my-repo')\n * // ['index.ts', 'lib.ts', ...]\n * ```\n */\nexport async function ls(cwd: string = \".\") {\n const [trackedFiles, modifiedFiles, untrackedFiles] = await Promise.all([\n execa({\n cwd: cwd,\n })`git ls-files`,\n execa({\n cwd: cwd,\n })`git ls-files -m`,\n execa({\n cwd: cwd,\n })`git ls-files --others --exclude-standard`,\n ]);\n\n const files = execPipe(\n [trackedFiles, modifiedFiles, untrackedFiles],\n flatMap((r) => r.stdout.split(\"\\n\")),\n filter((l) => l.trim().length > 0),\n );\n\n return [...new Set(files)].sort();\n}\n\n/**\n * Shows the details of a specific Git commit, including the commit message and changes.\n *\n * @param commitId - The hash of the commit to show\n * @param cwd - The working directory to execute the git command from\n * @returns The commit details as a string\n *\n * @example\n * ```ts\n * const commit = await show('449b7730436026243936a0a2f37c6d3474fcad3b')\n * // Returns commit message and changes\n * ```\n */\nexport async function show(commitId: string, cwd: string = \".\") {\n const res = await execa({\n cwd: cwd,\n })`git show ${commitId}`;\n return res.stdout.trim();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAsB;AACtB,2BAA0C;AAe1C,eAAsB,GAAG,MAAc,KAAK;AAC1C,QAAM,CAAC,cAAc,eAAe,cAAc,IAAI,MAAM,QAAQ,IAAI;AAAA,QACtE,oBAAM;AAAA,MACJ;AAAA,IACF,CAAC;AAAA,QACD,oBAAM;AAAA,MACJ;AAAA,IACF,CAAC;AAAA,QACD,oBAAM;AAAA,MACJ;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AAED,QAAM,YAAQ;AAAA,IACZ,CAAC,cAAc,eAAe,cAAc;AAAA,QAC5C,8BAAQ,CAAC,MAAM,EAAE,OAAO,MAAM,IAAI,CAAC;AAAA,QACnC,6BAAO,CAAC,MAAM,EAAE,KAAK,EAAE,SAAS,CAAC;AAAA,EACnC;AAEA,SAAO,CAAC,GAAG,IAAI,IAAI,KAAK,CAAC,EAAE,KAAK;AAClC;AAeA,eAAsB,KAAK,UAAkB,MAAc,KAAK;AAC9D,QAAM,MAAM,UAAM,oBAAM;AAAA,IACtB;AAAA,EACF,CAAC,aAAa,QAAQ;AACtB,SAAO,IAAI,OAAO,KAAK;AACzB;","names":[]}