@navbook/cli 0.1.2 → 0.2.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.
Files changed (167) hide show
  1. package/dist/commands/complete.js +124 -0
  2. package/dist/commands/complete.js.map +1 -0
  3. package/dist/{cli/commands → commands}/compose.js +5 -3
  4. package/dist/commands/compose.js.map +1 -0
  5. package/dist/commands/doctor.js +56 -0
  6. package/dist/commands/doctor.js.map +1 -0
  7. package/dist/commands/entity.js +235 -0
  8. package/dist/commands/entity.js.map +1 -0
  9. package/dist/commands/feature.js +202 -0
  10. package/dist/commands/feature.js.map +1 -0
  11. package/dist/commands/init.js +23 -0
  12. package/dist/commands/init.js.map +1 -0
  13. package/dist/{cli/commands → commands}/install.js +1 -2
  14. package/dist/commands/install.js.map +1 -0
  15. package/dist/commands/issue.js +89 -0
  16. package/dist/commands/issue.js.map +1 -0
  17. package/dist/commands/policy.js +49 -0
  18. package/dist/commands/policy.js.map +1 -0
  19. package/dist/commands/pr.js +262 -0
  20. package/dist/commands/pr.js.map +1 -0
  21. package/dist/context.js +21 -0
  22. package/dist/context.js.map +1 -0
  23. package/dist/{cli/editor.js → editor.js} +1 -1
  24. package/dist/editor.js.map +1 -0
  25. package/dist/errors.js.map +1 -0
  26. package/dist/install/completions.js.map +1 -0
  27. package/dist/{cli/install → install}/hook.js +1 -1
  28. package/dist/install/hook.js.map +1 -0
  29. package/dist/{cli/main.js → main.js} +10 -0
  30. package/dist/main.js.map +1 -0
  31. package/dist/{cli/program.js → program.js} +161 -23
  32. package/dist/program.js.map +1 -0
  33. package/dist/{cli/prompt.js → prompt.js} +11 -0
  34. package/dist/prompt.js.map +1 -0
  35. package/dist/render/colors.js.map +1 -0
  36. package/dist/render/detail.js +197 -0
  37. package/dist/render/detail.js.map +1 -0
  38. package/dist/render/table.js.map +1 -0
  39. package/dist/sort.js +77 -0
  40. package/dist/sort.js.map +1 -0
  41. package/package.json +15 -21
  42. package/README.md +0 -165
  43. package/dist/cli/commands/complete.d.ts +0 -9
  44. package/dist/cli/commands/complete.js +0 -72
  45. package/dist/cli/commands/complete.js.map +0 -1
  46. package/dist/cli/commands/compose.d.ts +0 -27
  47. package/dist/cli/commands/compose.js.map +0 -1
  48. package/dist/cli/commands/doctor.d.ts +0 -14
  49. package/dist/cli/commands/doctor.js +0 -127
  50. package/dist/cli/commands/doctor.js.map +0 -1
  51. package/dist/cli/commands/entity.d.ts +0 -55
  52. package/dist/cli/commands/entity.js +0 -209
  53. package/dist/cli/commands/entity.js.map +0 -1
  54. package/dist/cli/commands/init.d.ts +0 -11
  55. package/dist/cli/commands/init.js +0 -39
  56. package/dist/cli/commands/init.js.map +0 -1
  57. package/dist/cli/commands/install.d.ts +0 -17
  58. package/dist/cli/commands/install.js.map +0 -1
  59. package/dist/cli/commands/issue.d.ts +0 -12
  60. package/dist/cli/commands/issue.js +0 -42
  61. package/dist/cli/commands/issue.js.map +0 -1
  62. package/dist/cli/commands/pr.d.ts +0 -64
  63. package/dist/cli/commands/pr.js +0 -466
  64. package/dist/cli/commands/pr.js.map +0 -1
  65. package/dist/cli/commit-flow.d.ts +0 -27
  66. package/dist/cli/commit-flow.js +0 -47
  67. package/dist/cli/commit-flow.js.map +0 -1
  68. package/dist/cli/context.d.ts +0 -39
  69. package/dist/cli/context.js +0 -93
  70. package/dist/cli/context.js.map +0 -1
  71. package/dist/cli/editor.d.ts +0 -23
  72. package/dist/cli/editor.js.map +0 -1
  73. package/dist/cli/errors.d.ts +0 -17
  74. package/dist/cli/errors.js.map +0 -1
  75. package/dist/cli/history-checks.d.ts +0 -21
  76. package/dist/cli/history-checks.js +0 -134
  77. package/dist/cli/history-checks.js.map +0 -1
  78. package/dist/cli/install/completions.d.ts +0 -19
  79. package/dist/cli/install/completions.js.map +0 -1
  80. package/dist/cli/install/hook.d.ts +0 -20
  81. package/dist/cli/install/hook.js.map +0 -1
  82. package/dist/cli/main.d.ts +0 -14
  83. package/dist/cli/main.js.map +0 -1
  84. package/dist/cli/program.d.ts +0 -23
  85. package/dist/cli/program.js.map +0 -1
  86. package/dist/cli/prompt.d.ts +0 -22
  87. package/dist/cli/prompt.js.map +0 -1
  88. package/dist/cli/render/colors.d.ts +0 -13
  89. package/dist/cli/render/colors.js.map +0 -1
  90. package/dist/cli/render/detail.d.ts +0 -10
  91. package/dist/cli/render/detail.js +0 -105
  92. package/dist/cli/render/detail.js.map +0 -1
  93. package/dist/cli/render/table.d.ts +0 -19
  94. package/dist/cli/render/table.js.map +0 -1
  95. package/dist/cli/resolve.d.ts +0 -17
  96. package/dist/cli/resolve.js +0 -68
  97. package/dist/cli/resolve.js.map +0 -1
  98. package/dist/cli/workspace.d.ts +0 -52
  99. package/dist/cli/workspace.js +0 -178
  100. package/dist/cli/workspace.js.map +0 -1
  101. package/dist/core/comments.d.ts +0 -31
  102. package/dist/core/comments.js +0 -80
  103. package/dist/core/comments.js.map +0 -1
  104. package/dist/core/files.d.ts +0 -88
  105. package/dist/core/files.js +0 -441
  106. package/dist/core/files.js.map +0 -1
  107. package/dist/core/frontmatter.d.ts +0 -63
  108. package/dist/core/frontmatter.js +0 -149
  109. package/dist/core/frontmatter.js.map +0 -1
  110. package/dist/core/id.d.ts +0 -46
  111. package/dist/core/id.js +0 -66
  112. package/dist/core/id.js.map +0 -1
  113. package/dist/core/index.d.ts +0 -19
  114. package/dist/core/index.js +0 -20
  115. package/dist/core/index.js.map +0 -1
  116. package/dist/core/json.d.ts +0 -18
  117. package/dist/core/json.js +0 -51
  118. package/dist/core/json.js.map +0 -1
  119. package/dist/core/ops.d.ts +0 -92
  120. package/dist/core/ops.js +0 -173
  121. package/dist/core/ops.js.map +0 -1
  122. package/dist/core/person.d.ts +0 -20
  123. package/dist/core/person.js +0 -50
  124. package/dist/core/person.js.map +0 -1
  125. package/dist/core/query.d.ts +0 -30
  126. package/dist/core/query.js +0 -106
  127. package/dist/core/query.js.map +0 -1
  128. package/dist/core/refs.d.ts +0 -12
  129. package/dist/core/refs.js +0 -36
  130. package/dist/core/refs.js.map +0 -1
  131. package/dist/core/slug.d.ts +0 -22
  132. package/dist/core/slug.js +0 -40
  133. package/dist/core/slug.js.map +0 -1
  134. package/dist/core/time.d.ts +0 -14
  135. package/dist/core/time.js +0 -37
  136. package/dist/core/time.js.map +0 -1
  137. package/dist/core/tree.d.ts +0 -94
  138. package/dist/core/tree.js +0 -237
  139. package/dist/core/tree.js.map +0 -1
  140. package/dist/core/validate.d.ts +0 -55
  141. package/dist/core/validate.js +0 -312
  142. package/dist/core/validate.js.map +0 -1
  143. package/dist/git/config.d.ts +0 -12
  144. package/dist/git/config.js +0 -27
  145. package/dist/git/config.js.map +0 -1
  146. package/dist/git/exec.d.ts +0 -35
  147. package/dist/git/exec.js +0 -58
  148. package/dist/git/exec.js.map +0 -1
  149. package/dist/git/history.d.ts +0 -35
  150. package/dist/git/history.js +0 -82
  151. package/dist/git/history.js.map +0 -1
  152. package/dist/git/index-ops.d.ts +0 -20
  153. package/dist/git/index-ops.js +0 -45
  154. package/dist/git/index-ops.js.map +0 -1
  155. package/dist/git/merge.d.ts +0 -27
  156. package/dist/git/merge.js +0 -57
  157. package/dist/git/merge.js.map +0 -1
  158. package/dist/git/refscan.d.ts +0 -32
  159. package/dist/git/refscan.js +0 -82
  160. package/dist/git/refscan.js.map +0 -1
  161. package/dist/git/repo.d.ts +0 -45
  162. package/dist/git/repo.js +0 -95
  163. package/dist/git/repo.js.map +0 -1
  164. /package/dist/{cli/errors.js → errors.js} +0 -0
  165. /package/dist/{cli/install → install}/completions.js +0 -0
  166. /package/dist/{cli/render → render}/colors.js +0 -0
  167. /package/dist/{cli/render → render}/table.js +0 -0
