@procedures/git 0.3.0 → 0.4.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/CHANGELOG.md CHANGED
@@ -1,5 +1,36 @@
1
1
  # @procedures/git
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 0ecc788: `git.status` and `git.commit` take `paths`, and the package root exports the git runner and a parser of `git status --porcelain=v1 -z`.
8
+
9
+ - `git.status` has two new options: `paths` (the pathspecs after `--`) and `untrackedFiles` (`--untracked-files=no|normal|all`). With `"all"`, git gives each file of a new folder. Without the options, the output does not change.
10
+ - `git.commit` has the new option `paths`. The commit then has only those paths, as they are in the working tree (`git commit -m <message> -- <paths>`). The other staged changes stay in the index.
11
+ - With `paths`, a change of a tracked file counts, staged or not. When no tracked file of the paths changed, the output has `skipped: true`. `all` and `paths` together give an error, because git refuses `-a` with paths.
12
+ - `parsePorcelainV1(output)` gives each entry with `xy`, the exact `path`, `status` and `staged`, and `from` for a rename or a copy. `classifyStatus(xy)` gives the status of two status letters.
13
+ - The root also exports `git(args, options)`, the runner of the procedures. It throws a `GitError` when git fails.
14
+
15
+ The effects of `git.status` and `git.commit` do not change.
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies [d919678]
20
+ - Updated dependencies [057d69a]
21
+ - Updated dependencies [b2a1a1e]
22
+ - Updated dependencies [057d69a]
23
+ - Updated dependencies [057d69a]
24
+ - Updated dependencies [057d69a]
25
+ - Updated dependencies [057d69a]
26
+ - Updated dependencies [057d69a]
27
+ - Updated dependencies [afd6a19]
28
+ - Updated dependencies [057d69a]
29
+ - Updated dependencies [4c51727]
30
+ - Updated dependencies [4e751da]
31
+ - @procedures/client@0.4.0
32
+ - @procedures/shell@0.4.0
33
+
3
34
  ## 0.3.0
4
35
 
5
36
  ### Minor Changes
package/README.md CHANGED
@@ -108,6 +108,10 @@ interface GitStatusInput {
108
108
  cwd?: string;
109
109
  /** Also give `lines` in the format of `git status --short` (default: false) */
110
110
  short?: boolean;
111
+ /** Only the files of these pathspecs (`git status -- <paths>`) */
112
+ paths?: string[];
113
+ /** `--untracked-files`: "no", "normal" (a new folder is one entry) or "all" (each file) */
114
+ untrackedFiles?: "no" | "normal" | "all";
111
115
  }
112
116
 
113
117
  interface GitStatusFile {
@@ -136,8 +140,15 @@ const status = await client.exec(["git", "status"], { cwd: "./my-repo" });
136
140
  console.log(`On branch ${status.branch}`);
137
141
  console.log(`${status.ahead} commits ahead, ${status.behind} behind`);
138
142
  console.log(`${status.files.length} changed files`);
143
+
144
+ // Each new file under notes/, one entry for each file
145
+ const notes = await client.exec(["git", "status"], { cwd: "./my-repo", paths: ["notes"], untrackedFiles: "all" });
139
146
  ```
140
147
 
148
+ - Without `paths` and `untrackedFiles`, the procedure starts the same git command as before.
149
+ - After `--`, git reads each path as a pathspec. A path that starts with `-` is not an option.
150
+ - Without `untrackedFiles: "all"`, git gives a new folder as one entry, for example `notes/`.
151
+
141
152
  #### `git.log`
142
153
 
143
154
  Show commit history.
@@ -347,6 +358,8 @@ interface GitCommitInput {
347
358
  all?: boolean;
348
359
  /** Amend the last commit (default: false) */
349
360
  amend?: boolean;
361
+ /** Commit only these pathspecs, as they are in the working tree (`git commit -- <paths>`) */
362
+ paths?: string[];
350
363
  /** Working directory */
351
364
  cwd?: string;
352
365
  }
@@ -370,6 +383,17 @@ const commit = await client.exec(["git", "commit"], {
370
383
  console.log(`Created commit ${commit.hash}`);
371
384
  ```
372
385
 
386
+ With `paths`, the commit has only those paths, as they are in the working tree. The other staged changes stay in the index:
387
+
388
+ ```typescript
389
+ await client.exec(["git", "add"], { paths: ["ledger/new.ndjson"] });
390
+ await client.exec(["git", "commit"], { message: "ledger: the day", paths: ["ledger"] });
391
+ ```
392
+
393
+ - With `paths`, a change of a tracked file counts, staged or not. When no tracked file of the paths changed, the output has `skipped: true`.
394
+ - git does not commit an untracked file. Add a new file with `git.add` first.
395
+ - git refuses `-a` with paths. Thus `all` and `paths` together give an error.
396
+
373
397
  #### `git.checkout`
374
398
 
375
399
  Checkout branch, tag, or restore files.
@@ -1078,17 +1102,20 @@ export async function commit(
1078
1102
 
1079
1103
  ## Configuration
1080
1104
 
1081
- ### Auto-Registration
1105
+ ### Registration
1106
+
1107
+ An import of the package root registers nothing. Import the `./register` entry to register the procedures in the global registry:
1082
1108
 
1083
- Procedures are automatically registered when the package is loaded:
1109
+ ```typescript
1110
+ import "@procedures/git/register";
1111
+ ```
1112
+
1113
+ The `client.procedures` field of `package.json` names that entry. `mark` finds the package by this field:
1084
1114
 
1085
1115
  ```json
1086
1116
  {
1087
1117
  "client": {
1088
1118
  "procedures": "./dist/register.js"
1089
- },
1090
- "scripts": {
1091
- "postinstall": "client-registry announce"
1092
1119
  }
1093
1120
  }
1094
1121
  ```
@@ -1120,6 +1147,22 @@ await gitCommit({ message: "feat: new feature", cwd: "./repo" });
1120
1147
  await gitPush({ remote: "origin", cwd: "./repo" }, { signal: AbortSignal.timeout(60_000) });
1121
1148
  ```
1122
1149
 
1150
+ ### The git runner and the porcelain parser
1151
+
1152
+ The package root also exports the functions that the procedures use:
1153
+
1154
+ - `git(args, { cwd, signal, input, env })` starts git with an argument list and gives its stdout. It throws a `GitError` when git fails.
1155
+ - `parsePorcelainV1(output)` reads the output of `git status --porcelain=v1 -z`.
1156
+ - Each entry has `xy` (the two status letters), the exact `path`, `status` and `staged`. A rename or a copy also has `from`.
1157
+ - `classifyStatus(xy)` gives the `status` and `staged` of two status letters.
1158
+
1159
+ ```typescript
1160
+ import { git, parsePorcelainV1 } from "@procedures/git";
1161
+
1162
+ const output = await git(["status", "--porcelain=v1", "-z", "--untracked-files=all", "--", "ledger"], { cwd: "./repo" });
1163
+ const untracked = parsePorcelainV1(output).filter((entry) => entry.status === "untracked");
1164
+ ```
1165
+
1123
1166
  ### Custom Registration
1124
1167
 
1125
1168
  ```typescript