@ac-kit/cmd-git 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2024-2026 Anthony Champagne and contributors
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # @ac-kit/cmd-git
2
+
3
+ A typed wrapper over the `git` command-line program — not a reimplementation of
4
+ git.
5
+
6
+ Wrapping the real binary is the point: it gets credential helpers, SSH agents,
7
+ config precedence, hooks and LFS for free, none of which a from-scratch
8
+ implementation would match. What this adds is a typed signature per subcommand
9
+ and a parser for the output.
10
+
11
+ ```ts
12
+ import { gitRevParse, gitStatusV1Sync } from "@ac-kit/cmd-git";
13
+
14
+ const head = await gitRevParse("HEAD", {
15
+ execOptions: { cwd: repository },
16
+ });
17
+
18
+ // `git status --porcelain=v1`, parsed into entries rather than left as text.
19
+ for (const entry of await gitStatusV1Sync([], { execOptions: { cwd: repository } })) {
20
+ console.log(entry.path);
21
+ }
22
+ ```
23
+
24
+ Every wrapper takes an optional `AbortSignal` and passes `execOptions` —
25
+ including `cwd`, the repository to run in — straight through to `execFile`. The
26
+ `git` binary is spawned with an argv array, never through a shell, so there is
27
+ no metacharacter interpretation to guard against.
28
+
29
+ Covers `gitInit`, `gitCheckout`, `gitFetch`, `gitRemoteAdd`, `gitRevParse`,
30
+ `gitSparseCheckoutInit`/`gitSparseCheckoutSet`, and `gitStatusV1Sync`.
31
+
32
+ Requires `git` on `PATH`; it is not bundled. Node only.
33
+
34
+ See the
35
+ [generated API docs](https://anthochamp.github.io/node-essentials/api/cmd-git/)
36
+ for the full reference.
@@ -0,0 +1,9 @@
1
+ import type { GitCommandOptions } from "./command-options.js";
2
+ /**
3
+ * Checks out `ref` (a branch, tag, or commit SHA) into the working tree at
4
+ * `options.execOptions.cwd`.
5
+ *
6
+ * @see https://git-scm.com/docs/git-checkout
7
+ */
8
+ export declare function gitCheckout(ref: string, options?: GitCommandOptions): Promise<void>;
9
+ //# sourceMappingURL=checkout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkout.d.ts","sourceRoot":"","sources":["../src/checkout.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D;;;;;GAKG;AACH,wBAAsB,WAAW,CAChC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,iBAAiB,GACzB,OAAO,CAAC,IAAI,CAAC,CAKf"}
@@ -0,0 +1,14 @@
1
+ import { execFileAsync } from "@ac-kit/node";
2
+ /**
3
+ * Checks out `ref` (a branch, tag, or commit SHA) into the working tree at
4
+ * `options.execOptions.cwd`.
5
+ *
6
+ * @see https://git-scm.com/docs/git-checkout
7
+ */
8
+ export async function gitCheckout(ref, options) {
9
+ await execFileAsync("git", ["checkout", "--quiet", ref], {
10
+ ...options?.execOptions,
11
+ signal: options?.signal ?? undefined,
12
+ });
13
+ }
14
+ //# sourceMappingURL=checkout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkout.js","sourceRoot":"","sources":["../src/checkout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAI7C;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAChC,GAAW,EACX,OAA2B;IAE3B,MAAM,aAAa,CAAC,KAAK,EAAE,CAAC,UAAU,EAAE,SAAS,EAAE,GAAG,CAAC,EAAE;QACxD,GAAG,OAAO,EAAE,WAAW;QACvB,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,SAAS;KACpC,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { ExecFileOptions } from "node:child_process";
2
+ /** Common options accepted by every git-subcommand wrapper in this package. */
3
+ export type GitCommandOptions = {
4
+ /** An optional AbortSignal that can be used to abort the operation. */
5
+ signal?: AbortSignal | null;
6
+ /**
7
+ * Additional options to pass to the underlying `execFileAsync` call,
8
+ * including `cwd` — the git repository to run the command in. Defaults to
9
+ * `execFileAsync`'s own default (`process.cwd()`) when omitted.
10
+ */
11
+ execOptions?: Omit<ExecFileOptions, "signal" | "encoding">;
12
+ };
13
+ //# sourceMappingURL=command-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-options.d.ts","sourceRoot":"","sources":["../src/command-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAQ1D,+EAA+E;AAC/E,MAAM,MAAM,iBAAiB,GAAG;IAC/B,uEAAuE;IACvE,MAAM,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IAE5B;;;;OAIG;IACH,WAAW,CAAC,EAAE,IAAI,CAAC,eAAe,EAAE,QAAQ,GAAG,UAAU,CAAC,CAAC;CAC3D,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=command-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-options.js","sourceRoot":"","sources":["../src/command-options.ts"],"names":[],"mappings":""}
@@ -0,0 +1,26 @@
1
+ import type { GitCommandOptions } from "./command-options.js";
2
+ export type GitFetchOptions = GitCommandOptions & {
3
+ /**
4
+ * Object filter passed to `--filter`, e.g. `"blob:none"` to omit blob objects
5
+ * until a later checkout needs them.
6
+ *
7
+ * @see https://git-scm.com/docs/git-fetch#Documentation/git-fetch.txt---filterltfilter-specgt
8
+ */
9
+ filter?: string;
10
+ /**
11
+ * Shallow-fetch depth passed to `--depth` — only the history needed to
12
+ * resolve `refspec` is transferred.
13
+ *
14
+ * @see https://git-scm.com/docs/git-fetch#Documentation/git-fetch.txt---depthltdepthgt
15
+ */
16
+ depth?: number;
17
+ };
18
+ /**
19
+ * Fetches `refspec` (a branch, tag, or full commit SHA the remote exposes,
20
+ * reachable or not) from `remote` into the object store at
21
+ * `options.execOptions.cwd`.
22
+ *
23
+ * @see https://git-scm.com/docs/git-fetch
24
+ */
25
+ export declare function gitFetch(remote: string, refspec: string, options?: GitFetchOptions): Promise<void>;
26
+ //# sourceMappingURL=fetch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D,MAAM,MAAM,eAAe,GAAG,iBAAiB,GAAG;IACjD;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;;;OAKG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;;;GAMG;AACH,wBAAsB,QAAQ,CAC7B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,eAAe,GACvB,OAAO,CAAC,IAAI,CAAC,CAgBf"}
package/dist/fetch.js ADDED
@@ -0,0 +1,23 @@
1
+ import { execFileAsync } from "@ac-kit/node";
2
+ /**
3
+ * Fetches `refspec` (a branch, tag, or full commit SHA the remote exposes,
4
+ * reachable or not) from `remote` into the object store at
5
+ * `options.execOptions.cwd`.
6
+ *
7
+ * @see https://git-scm.com/docs/git-fetch
8
+ */
9
+ export async function gitFetch(remote, refspec, options) {
10
+ const args = ["fetch", "--quiet"];
11
+ if (options?.filter !== undefined) {
12
+ args.push(`--filter=${options.filter}`);
13
+ }
14
+ if (options?.depth !== undefined) {
15
+ args.push(`--depth=${options.depth}`);
16
+ }
17
+ args.push(remote, refspec);
18
+ await execFileAsync("git", args, {
19
+ ...options?.execOptions,
20
+ signal: options?.signal ?? undefined,
21
+ });
22
+ }
23
+ //# sourceMappingURL=fetch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch.js","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAsB7C;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC7B,MAAc,EACd,OAAe,EACf,OAAyB;IAEzB,MAAM,IAAI,GAAG,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IAElC,IAAI,OAAO,EAAE,MAAM,KAAK,SAAS,EAAE,CAAC;QACnC,IAAI,CAAC,IAAI,CAAC,YAAY,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACzC,CAAC;IACD,IAAI,OAAO,EAAE,KAAK,KAAK,SAAS,EAAE,CAAC;QAClC,IAAI,CAAC,IAAI,CAAC,WAAW,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;IACvC,CAAC;IAED,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAE3B,MAAM,aAAa,CAAC,KAAK,EAAE,IAAI,EAAE;QAChC,GAAG,OAAO,EAAE,WAAW;QACvB,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,SAAS;KACpC,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,9 @@
1
+ export * from "./checkout.js";
2
+ export * from "./command-options.js";
3
+ export * from "./fetch.js";
4
+ export * from "./init.js";
5
+ export * from "./remote.js";
6
+ export * from "./rev-parse.js";
7
+ export * from "./sparse-checkout.js";
8
+ export * from "./status-v1.js";
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ export * from "./checkout.js";
2
+ export * from "./command-options.js";
3
+ export * from "./fetch.js";
4
+ export * from "./init.js";
5
+ export * from "./remote.js";
6
+ export * from "./rev-parse.js";
7
+ export * from "./sparse-checkout.js";
8
+ export * from "./status-v1.js";
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC"}
package/dist/init.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import type { GitCommandOptions } from "./command-options.js";
2
+ /**
3
+ * Initializes a new, empty git repository (in `options.execOptions.cwd`, or the
4
+ * process's own working directory when omitted).
5
+ *
6
+ * @see https://git-scm.com/docs/git-init
7
+ */
8
+ export declare function gitInit(options?: GitCommandOptions): Promise<void>;
9
+ //# sourceMappingURL=init.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D;;;;;GAKG;AACH,wBAAsB,OAAO,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAKxE"}
package/dist/init.js ADDED
@@ -0,0 +1,14 @@
1
+ import { execFileAsync } from "@ac-kit/node";
2
+ /**
3
+ * Initializes a new, empty git repository (in `options.execOptions.cwd`, or the
4
+ * process's own working directory when omitted).
5
+ *
6
+ * @see https://git-scm.com/docs/git-init
7
+ */
8
+ export async function gitInit(options) {
9
+ await execFileAsync("git", ["init", "--quiet"], {
10
+ ...options?.execOptions,
11
+ signal: options?.signal ?? undefined,
12
+ });
13
+ }
14
+ //# sourceMappingURL=init.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.js","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAI7C;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,OAA2B;IACxD,MAAM,aAAa,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE;QAC/C,GAAG,OAAO,EAAE,WAAW;QACvB,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,SAAS;KACpC,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { GitCommandOptions } from "./command-options.js";
2
+ /**
3
+ * Adds a remote named `name` pointing at `url` (in `options.execOptions.cwd`).
4
+ *
5
+ * @see https://git-scm.com/docs/git-remote#Documentation/git-remote.txt-emaddem
6
+ */
7
+ export declare function gitRemoteAdd(name: string, url: string, options?: GitCommandOptions): Promise<void>;
8
+ //# sourceMappingURL=remote.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remote.d.ts","sourceRoot":"","sources":["../src/remote.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D;;;;GAIG;AACH,wBAAsB,YAAY,CACjC,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,iBAAiB,GACzB,OAAO,CAAC,IAAI,CAAC,CAKf"}
package/dist/remote.js ADDED
@@ -0,0 +1,13 @@
1
+ import { execFileAsync } from "@ac-kit/node";
2
+ /**
3
+ * Adds a remote named `name` pointing at `url` (in `options.execOptions.cwd`).
4
+ *
5
+ * @see https://git-scm.com/docs/git-remote#Documentation/git-remote.txt-emaddem
6
+ */
7
+ export async function gitRemoteAdd(name, url, options) {
8
+ await execFileAsync("git", ["remote", "add", name, url], {
9
+ ...options?.execOptions,
10
+ signal: options?.signal ?? undefined,
11
+ });
12
+ }
13
+ //# sourceMappingURL=remote.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remote.js","sourceRoot":"","sources":["../src/remote.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAI7C;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CACjC,IAAY,EACZ,GAAW,EACX,OAA2B;IAE3B,MAAM,aAAa,CAAC,KAAK,EAAE,CAAC,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,CAAC,EAAE;QACxD,GAAG,OAAO,EAAE,WAAW;QACvB,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,SAAS;KACpC,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { GitCommandOptions } from "./command-options.js";
2
+ /**
3
+ * Resolves `rev` (e.g. `"HEAD"`, a branch name, or a short SHA) to its full
4
+ * commit SHA at `options.execOptions.cwd`.
5
+ *
6
+ * @throws {ProcessExitWithOutputError} When `rev` cannot be resolved.
7
+ * @see https://git-scm.com/docs/git-rev-parse
8
+ */
9
+ export declare function gitRevParse(rev: string, options?: GitCommandOptions): Promise<string>;
10
+ //# sourceMappingURL=rev-parse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rev-parse.d.ts","sourceRoot":"","sources":["../src/rev-parse.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D;;;;;;GAMG;AACH,wBAAsB,WAAW,CAChC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,iBAAiB,GACzB,OAAO,CAAC,MAAM,CAAC,CAQjB"}
@@ -0,0 +1,17 @@
1
+ import { execFileAsync } from "@ac-kit/node";
2
+ /**
3
+ * Resolves `rev` (e.g. `"HEAD"`, a branch name, or a short SHA) to its full
4
+ * commit SHA at `options.execOptions.cwd`.
5
+ *
6
+ * @throws {ProcessExitWithOutputError} When `rev` cannot be resolved.
7
+ * @see https://git-scm.com/docs/git-rev-parse
8
+ */
9
+ export async function gitRevParse(rev, options) {
10
+ const { stdout } = await execFileAsync("git", ["rev-parse", rev], {
11
+ ...options?.execOptions,
12
+ encoding: "utf8",
13
+ signal: options?.signal ?? undefined,
14
+ });
15
+ return stdout.trim();
16
+ }
17
+ //# sourceMappingURL=rev-parse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rev-parse.js","sourceRoot":"","sources":["../src/rev-parse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAI7C;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAChC,GAAW,EACX,OAA2B;IAE3B,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,aAAa,CAAC,KAAK,EAAE,CAAC,WAAW,EAAE,GAAG,CAAC,EAAE;QACjE,GAAG,OAAO,EAAE,WAAW;QACvB,QAAQ,EAAE,MAAM;QAChB,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,SAAS;KACpC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;AACtB,CAAC"}
@@ -0,0 +1,23 @@
1
+ import type { GitCommandOptions } from "./command-options.js";
2
+ export type GitSparseCheckoutInitOptions = GitCommandOptions & {
3
+ /**
4
+ * Use cone mode — directory-scoped patterns instead of full gitignore-style
5
+ * patterns.
6
+ */
7
+ cone?: boolean;
8
+ };
9
+ /**
10
+ * Enables sparse-checkout for the repository at `options.execOptions.cwd`.
11
+ *
12
+ * @see https://git-scm.com/docs/git-sparse-checkout
13
+ */
14
+ export declare function gitSparseCheckoutInit(options?: GitSparseCheckoutInitOptions): Promise<void>;
15
+ /**
16
+ * Restricts the working tree at `options.execOptions.cwd` to `paths` (cone-mode
17
+ * directory patterns when {@link gitSparseCheckoutInit} was called with `cone:
18
+ * true`).
19
+ *
20
+ * @see https://git-scm.com/docs/git-sparse-checkout
21
+ */
22
+ export declare function gitSparseCheckoutSet(paths: readonly string[], options?: GitCommandOptions): Promise<void>;
23
+ //# sourceMappingURL=sparse-checkout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sparse-checkout.d.ts","sourceRoot":"","sources":["../src/sparse-checkout.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D,MAAM,MAAM,4BAA4B,GAAG,iBAAiB,GAAG;IAC9D;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;CACf,CAAC;AAEF;;;;GAIG;AACH,wBAAsB,qBAAqB,CAC1C,OAAO,CAAC,EAAE,4BAA4B,GACpC,OAAO,CAAC,IAAI,CAAC,CAWf;AAED;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CACzC,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,OAAO,CAAC,EAAE,iBAAiB,GACzB,OAAO,CAAC,IAAI,CAAC,CAKf"}
@@ -0,0 +1,30 @@
1
+ import { execFileAsync } from "@ac-kit/node";
2
+ /**
3
+ * Enables sparse-checkout for the repository at `options.execOptions.cwd`.
4
+ *
5
+ * @see https://git-scm.com/docs/git-sparse-checkout
6
+ */
7
+ export async function gitSparseCheckoutInit(options) {
8
+ const args = ["sparse-checkout", "init"];
9
+ if (options?.cone) {
10
+ args.push("--cone");
11
+ }
12
+ await execFileAsync("git", args, {
13
+ ...options?.execOptions,
14
+ signal: options?.signal ?? undefined,
15
+ });
16
+ }
17
+ /**
18
+ * Restricts the working tree at `options.execOptions.cwd` to `paths` (cone-mode
19
+ * directory patterns when {@link gitSparseCheckoutInit} was called with `cone:
20
+ * true`).
21
+ *
22
+ * @see https://git-scm.com/docs/git-sparse-checkout
23
+ */
24
+ export async function gitSparseCheckoutSet(paths, options) {
25
+ await execFileAsync("git", ["sparse-checkout", "set", ...paths], {
26
+ ...options?.execOptions,
27
+ signal: options?.signal ?? undefined,
28
+ });
29
+ }
30
+ //# sourceMappingURL=sparse-checkout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sparse-checkout.js","sourceRoot":"","sources":["../src/sparse-checkout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAY7C;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAC1C,OAAsC;IAEtC,MAAM,IAAI,GAAG,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAC;IAEzC,IAAI,OAAO,EAAE,IAAI,EAAE,CAAC;QACnB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACrB,CAAC;IAED,MAAM,aAAa,CAAC,KAAK,EAAE,IAAI,EAAE;QAChC,GAAG,OAAO,EAAE,WAAW;QACvB,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,SAAS;KACpC,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACzC,KAAwB,EACxB,OAA2B;IAE3B,MAAM,aAAa,CAAC,KAAK,EAAE,CAAC,iBAAiB,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC,EAAE;QAChE,GAAG,OAAO,EAAE,WAAW;QACvB,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,SAAS;KACpC,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,28 @@
1
+ import type { ExecOptions } from "node:child_process";
2
+ export type GitStatusCode = [string, string];
3
+ export type GitStatusV1Entry = {
4
+ statusCode: GitStatusCode;
5
+ /** Path relative to the git root. */
6
+ path: string;
7
+ /** Original path in case of rename/copied contents, null otherwise. */
8
+ origPath: string | null;
9
+ };
10
+ export type GitStatusOptions = {
11
+ /** Include ignored files. */
12
+ ignored?: boolean;
13
+ /** An optional AbortSignal that can be used to abort the operation. */
14
+ signal?: AbortSignal | null;
15
+ /** Additional options to pass to the `execAsync` function. */
16
+ execOptions?: Omit<ExecOptions, "signal" | "encoding">;
17
+ };
18
+ /**
19
+ * Retrieves the git status in porcelain v1 format, optionally limited to the
20
+ * specified path(s).
21
+ *
22
+ * @param pathSpec Array of paths to limit the status to.
23
+ * @param options Options for the git status command.
24
+ * @returns Array of git status entries.
25
+ * @see https://git-scm.com/docs/git-status#_porcelain_format_version_1
26
+ */
27
+ export declare function gitStatusV1Sync(pathSpec?: string[], options?: GitStatusOptions): Promise<GitStatusV1Entry[]>;
28
+ //# sourceMappingURL=status-v1.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status-v1.d.ts","sourceRoot":"","sources":["../src/status-v1.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAOtD,MAAM,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAE7C,MAAM,MAAM,gBAAgB,GAAG;IAC9B,UAAU,EAAE,aAAa,CAAC;IAE1B,qCAAqC;IACrC,IAAI,EAAE,MAAM,CAAC;IAEb,uEAAuE;IACvE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC9B,6BAA6B;IAC7B,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB,uEAAuE;IACvE,MAAM,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IAE5B,8DAA8D;IAC9D,WAAW,CAAC,EAAE,IAAI,CAAC,WAAW,EAAE,QAAQ,GAAG,UAAU,CAAC,CAAC;CACvD,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAsB,eAAe,CACpC,QAAQ,GAAE,MAAM,EAAO,EACvB,OAAO,CAAC,EAAE,gBAAgB,GACxB,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAkD7B"}
@@ -0,0 +1,56 @@
1
+ import { EOL } from "node:os";
2
+ import { joinNonEmpty } from "@ac-kit/core";
3
+ import { escapeCommandArg, execAsync } from "@ac-kit/node";
4
+ /**
5
+ * Retrieves the git status in porcelain v1 format, optionally limited to the
6
+ * specified path(s).
7
+ *
8
+ * @param pathSpec Array of paths to limit the status to.
9
+ * @param options Options for the git status command.
10
+ * @returns Array of git status entries.
11
+ * @see https://git-scm.com/docs/git-status#_porcelain_format_version_1
12
+ */
13
+ export async function gitStatusV1Sync(pathSpec = [], options) {
14
+ const pathArgs = pathSpec.map((p) => escapeCommandArg(p));
15
+ const args = [
16
+ ...pathArgs,
17
+ pathArgs.length > 0 ? "--" : "",
18
+ "--porcelain=v1",
19
+ options?.ignored ? "--ignored" : "",
20
+ ];
21
+ const { stdout } = await execAsync(`git status ${joinNonEmpty(args, " ")}`, {
22
+ ...options?.execOptions,
23
+ encoding: "utf8",
24
+ signal: options?.signal ?? undefined,
25
+ });
26
+ return stdout
27
+ .trimEnd()
28
+ .split(EOL)
29
+ .map((line) => {
30
+ // either "XY PATH" or "XY ORIG_PATH -> PATH"
31
+ const words = line.split(" ");
32
+ const [statusCodeFirstChar, statusCodeSecondChar] = words[0];
33
+ if (statusCodeFirstChar === undefined ||
34
+ statusCodeSecondChar === undefined) {
35
+ throw new Error(`Unexpected git status output line: ${line}`);
36
+ }
37
+ let path;
38
+ let origPath;
39
+ const pathSeparatorIndex = words.indexOf("->");
40
+ if (pathSeparatorIndex !== -1) {
41
+ // rename or copy
42
+ origPath = words.slice(1, pathSeparatorIndex).join(" ");
43
+ path = words.slice(pathSeparatorIndex).join(" ");
44
+ }
45
+ else {
46
+ origPath = null;
47
+ path = words.slice(1, pathSeparatorIndex).join(" ");
48
+ }
49
+ return {
50
+ statusCode: [statusCodeFirstChar, statusCodeSecondChar],
51
+ path,
52
+ origPath,
53
+ };
54
+ });
55
+ }
56
+ //# sourceMappingURL=status-v1.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status-v1.js","sourceRoot":"","sources":["../src/status-v1.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAE9B,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AA0B3D;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACpC,QAAQ,GAAa,EAAE,EACvB,OAA0B;IAE1B,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1D,MAAM,IAAI,GAAG;QACZ,GAAG,QAAQ;QACX,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE;QAC/B,gBAAgB;QAChB,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE;KACnC,CAAC;IAEF,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,SAAS,CAAC,cAAc,YAAY,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,EAAE;QAC3E,GAAG,OAAO,EAAE,WAAW;QACvB,QAAQ,EAAE,MAAM;QAChB,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,SAAS;KACpC,CAAC,CAAC;IAEH,OAAO,MAAM;SACX,OAAO,EAAE;SACT,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACb,6CAA6C;QAC7C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAE9B,MAAM,CAAC,mBAAmB,EAAE,oBAAoB,CAAC,GAAG,KAAK,CAAC,CAAC,CAAE,CAAC;QAE9D,IACC,mBAAmB,KAAK,SAAS;YACjC,oBAAoB,KAAK,SAAS,EACjC,CAAC;YACF,MAAM,IAAI,KAAK,CAAC,sCAAsC,IAAI,EAAE,CAAC,CAAC;QAC/D,CAAC;QAED,IAAI,IAAY,CAAC;QACjB,IAAI,QAAuB,CAAC;QAE5B,MAAM,kBAAkB,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC/C,IAAI,kBAAkB,KAAK,CAAC,CAAC,EAAE,CAAC;YAC/B,iBAAiB;YACjB,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,kBAAkB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACxD,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAClD,CAAC;aAAM,CAAC;YACP,QAAQ,GAAG,IAAI,CAAC;YAChB,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,kBAAkB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACrD,CAAC;QAED,OAAO;YACN,UAAU,EAAE,CAAC,mBAAmB,EAAE,oBAAoB,CAAC;YACvD,IAAI;YACJ,QAAQ;SACR,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@ac-kit/cmd-git",
3
+ "version": "0.1.0",
4
+ "description": "Typed wrapper over the git CLI: invocation plus git status porcelain v1 parsing.",
5
+ "keywords": [
6
+ "cli",
7
+ "git",
8
+ "porcelain",
9
+ "wrapper"
10
+ ],
11
+ "homepage": "https://anthochamp.github.io/node-essentials/api/cmd-git/",
12
+ "bugs": {
13
+ "url": "https://github.com/anthochamp/node-essentials/issues"
14
+ },
15
+ "license": "BSD-3-Clause",
16
+ "author": "Anthony Champagne <dev@anthonychampagne.fr>",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/anthochamp/node-essentials.git",
20
+ "directory": "packages/cmd-git"
21
+ },
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "type": "module",
26
+ "sideEffects": false,
27
+ "main": "./dist/index.js",
28
+ "publishConfig": {
29
+ "main": "./dist/index.js",
30
+ "access": "public"
31
+ },
32
+ "scripts": {
33
+ "compile": "tsc -p ./tsconfig.build.json -outDir dist",
34
+ "compile:check": "tsc -noEmit -p ./tsconfig.json",
35
+ "clean": "rimraf dist",
36
+ "build": "yarn clean && yarn compile",
37
+ "test": "yarn run -T vitest run",
38
+ "prepack": "yarn build"
39
+ },
40
+ "dependencies": {
41
+ "@ac-kit/core": "^0.1.0",
42
+ "@ac-kit/node": "^0.1.0"
43
+ },
44
+ "devDependencies": {
45
+ "@ac-kit/tsconfig": "0.1.0",
46
+ "@ac-kit/typedoc-config": "0.1.0",
47
+ "@ac-kit/vitest-config": "0.1.0",
48
+ "@types/node": "26.5.1",
49
+ "@typescript/native": "typescript@7.0.2",
50
+ "rimraf": "6.1.3",
51
+ "typedoc": "0.28.20",
52
+ "typescript": "@typescript/typescript6@6.0.2"
53
+ },
54
+ "engines": {
55
+ "node": ">=24"
56
+ }
57
+ }