@@ -1,27 +0,0 @@
1
- /**
2
- * The git configuration Navbook manages on the user's behalf.
3
- */
4
- import { git, gitMaybe } from "./exec.js";
5
- export const ALIAS_DEFAULT = "nav";
6
- export const DIRECTORY_RENAMES_KEY = "merge.directoryRenames";
7
- /** The `git nav` style alias: `git config --global alias.<name> '!nav'`. */
8
- export function aliasCommand(name) {
9
- return ["config", "--global", `alias.${name}`, "!nav"];
10
- }
11
- export function readGlobal(key) {
12
- return gitMaybe(["config", "--global", "--get", key]);
13
- }
14
- export function unsetGlobal(key) {
15
- // --unset fails with exit 5 when the key is already absent, which is fine.
16
- gitMaybe(["config", "--global", "--unset", key]);
17
- }
18
- export function readLocal(cwd, key) {
19
- return gitMaybe(["config", "--local", "--get", key], { cwd });
20
- }
21
- export function setLocal(cwd, key, value) {
22
- git(["config", "--local", key, value], { cwd });
23
- }
24
- export function unsetLocal(cwd, key) {
25
- gitMaybe(["config", "--local", "--unset", key], { cwd });
26
- }
27
- //# sourceMappingURL=config.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/git/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE1C,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,CAAC;AACnC,MAAM,CAAC,MAAM,qBAAqB,GAAG,wBAAwB,CAAC;AAE9D,4EAA4E;AAC5E,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,OAAO,CAAC,QAAQ,EAAE,UAAU,EAAE,SAAS,IAAI,EAAE,EAAE,MAAM,CAAC,CAAC;AACzD,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,GAAW;IACpC,OAAO,QAAQ,CAAC,CAAC,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;AACxD,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,GAAW;IACrC,2EAA2E;IAC3E,QAAQ,CAAC,CAAC,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,CAAC,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,GAAW,EAAE,GAAW;IAChD,OAAO,QAAQ,CAAC,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;AAChE,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,GAAW,EAAE,GAAW,EAAE,KAAa;IAC9D,GAAG,CAAC,CAAC,QAAQ,EAAE,SAAS,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,GAAW,EAAE,GAAW;IACjD,QAAQ,CAAC,CAAC,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;AAC3D,CAAC"}
@@ -1,35 +0,0 @@
1
- /**
2
- * The single choke point for talking to git.
3
- *
4
- * Navbook shells out to the `git` binary rather than linking a library, so the
5
- * CLI's git behavior is definitionally the user's git (spec 05 §5.2).
6
- */
7
- export interface GitResult {
8
- code: number;
9
- stdout: string;
10
- stderr: string;
11
- }
12
- export interface GitOptions {
13
- cwd?: string;
14
- input?: string;
15
- /** Extra environment entries layered over a locale-neutral base. */
16
- env?: NodeJS.ProcessEnv;
17
- /** Allow output larger than the default 10 MB buffer. */
18
- maxBuffer?: number;
19
- }
20
- export declare class GitError extends Error {
21
- readonly code: number;
22
- readonly stderr: string;
23
- readonly args: string[];
24
- constructor(args: string[], result: GitResult);
25
- }
26
- /** Run git and return its result without throwing. */
27
- export declare function gitRun(args: string[], opts?: GitOptions): GitResult;
28
- /** Run git, throwing {@link GitError} on a non-zero exit. */
29
- export declare function git(args: string[], opts?: GitOptions): string;
30
- /** Run git and return trimmed stdout, or null when the command fails. */
31
- export declare function gitMaybe(args: string[], opts?: GitOptions): string | null;
32
- /** Split NUL-delimited git output into entries, dropping the trailing blank. */
33
- export declare function splitNul(output: string): string[];
34
- /** Split line-oriented git output, dropping the trailing blank. */
35
- export declare function splitLines(output: string): string[];
package/dist/git/exec.js DELETED
@@ -1,58 +0,0 @@
1
- /**
2
- * The single choke point for talking to git.
3
- *
4
- * Navbook shells out to the `git` binary rather than linking a library, so the
5
- * CLI's git behavior is definitionally the user's git (spec 05 §5.2).
6
- */
7
- import { spawnSync } from "node:child_process";
8
- export class GitError extends Error {
9
- code;
10
- stderr;
11
- args;
12
- constructor(args, result) {
13
- super(`git ${args.join(" ")} failed (exit ${result.code}): ${result.stderr.trim()}`);
14
- this.name = "GitError";
15
- this.code = result.code;
16
- this.stderr = result.stderr;
17
- this.args = args;
18
- }
19
- }
20
- /** Run git and return its result without throwing. */
21
- export function gitRun(args, opts = {}) {
22
- const result = spawnSync("git", args, {
23
- cwd: opts.cwd,
24
- input: opts.input,
25
- encoding: "utf8",
26
- maxBuffer: opts.maxBuffer ?? 64 * 1024 * 1024,
27
- env: { ...process.env, LC_ALL: "C", GIT_PAGER: "cat", ...opts.env },
28
- });
29
- if (result.error) {
30
- const err = result.error;
31
- if (err.code === "ENOENT") {
32
- throw new Error("git was not found on PATH; Navbook requires a working git installation");
33
- }
34
- throw result.error;
35
- }
36
- return { code: result.status ?? 1, stdout: result.stdout ?? "", stderr: result.stderr ?? "" };
37
- }
38
- /** Run git, throwing {@link GitError} on a non-zero exit. */
39
- export function git(args, opts = {}) {
40
- const result = gitRun(args, opts);
41
- if (result.code !== 0)
42
- throw new GitError(args, result);
43
- return result.stdout;
44
- }
45
- /** Run git and return trimmed stdout, or null when the command fails. */
46
- export function gitMaybe(args, opts = {}) {
47
- const result = gitRun(args, opts);
48
- return result.code === 0 ? result.stdout.trim() : null;
49
- }
50
- /** Split NUL-delimited git output into entries, dropping the trailing blank. */
51
- export function splitNul(output) {
52
- return output.split("\0").filter((entry) => entry !== "");
53
- }
54
- /** Split line-oriented git output, dropping the trailing blank. */
55
- export function splitLines(output) {
56
- return output.split("\n").filter((line) => line !== "");
57
- }
58
- //# sourceMappingURL=exec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"exec.js","sourceRoot":"","sources":["../../src/git/exec.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OA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ACD,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,EAAE,EAAE,CAAC;AAChG,CAAC;AAED,6DAA6D;AAC7D,MAAM,UAAU,GAAG,CAAC,IAAc,EAAE,OAAmB,EAAE;IACvD,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAClC,IAAI,MAAM,CAAC,IAAI,KAAK,CAAC;QAAE,MAAM,IAAI,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACxD,OAAO,MAAM,CAAC,MAAM,CAAC;AACvB,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,QAAQ,CAAC,IAAc,EAAE,OAAmB,EAAE;IAC5D,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAClC,OAAO,MAAM,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AACzD,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,QAAQ,CAAC,MAAc;IACrC,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC;AAC5D,CAAC;AAED,mEAAmE;AACnE,MAAM,UAAU,UAAU,CAAC,MAAc;IACvC,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC;AAC1D,CAAC"}
@@ -1,35 +0,0 @@
1
- /**
2
- * Reading history, for the doctor checks that cannot be decided from the tree
3
- * alone (D7, D9, D10) and for pinning pull-request revisions.
4
- */
5
- export interface FileVersion {
6
- sha: string;
7
- /** The file's path in that commit, which a rename may have changed. */
8
- path: string;
9
- authored: Date;
10
- }
11
- /**
12
- * Every commit that touched `path`, oldest first, following renames.
13
- *
14
- * `--follow` reports the path as it stood at each commit, which is what makes a
15
- * `pr.md` readable across its move from `prs/open/` to `prs/merged/`.
16
- */
17
- export declare function fileVersions(cwd: string, path: string): FileVersion[];
18
- /** File contents at a commit, or null when the path did not exist there. */
19
- export declare function blobAt(cwd: string, sha: string, path: string): string | null;
20
- /** The commit that introduced `path`, following renames. */
21
- export declare function addedAt(cwd: string, path: string): FileVersion | null;
22
- /** True when `ancestor` is an ancestor of `descendant` (or the same commit). */
23
- export declare function isAncestor(cwd: string, ancestor: string, descendant: string): boolean;
24
- /** The merge base of two revisions, or null when they share no history. */
25
- export declare function mergeBase(cwd: string, a: string, b: string): string | null;
26
- /** True when the object exists locally; false for an unfetched commit. */
27
- export declare function objectExists(cwd: string, sha: string): boolean;
28
- /** Commit messages of the given revision range, newest first. */
29
- export declare function commitMessages(cwd: string, range: string, limit?: number): string[];
30
- /** Branch names that contain the given commit. */
31
- export declare function branchesContaining(cwd: string, sha: string): string[];
32
- /** Author date of a commit. */
33
- export declare function authoredAt(cwd: string, sha: string): Date | null;
34
- /** Resolve a revision, throwing a useful message when it does not exist. */
35
- export declare function requireSha(cwd: string, rev: string): string;
@@ -1,82 +0,0 @@
1
- /**
2
- * Reading history, for the doctor checks that cannot be decided from the tree
3
- * alone (D7, D9, D10) and for pinning pull-request revisions.
4
- */
5
- import { git, gitMaybe, gitRun, splitLines } from "./exec.js";
6
- /** ASCII SOH/STX: separators that cannot occur in a commit message or path. */
7
- const RECORD_SEPARATOR = "\u0001";
8
- const FIELD_SEPARATOR = "\u0002";
9
- /**
10
- * Every commit that touched `path`, oldest first, following renames.
11
- *
12
- * `--follow` reports the path as it stood at each commit, which is what makes a
13
- * `pr.md` readable across its move from `prs/open/` to `prs/merged/`.
14
- */
15
- export function fileVersions(cwd, path) {
16
- const output = gitMaybe(["log", "--follow", "--name-only", "--format=%x01%H%x02%aI", "--", path], { cwd });
17
- if (output === null)
18
- return [];
19
- const versions = [];
20
- for (const record of output.split(RECORD_SEPARATOR)) {
21
- if (record.trim() === "")
22
- continue;
23
- const [header, ...rest] = record.split("\n");
24
- const [sha, authored] = (header ?? "").split(FIELD_SEPARATOR);
25
- if (!sha || !authored)
26
- continue;
27
- const names = rest.filter((line) => line.trim() !== "");
28
- const date = new Date(authored);
29
- if (Number.isNaN(date.getTime()))
30
- continue;
31
- versions.push({ sha, path: names[0] ?? path, authored: date });
32
- }
33
- return versions.reverse();
34
- }
35
- /** File contents at a commit, or null when the path did not exist there. */
36
- export function blobAt(cwd, sha, path) {
37
- const result = gitRun(["show", `${sha}:${path}`], { cwd });
38
- return result.code === 0 ? result.stdout : null;
39
- }
40
- /** The commit that introduced `path`, following renames. */
41
- export function addedAt(cwd, path) {
42
- return fileVersions(cwd, path)[0] ?? null;
43
- }
44
- /** True when `ancestor` is an ancestor of `descendant` (or the same commit). */
45
- export function isAncestor(cwd, ancestor, descendant) {
46
- return gitRun(["merge-base", "--is-ancestor", ancestor, descendant], { cwd }).code === 0;
47
- }
48
- /** The merge base of two revisions, or null when they share no history. */
49
- export function mergeBase(cwd, a, b) {
50
- return gitMaybe(["merge-base", a, b], { cwd });
51
- }
52
- /** True when the object exists locally; false for an unfetched commit. */
53
- export function objectExists(cwd, sha) {
54
- return gitRun(["cat-file", "-e", `${sha}^{commit}`], { cwd }).code === 0;
55
- }
56
- /** Commit messages of the given revision range, newest first. */
57
- export function commitMessages(cwd, range, limit = 100) {
58
- const output = gitMaybe(["log", "--format=%B%x00", "-n", String(limit), range], { cwd });
59
- if (output === null)
60
- return [];
61
- return output.split("\0").filter((message) => message.trim() !== "");
62
- }
63
- /** Branch names that contain the given commit. */
64
- export function branchesContaining(cwd, sha) {
65
- const output = gitMaybe(["branch", "--all", "--format=%(refname:short)", "--contains", sha], {
66
- cwd,
67
- });
68
- return output === null ? [] : splitLines(output);
69
- }
70
- /** Author date of a commit. */
71
- export function authoredAt(cwd, sha) {
72
- const value = gitMaybe(["show", "-s", "--format=%aI", sha], { cwd });
73
- if (value === null)
74
- return null;
75
- const date = new Date(value);
76
- return Number.isNaN(date.getTime()) ? null : date;
77
- }
78
- /** Resolve a revision, throwing a useful message when it does not exist. */
79
- export function requireSha(cwd, rev) {
80
- return git(["rev-parse", "--verify", `${rev}^{commit}`], { cwd }).trim();
81
- }
82
- //# sourceMappingURL=history.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"history.js","sourceRoot":"","sources":["../../src/git/history.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE9D,+EAA+E;AAC/E,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAClC,MAAM,eAAe,GAAG,QAAQ,CAAC;AASjC;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,GAAW,EAAE,IAAY;IACpD,MAAM,MAAM,GAAG,QAAQ,CACrB,CAAC,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,wBAAwB,EAAE,IAAI,EAAE,IAAI,CAAC,EACxE,EAAE,GAAG,EAAE,CACR,CAAC;IACF,IAAI,MAAM,KAAK,IAAI;QAAE,OAAO,EAAE,CAAC;IAE/B,MAAM,QAAQ,GAAkB,EAAE,CAAC;IACnC,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC,EAAE,CAAC;QACpD,IAAI,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE;YAAE,SAAS;QACnC,MAAM,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC7C,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,e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B,MAAM,UAAU,UAAU,CAAC,GAAW,EAAE,GAAW;IACjD,MAAM,KAAK,GAAG,QAAQ,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;IACrE,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAChC,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;IAC7B,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;AACpD,CAAC;AAED,4EAA4E;AAC5E,MAAM,UAAU,UAAU,CAAC,GAAW,EAAE,GAAW;IACjD,OAAO,GAAG,CAAC,CAAC,WAAW,EAAE,UAAU,EAAE,GAAG,GAAG,WAAW,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;AAC3E,CAAC"}
@@ -1,20 +0,0 @@
1
- /**
2
- * Index and commit operations.
3
- */
4
- import type { Trailer } from "../core/ops.ts";
5
- /** Repository-relative paths currently staged in the index. */
6
- export declare function stagedPaths(cwd: string): string[];
7
- /** Contents of a staged file, or null when it is not in the index. */
8
- export declare function stagedContent(cwd: string, path: string): string | null;
9
- /** Repository-relative paths of every file in the index. */
10
- export declare function indexPaths(cwd: string): string[];
11
- /** Stage the given paths, including deletions. */
12
- export declare function add(cwd: string, paths: readonly string[]): void;
13
- /** Move a tracked path, staging the rename. */
14
- export declare function move(cwd: string, from: string, to: string): void;
15
- /** Compose a commit message from a subject and its trailers. */
16
- export declare function composeMessage(subject: string, trailers: readonly Trailer[]): string;
17
- /** Create a commit from what is currently staged. */
18
- export declare function commit(cwd: string, message: string, opts?: {
19
- allowEmpty?: boolean;
20
- }): string;
@@ -1,45 +0,0 @@
1
- /**
2
- * Index and commit operations.
3
- */
4
- import { git, gitRun, splitNul } from "./exec.js";
5
- /** Repository-relative paths currently staged in the index. */
6
- export function stagedPaths(cwd) {
7
- const head = gitRun(["rev-parse", "--verify", "--quiet", "HEAD"], { cwd });
8
- const args = head.code === 0 ? ["diff", "--cached", "--name-only", "-z"] : ["ls-files", "--cached", "-z"];
9
- return splitNul(git(args, { cwd }));
10
- }
11
- /** Contents of a staged file, or null when it is not in the index. */
12
- export function stagedContent(cwd, path) {
13
- const result = gitRun(["show", `:${path}`], { cwd });
14
- return result.code === 0 ? result.stdout : null;
15
- }
16
- /** Repository-relative paths of every file in the index. */
17
- export function indexPaths(cwd) {
18
- return splitNul(git(["ls-files", "--cached", "-z"], { cwd }));
19
- }
20
- /** Stage the given paths, including deletions. */
21
- export function add(cwd, paths) {
22
- if (paths.length === 0)
23
- return;
24
- git(["add", "--all", "--", ...paths], { cwd });
25
- }
26
- /** Move a tracked path, staging the rename. */
27
- export function move(cwd, from, to) {
28
- git(["mv", "--", from, to], { cwd });
29
- }
30
- /** Compose a commit message from a subject and its trailers. */
31
- export function composeMessage(subject, trailers) {
32
- if (trailers.length === 0)
33
- return `${subject}\n`;
34
- const lines = trailers.map((t) => `${t.key}: ${t.id}`);
35
- return `${subject}\n\n${lines.join("\n")}\n`;
36
- }
37
- /** Create a commit from what is currently staged. */
38
- export function commit(cwd, message, opts = {}) {
39
- const args = ["commit", "--quiet", "-m", message];
40
- if (opts.allowEmpty)
41
- args.push("--allow-empty");
42
- git(args, { cwd });
43
- return git(["rev-parse", "HEAD"], { cwd }).trim();
44
- }
45
- //# sourceMappingURL=index-ops.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-ops.js","sourceRoot":"","sources":["../../src/git/index-ops.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAElD,+DAA+D;AAC/D,MAAM,UAAU,WAAW,CAAC,GAAW;IACrC,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,WAAW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AE,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;AACvC,CAAC;AAED,gEAAgE;AAChE,MAAM,UAAU,cAAc,CAAC,OAAe,EAAE,QAA4B;IAC1E,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,GAAG,OAAO,IAAI,CAAC;IACjD,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACvD,OAAO,GAAG,OAAO,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;AAC/C,CAAC;AAED,qDAAqD;AACrD,MAAM,UAAU,MAAM,CAAC,GAAW,EAAE,OAAe,EAAE,OAAiC,EAAE;IACtF,MAAM,IAAI,GAAG,CAAC,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAClD,IAAI,IAAI,CAAC,UAAU;QAAE,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IAChD,GAAG,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;IACnB,OAAO,GAAG,CAAC,CAAC,WAAW,EAAE,MAAM,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;AACpD,CAAC"}
@@ -1,27 +0,0 @@
1
- /**
2
- * Merging, for `nav pr merge`.
3
- *
4
- * The PR directory has to move into `prs/merged/` as part of the merge that
5
- * lands the branch, so the merge is performed with `--no-commit` and committed
6
- * only after the move is staged (spec 02 §2.8).
7
- */
8
- export type MergeOutcome = "up-to-date" | "fast-forward" | "staged" | "conflict";
9
- /** True when merging `source` into HEAD would just move the branch pointer. */
10
- export declare function canFastForward(cwd: string, source: string): boolean;
11
- /** True when `source` is already contained in HEAD. */
12
- export declare function isAlreadyMerged(cwd: string, source: string): boolean;
13
- /** Fast-forward HEAD to `source`. */
14
- export declare function fastForward(cwd: string, source: string): void;
15
- /**
16
- * Start a real merge commit without completing it, leaving the result staged so
17
- * the caller can add the PR directory move before committing.
18
- */
19
- export declare function mergeNoCommit(cwd: string, source: string): MergeOutcome;
20
- /** Complete an in-progress merge with an explicit message. */
21
- export declare function commitMerge(cwd: string, message: string): string;
22
- /** Abandon an in-progress merge. */
23
- export declare function abortMerge(cwd: string): void;
24
- /** Paths git could not merge automatically. */
25
- export declare function conflictedPaths(cwd: string): string[];
26
- /** The commit being merged in, read from MERGE_HEAD. */
27
- export declare function mergeHead(cwd: string): string | null;
package/dist/git/merge.js DELETED
@@ -1,57 +0,0 @@
1
- /**
2
- * Merging, for `nav pr merge`.
3
- *
4
- * The PR directory has to move into `prs/merged/` as part of the merge that
5
- * lands the branch, so the merge is performed with `--no-commit` and committed
6
- * only after the move is staged (spec 02 §2.8).
7
- */
8
- import { git, gitRun } from "./exec.js";
9
- import { isAncestor } from "./history.js";
10
- /** True when merging `source` into HEAD would just move the branch pointer. */
11
- export function canFastForward(cwd, source) {
12
- const head = git(["rev-parse", "HEAD"], { cwd }).trim();
13
- const tip = git(["rev-parse", `${source}^{commit}`], { cwd }).trim();
14
- return isAncestor(cwd, head, tip);
15
- }
16
- /** True when `source` is already contained in HEAD. */
17
- export function isAlreadyMerged(cwd, source) {
18
- const head = git(["rev-parse", "HEAD"], { cwd }).trim();
19
- const tip = git(["rev-parse", `${source}^{commit}`], { cwd }).trim();
20
- return isAncestor(cwd, tip, head);
21
- }
22
- /** Fast-forward HEAD to `source`. */
23
- export function fastForward(cwd, source) {
24
- git(["merge", "--ff-only", "--quiet", source], { cwd });
25
- }
26
- /**
27
- * Start a real merge commit without completing it, leaving the result staged so
28
- * the caller can add the PR directory move before committing.
29
- */
30
- export function mergeNoCommit(cwd, source) {
31
- const result = gitRun(["merge", "--no-ff", "--no-commit", "--quiet", source], { cwd });
32
- if (result.code === 0)
33
- return "staged";
34
- return "conflict";
35
- }
36
- /** Complete an in-progress merge with an explicit message. */
37
- export function commitMerge(cwd, message) {
38
- git(["commit", "--quiet", "--no-edit", "-m", message], { cwd });
39
- return git(["rev-parse", "HEAD"], { cwd }).trim();
40
- }
41
- /** Abandon an in-progress merge. */
42
- export function abortMerge(cwd) {
43
- gitRun(["merge", "--abort"], { cwd });
44
- }
45
- /** Paths git could not merge automatically. */
46
- export function conflictedPaths(cwd) {
47
- const result = gitRun(["diff", "--name-only", "--diff-filter=U"], { cwd });
48
- if (result.code !== 0)
49
- return [];
50
- return result.stdout.split("\n").filter((line) => line !== "");
51
- }
52
- /** The commit being merged in, read from MERGE_HEAD. */
53
- export function mergeHead(cwd) {
54
- const result = gitRun(["rev-parse", "--verify", "--quiet", "MERGE_HEAD"], { cwd });
55
- return result.code === 0 ? result.stdout.trim() : null;
56
- }
57
- //# sourceMappingURL=merge.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"merge.js","sourceRoot":"","sources":["../../src/git/merge.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAI1C,+EAA+E;AAC/E,MAAM,UAAU,cAAc,CAAC,GAAW,EAAE,MAAc;IACxD,MAAM,IAAI,GAAG,GAAG,CAAC,CAAC,WAAW,EAAE,MAAM,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACxD,MAAM,GAAG,GAAG,GAAG,CAAC,CAAC,WAAW,EAAE,GAAG,MAAM,WAAW,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACrE,OAAO,UAAU,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;AACpC,CAAC;AAED,uDAAuD;AACvD,MAAM,UAAU,eAAe,CAAC,GAAW,EAAE,MAAc;IACzD,MAAM,IAAI,GAAG,GAAG,CAAC,CAAC,WAAW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AAC/C,MAAM,UAAU,eAAe,CAAC,GAAW;IACzC,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,MAAM,EAAE,aAAa,EAAE,iBAAiB,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;IAC3E,IAAI,MAAM,CAAC,IAAI,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IACjC,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC;AACjE,CAAC;AAED,wDAAwD;AACxD,MAAM,UAAU,SAAS,CAAC,GAAW;IACnC,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;IACnF,OAAO,MAAM,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AACzD,CAAC"}
@@ -1,32 +0,0 @@
1
- /**
2
- * Reading `.navbook/` out of branches that are not checked out.
3
- *
4
- * A pull request's files live on the branch it proposes to merge (spec 03
5
- * §3.5), so listing open PRs means enumerating refs, not walking the working
6
- * tree. Blobs are read through a single `git cat-file --batch` process so the
7
- * cost is one subprocess rather than one per file.
8
- */
9
- export interface Ref {
10
- /** Full ref name, e.g. `refs/heads/feat/auth`. */
11
- full: string;
12
- /** Short name, e.g. `feat/auth` or `origin/feat/auth`. */
13
- short: string;
14
- remote: boolean;
15
- }
16
- /** Local branches and fetched remote branches, excluding symbolic refs. */
17
- export declare function listBranchRefs(cwd: string): Ref[];
18
- /** Entries directly inside `dir` at `ref`; empty when the path does not exist. */
19
- export declare function lsTreeNames(cwd: string, ref: string, dir: string): string[];
20
- /** Every file path under `dir` at `ref`, recursively. */
21
- export declare function lsTreeRecursive(cwd: string, ref: string, dir: string): string[];
22
- export interface BlobRequest {
23
- ref: string;
24
- path: string;
25
- }
26
- /**
27
- * Read many blobs in one `git cat-file --batch` process.
28
- *
29
- * Results are keyed `<ref>:<path>`; missing objects are simply absent, which is
30
- * the normal case for a branch that has no `.navbook/` at all.
31
- */
32
- export declare function catBlobs(cwd: string, requests: readonly BlobRequest[]): Map<string, string>;
@@ -1,82 +0,0 @@
1
- /**
2
- * Reading `.navbook/` out of branches that are not checked out.
3
- *
4
- * A pull request's files live on the branch it proposes to merge (spec 03
5
- * §3.5), so listing open PRs means enumerating refs, not walking the working
6
- * tree. Blobs are read through a single `git cat-file --batch` process so the
7
- * cost is one subprocess rather than one per file.
8
- */
9
- import { spawnSync } from "node:child_process";
10
- import { gitMaybe, splitLines, splitNul } from "./exec.js";
11
- /** Local branches and fetched remote branches, excluding symbolic refs. */
12
- export function listBranchRefs(cwd) {
13
- const output = gitMaybe([
14
- "for-each-ref",
15
- "--format=%(refname)%00%(refname:short)%00%(symref)",
16
- "refs/heads",
17
- "refs/remotes",
18
- ], { cwd });
19
- if (output === null)
20
- return [];
21
- const refs = [];
22
- for (const line of splitLines(output)) {
23
- const [full, short, symref] = line.split("\0");
24
- if (!full || !short)
25
- continue;
26
- // Skip origin/HEAD and friends: they duplicate a branch already listed.
27
- if (symref !== undefined && symref !== "")
28
- continue;
29
- refs.push({ full, short, remote: full.startsWith("refs/remotes/") });
30
- }
31
- return refs;
32
- }
33
- /** Entries directly inside `dir` at `ref`; empty when the path does not exist. */
34
- export function lsTreeNames(cwd, ref, dir) {
35
- const output = gitMaybe(["ls-tree", "--name-only", "-z", `${ref}:${dir}`], { cwd });
36
- return output === null ? [] : splitNul(output).map((name) => name.replace(/\/$/, ""));
37
- }
38
- /** Every file path under `dir` at `ref`, recursively. */
39
- export function lsTreeRecursive(cwd, ref, dir) {
40
- const output = gitMaybe(["ls-tree", "-r", "--name-only", "-z", `${ref}:${dir}`], { cwd });
41
- return output === null ? [] : splitNul(output);
42
- }
43
- /**
44
- * Read many blobs in one `git cat-file --batch` process.
45
- *
46
- * Results are keyed `<ref>:<path>`; missing objects are simply absent, which is
47
- * the normal case for a branch that has no `.navbook/` at all.
48
- */
49
- export function catBlobs(cwd, requests) {
50
- const out = new Map();
51
- if (requests.length === 0)
52
- return out;
53
- const specs = requests.map((request) => `${request.ref}:${request.path}`);
54
- // No `encoding` option: stdout must stay a Buffer, because the batch protocol
55
- // frames each blob by byte length rather than by any text delimiter.
56
- const result = spawnSync("git", ["cat-file", "--batch"], {
57
- cwd,
58
- input: `${specs.join("\n")}\n`,
59
- maxBuffer: 256 * 1024 * 1024,
60
- env: { ...process.env, LC_ALL: "C" },
61
- });
62
- if (result.error || result.status !== 0)
63
- return out;
64
- const stdout = result.stdout;
65
- let offset = 0;
66
- for (const spec of specs) {
67
- const newline = stdout.indexOf(0x0a, offset);
68
- if (newline === -1)
69
- break;
70
- const header = stdout.subarray(offset, newline).toString("utf8");
71
- offset = newline + 1;
72
- // A missing object reports "<spec> missing" and consumes no body.
73
- const parts = header.split(" ");
74
- const size = Number(parts[2]);
75
- if (parts.length < 3 || Number.isNaN(size))
76
- continue;
77
- out.set(spec, stdout.subarray(offset, offset + size).toString("utf8"));
78
- offset += size + 1; // the body is followed by a newline
79
- }
80
- return out;
81
- }
82
- //# sourceMappingURL=refscan.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"refscan.js","sourceRoot":"","sources":["../../src/git/refscan.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAU3D,2EAA2E;AAC3E,MAAM,UAAU,cAAc,CAAC,GAAW;IACxC,MAAM,MAAM,GAAG,QAAQ,CACrB;QACE,cAAc;QACd,oDAAoD;QACpD,YAAY;QACZ,cAAc;KACf,EACD,EAAE,GAAG,EAAE,CACR,CAAC;I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QAAQ,CAAC,MAAM,CAAC,CAAC;QACjE,MAAM,GAAG,OAAO,GAAG,CAAC,CAAC;QAErB,kEAAkE;QAClE,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAChC,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAC9B,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;YAAE,SAAS;QAErD,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;QACvE,MAAM,IAAI,IAAI,GAAG,CAAC,CAAC,CAAC,oCAAoC;IAC1D,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -1,45 +0,0 @@
1
- /**
2
- * Repository discovery and identity.
3
- *
4
- * `.navbook/` always sits at the repository root (spec 02 §2.1), so "walk up
5
- * like git does" and "ask git for the top level" are the same answer.
6
- */
7
- export declare const NAVBOOK_DIR = ".navbook";
8
- export interface RepoPaths {
9
- repoRoot: string;
10
- navRoot: string;
11
- hasNavbook: boolean;
12
- }
13
- export declare class NotARepositoryError extends Error {
14
- }
15
- /** Locate the repository root containing `cwd`, and its `.navbook/` directory. */
16
- export declare function findRepo(cwd: string): RepoPaths;
17
- /** Current branch name, or null when HEAD is detached. */
18
- export declare function currentBranch(cwd: string): string | null;
19
- /** Resolve a revision to a full 40-hex SHA, or null when it does not exist. */
20
- export declare function resolveSha(cwd: string, rev: string): string | null;
21
- /** True when the repository has at least one commit. */
22
- export declare function hasCommits(cwd: string): boolean;
23
- /**
24
- * The repository's default branch — the tracker of record (spec 03 §3.1).
25
- *
26
- * Prefers what `origin/HEAD` designates, then a configured `init.defaultBranch`
27
- * that actually exists, then conventional names, then the current branch.
28
- */
29
- export declare function defaultBranch(cwd: string): string | null;
30
- export interface Identity {
31
- name?: string;
32
- email: string;
33
- }
34
- export declare class MissingIdentityError extends Error {
35
- }
36
- /** Author identity from `git config user.name` / `user.email` (spec 04 §4.2). */
37
- export declare function userIdentity(cwd: string): Identity;
38
- /** True when the working tree and index have no changes at all. */
39
- export declare function isTreeClean(cwd: string): boolean;
40
- /** True when a merge is currently in progress. */
41
- export declare function isMergeInProgress(cwd: string): boolean;
42
- /** Absolute path of the repository's git directory. */
43
- export declare function gitDir(cwd: string): string;
44
- /** Absolute path of the hooks directory git will actually use. */
45
- export declare function hooksDir(cwd: string): string;