@optique/git 0.9.0-dev.268 → 0.9.0-dev.272
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/README.md +17 -17
- package/dist/index.cjs +16 -18
- package/dist/index.js +16 -18
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@ Quick start
|
|
|
31
31
|
~~~~ typescript
|
|
32
32
|
import { gitBranch, gitTag, gitCommit } from "@optique/git";
|
|
33
33
|
import { argument, option, object } from "@optique/core/primitives";
|
|
34
|
-
import {
|
|
34
|
+
import { parseAsync } from "@optique/core/parser";
|
|
35
35
|
|
|
36
36
|
const parser = object({
|
|
37
37
|
branch: argument(gitBranch()),
|
|
@@ -39,7 +39,7 @@ const parser = object({
|
|
|
39
39
|
commit: option("-c", "--commit", gitCommit()),
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
-
const result = await
|
|
42
|
+
const result = await parseAsync(parser, ["feature/login"]);
|
|
43
43
|
// result.success === true
|
|
44
44
|
// result.value.branch === "feature/login"
|
|
45
45
|
~~~~
|
|
@@ -54,7 +54,7 @@ Use `createGitParsers()` to create parsers for a different repository:
|
|
|
54
54
|
~~~~ typescript
|
|
55
55
|
import { createGitParsers } from "@optique/git";
|
|
56
56
|
import { argument, object } from "@optique/core/primitives";
|
|
57
|
-
import {
|
|
57
|
+
import { parseAsync } from "@optique/core/parser";
|
|
58
58
|
|
|
59
59
|
const git = createGitParsers({ dir: "/path/to/repo" });
|
|
60
60
|
|
|
@@ -63,7 +63,7 @@ const parser = object({
|
|
|
63
63
|
tag: option("-t", "--tag", git.tag()),
|
|
64
64
|
});
|
|
65
65
|
|
|
66
|
-
const result = await
|
|
66
|
+
const result = await parseAsync(parser, ["v1.0.0"]);
|
|
67
67
|
// result.success === true
|
|
68
68
|
// result.value.tag === "v1.0.0"
|
|
69
69
|
~~~~
|
|
@@ -80,13 +80,13 @@ existing branch in the repository.
|
|
|
80
80
|
~~~~ typescript
|
|
81
81
|
import { gitBranch } from "@optique/git";
|
|
82
82
|
import { argument, object } from "@optique/core/primitives";
|
|
83
|
-
import {
|
|
83
|
+
import { parseAsync } from "@optique/core/parser";
|
|
84
84
|
|
|
85
85
|
const parser = object({
|
|
86
86
|
branch: argument(gitBranch()),
|
|
87
87
|
});
|
|
88
88
|
|
|
89
|
-
const result = await
|
|
89
|
+
const result = await parseAsync(parser, ["main"]);
|
|
90
90
|
// Valid branch
|
|
91
91
|
~~~~
|
|
92
92
|
|
|
@@ -103,13 +103,13 @@ existing branch on the specified remote.
|
|
|
103
103
|
~~~~ typescript
|
|
104
104
|
import { gitRemoteBranch } from "@optique/git";
|
|
105
105
|
import { option, object } from "@optique/core/primitives";
|
|
106
|
-
import {
|
|
106
|
+
import { parseAsync } from "@optique/core/parser";
|
|
107
107
|
|
|
108
108
|
const parser = object({
|
|
109
109
|
branch: option("-b", "--branch", gitRemoteBranch("origin")),
|
|
110
110
|
});
|
|
111
111
|
|
|
112
|
-
const result = await
|
|
112
|
+
const result = await parseAsync(parser, ["--branch=main"]);
|
|
113
113
|
// Valid remote branch on origin
|
|
114
114
|
~~~~
|
|
115
115
|
|
|
@@ -122,13 +122,13 @@ in the repository.
|
|
|
122
122
|
~~~~ typescript
|
|
123
123
|
import { gitTag } from "@optique/git";
|
|
124
124
|
import { option, object } from "@optique/core/primitives";
|
|
125
|
-
import {
|
|
125
|
+
import { parseAsync } from "@optique/core/parser";
|
|
126
126
|
|
|
127
127
|
const parser = object({
|
|
128
128
|
tag: option("-t", "--tag", gitTag()),
|
|
129
129
|
});
|
|
130
130
|
|
|
131
|
-
const result = await
|
|
131
|
+
const result = await parseAsync(parser, ["--tag=v1.0.0"]);
|
|
132
132
|
// Valid tag
|
|
133
133
|
~~~~
|
|
134
134
|
|
|
@@ -141,13 +141,13 @@ remote in the repository.
|
|
|
141
141
|
~~~~ typescript
|
|
142
142
|
import { gitRemote } from "@optique/git";
|
|
143
143
|
import { option, object } from "@optique/core/primitives";
|
|
144
|
-
import {
|
|
144
|
+
import { parseAsync } from "@optique/core/parser";
|
|
145
145
|
|
|
146
146
|
const parser = object({
|
|
147
147
|
remote: option("-r", "--remote", gitRemote()),
|
|
148
148
|
});
|
|
149
149
|
|
|
150
|
-
const result = await
|
|
150
|
+
const result = await parseAsync(parser, ["--remote=origin"]);
|
|
151
151
|
// Valid remote
|
|
152
152
|
~~~~
|
|
153
153
|
|
|
@@ -160,13 +160,13 @@ A value parser for commit SHAs. Validates that the input is a valid commit SHA
|
|
|
160
160
|
~~~~ typescript
|
|
161
161
|
import { gitCommit } from "@optique/git";
|
|
162
162
|
import { option, object } from "@optique/core/primitives";
|
|
163
|
-
import {
|
|
163
|
+
import { parseAsync } from "@optique/core/parser";
|
|
164
164
|
|
|
165
165
|
const parser = object({
|
|
166
166
|
commit: option("-c", "--commit", gitCommit()),
|
|
167
167
|
});
|
|
168
168
|
|
|
169
|
-
const result = await
|
|
169
|
+
const result = await parseAsync(parser, ["--commit=abc1234"]);
|
|
170
170
|
// Valid commit SHA
|
|
171
171
|
~~~~
|
|
172
172
|
|
|
@@ -179,13 +179,13 @@ that the input resolves to a valid Git reference.
|
|
|
179
179
|
~~~~ typescript
|
|
180
180
|
import { gitRef } from "@optique/git";
|
|
181
181
|
import { option, object } from "@optique/core/primitives";
|
|
182
|
-
import {
|
|
182
|
+
import { parseAsync } from "@optique/core/parser";
|
|
183
183
|
|
|
184
184
|
const parser = object({
|
|
185
185
|
ref: option("--ref", gitRef()),
|
|
186
186
|
});
|
|
187
187
|
|
|
188
|
-
const result = await
|
|
188
|
+
const result = await parseAsync(parser, ["--ref=v1.0.0"]);
|
|
189
189
|
// Valid branch, tag, or commit
|
|
190
190
|
~~~~
|
|
191
191
|
|
|
@@ -198,7 +198,7 @@ created by the factory share the same filesystem and directory options.
|
|
|
198
198
|
~~~~ typescript
|
|
199
199
|
import { createGitParsers } from "@optique/git";
|
|
200
200
|
import { argument, option, object } from "@optique/core/primitives";
|
|
201
|
-
import {
|
|
201
|
+
import { parseAsync } from "@optique/core/parser";
|
|
202
202
|
|
|
203
203
|
const git = createGitParsers({ dir: "/path/to/repo" });
|
|
204
204
|
|
package/dist/index.cjs
CHANGED
|
@@ -34,28 +34,18 @@ const logger = (0, __logtape_logtape.getLogger)(["optique", "git"]);
|
|
|
34
34
|
* Read-only filesystem interface passed to isomorphic-git.
|
|
35
35
|
*
|
|
36
36
|
* This package only performs read operations (validation and listing).
|
|
37
|
-
* Write methods are implemented as stubs that
|
|
37
|
+
* Write methods are implemented as stubs that return rejected promises,
|
|
38
38
|
* enforcing the read-only contract and preventing accidental writes.
|
|
39
39
|
*/
|
|
40
40
|
const gitFs = {
|
|
41
41
|
readFile: node_fs_promises.readFile,
|
|
42
|
-
writeFile: () =>
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
throw new Error("gitFs is read-only: mkdir is disabled.");
|
|
47
|
-
},
|
|
48
|
-
rmdir: () => {
|
|
49
|
-
throw new Error("gitFs is read-only: rmdir is disabled.");
|
|
50
|
-
},
|
|
51
|
-
unlink: () => {
|
|
52
|
-
throw new Error("gitFs is read-only: unlink is disabled.");
|
|
53
|
-
},
|
|
42
|
+
writeFile: () => Promise.reject(/* @__PURE__ */ new Error("gitFs is read-only: writeFile is disabled.")),
|
|
43
|
+
mkdir: () => Promise.reject(/* @__PURE__ */ new Error("gitFs is read-only: mkdir is disabled.")),
|
|
44
|
+
rmdir: () => Promise.reject(/* @__PURE__ */ new Error("gitFs is read-only: rmdir is disabled.")),
|
|
45
|
+
unlink: () => Promise.reject(/* @__PURE__ */ new Error("gitFs is read-only: unlink is disabled.")),
|
|
54
46
|
readdir: node_fs_promises.readdir,
|
|
55
47
|
readlink: node_fs_promises.readlink,
|
|
56
|
-
symlink: () =>
|
|
57
|
-
throw new Error("gitFs is read-only: symlink is disabled.");
|
|
58
|
-
},
|
|
48
|
+
symlink: () => Promise.reject(/* @__PURE__ */ new Error("gitFs is read-only: symlink is disabled.")),
|
|
59
49
|
stat: node_fs_promises.stat,
|
|
60
50
|
lstat: node_fs_promises.lstat
|
|
61
51
|
};
|
|
@@ -378,7 +368,11 @@ function gitCommit(options) {
|
|
|
378
368
|
success: true,
|
|
379
369
|
value: oid
|
|
380
370
|
};
|
|
381
|
-
} catch {
|
|
371
|
+
} catch (e) {
|
|
372
|
+
if (hasErrorCode(e, "AmbiguousShortOidError")) return {
|
|
373
|
+
success: false,
|
|
374
|
+
error: __optique_core_message.message`Commit SHA ${(0, __optique_core_message.value)(input)} is ambiguous. Provide more characters to disambiguate.`
|
|
375
|
+
};
|
|
382
376
|
if (errors?.notFound) return {
|
|
383
377
|
success: false,
|
|
384
378
|
error: errors.notFound(input)
|
|
@@ -448,7 +442,11 @@ function gitRef(options) {
|
|
|
448
442
|
success: true,
|
|
449
443
|
value: oid
|
|
450
444
|
};
|
|
451
|
-
} catch {
|
|
445
|
+
} catch (e) {
|
|
446
|
+
if (hasErrorCode(e, "AmbiguousShortOidError")) return {
|
|
447
|
+
success: false,
|
|
448
|
+
error: __optique_core_message.message`Reference ${(0, __optique_core_message.value)(input)} is ambiguous. Provide more characters to disambiguate.`
|
|
449
|
+
};
|
|
452
450
|
if (errors?.notFound) return {
|
|
453
451
|
success: false,
|
|
454
452
|
error: errors.notFound(input)
|
package/dist/index.js
CHANGED
|
@@ -12,28 +12,18 @@ const logger = getLogger(["optique", "git"]);
|
|
|
12
12
|
* Read-only filesystem interface passed to isomorphic-git.
|
|
13
13
|
*
|
|
14
14
|
* This package only performs read operations (validation and listing).
|
|
15
|
-
* Write methods are implemented as stubs that
|
|
15
|
+
* Write methods are implemented as stubs that return rejected promises,
|
|
16
16
|
* enforcing the read-only contract and preventing accidental writes.
|
|
17
17
|
*/
|
|
18
18
|
const gitFs = {
|
|
19
19
|
readFile: fs.readFile,
|
|
20
|
-
writeFile: () =>
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
throw new Error("gitFs is read-only: mkdir is disabled.");
|
|
25
|
-
},
|
|
26
|
-
rmdir: () => {
|
|
27
|
-
throw new Error("gitFs is read-only: rmdir is disabled.");
|
|
28
|
-
},
|
|
29
|
-
unlink: () => {
|
|
30
|
-
throw new Error("gitFs is read-only: unlink is disabled.");
|
|
31
|
-
},
|
|
20
|
+
writeFile: () => Promise.reject(/* @__PURE__ */ new Error("gitFs is read-only: writeFile is disabled.")),
|
|
21
|
+
mkdir: () => Promise.reject(/* @__PURE__ */ new Error("gitFs is read-only: mkdir is disabled.")),
|
|
22
|
+
rmdir: () => Promise.reject(/* @__PURE__ */ new Error("gitFs is read-only: rmdir is disabled.")),
|
|
23
|
+
unlink: () => Promise.reject(/* @__PURE__ */ new Error("gitFs is read-only: unlink is disabled.")),
|
|
32
24
|
readdir: fs.readdir,
|
|
33
25
|
readlink: fs.readlink,
|
|
34
|
-
symlink: () =>
|
|
35
|
-
throw new Error("gitFs is read-only: symlink is disabled.");
|
|
36
|
-
},
|
|
26
|
+
symlink: () => Promise.reject(/* @__PURE__ */ new Error("gitFs is read-only: symlink is disabled.")),
|
|
37
27
|
stat: fs.stat,
|
|
38
28
|
lstat: fs.lstat
|
|
39
29
|
};
|
|
@@ -356,7 +346,11 @@ function gitCommit(options) {
|
|
|
356
346
|
success: true,
|
|
357
347
|
value: oid
|
|
358
348
|
};
|
|
359
|
-
} catch {
|
|
349
|
+
} catch (e) {
|
|
350
|
+
if (hasErrorCode(e, "AmbiguousShortOidError")) return {
|
|
351
|
+
success: false,
|
|
352
|
+
error: message`Commit SHA ${value(input)} is ambiguous. Provide more characters to disambiguate.`
|
|
353
|
+
};
|
|
360
354
|
if (errors?.notFound) return {
|
|
361
355
|
success: false,
|
|
362
356
|
error: errors.notFound(input)
|
|
@@ -426,7 +420,11 @@ function gitRef(options) {
|
|
|
426
420
|
success: true,
|
|
427
421
|
value: oid
|
|
428
422
|
};
|
|
429
|
-
} catch {
|
|
423
|
+
} catch (e) {
|
|
424
|
+
if (hasErrorCode(e, "AmbiguousShortOidError")) return {
|
|
425
|
+
success: false,
|
|
426
|
+
error: message`Reference ${value(input)} is ambiguous. Provide more characters to disambiguate.`
|
|
427
|
+
};
|
|
430
428
|
if (errors?.notFound) return {
|
|
431
429
|
success: false,
|
|
432
430
|
error: errors.notFound(input)
|