@optique/git 0.9.0-dev.254 → 0.9.0-dev.258

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/dist/index.cjs CHANGED
@@ -54,14 +54,6 @@ function listFailureMessage(error, dir, errors, fallback) {
54
54
  if (hasErrorCode(error, "NotAGitRepositoryError") || hasErrorCode(error, "NotFoundError")) return __optique_core_message.message`${(0, __optique_core_message.value)(dir)} is not a git repository.`;
55
55
  return fallback;
56
56
  }
57
- function formatChoiceList(choices) {
58
- let result = [];
59
- for (let i = 0; i < choices.length; i++) {
60
- if (i > 0) result = [...result, ...__optique_core_message.message`, `];
61
- result = [...result, ...__optique_core_message.message`${choices[i]}`];
62
- }
63
- return result;
64
- }
65
57
  function createAsyncValueParser(options, metavar, parseFn, suggestFn) {
66
58
  (0, __optique_core_nonempty.ensureNonEmptyString)(metavar);
67
59
  return {
@@ -116,7 +108,7 @@ function gitBranch(options) {
116
108
  };
117
109
  return {
118
110
  success: false,
119
- error: __optique_core_message.message`Branch ${(0, __optique_core_message.value)(input)} does not exist. Available branches: ${formatChoiceList(branches)}`
111
+ error: __optique_core_message.message`Branch ${(0, __optique_core_message.value)(input)} does not exist. Available branches: ${(0, __optique_core_message.valueSet)(branches)}`
120
112
  };
121
113
  } catch (error) {
122
114
  const fallback = __optique_core_message.message`Failed to list branches. Ensure ${(0, __optique_core_message.value)(dir)} is a valid git repository.`;
@@ -176,7 +168,7 @@ function gitRemoteBranch(remote, options) {
176
168
  };
177
169
  return {
178
170
  success: false,
179
- error: __optique_core_message.message`Remote branch ${(0, __optique_core_message.value)(input)} does not exist on remote ${(0, __optique_core_message.value)(remote)}. Available branches: ${formatChoiceList(branches)}`
171
+ error: __optique_core_message.message`Remote branch ${(0, __optique_core_message.value)(input)} does not exist on remote ${(0, __optique_core_message.value)(remote)}. Available branches: ${(0, __optique_core_message.valueSet)(branches)}`
180
172
  };
181
173
  } catch (error) {
182
174
  const fallback = __optique_core_message.message`Failed to list remote branches. Ensure remote ${(0, __optique_core_message.value)(remote)} exists.`;
@@ -224,7 +216,7 @@ function gitTag(options) {
224
216
  };
225
217
  return {
226
218
  success: false,
227
- error: __optique_core_message.message`Tag ${(0, __optique_core_message.value)(input)} does not exist. Available tags: ${formatChoiceList(tags)}`
219
+ error: __optique_core_message.message`Tag ${(0, __optique_core_message.value)(input)} does not exist. Available tags: ${(0, __optique_core_message.valueSet)(tags)}`
228
220
  };
229
221
  } catch (error) {
230
222
  const fallback = __optique_core_message.message`Failed to list tags. Ensure ${(0, __optique_core_message.value)(dir)} is a valid git repository.`;
@@ -272,7 +264,7 @@ function gitRemote(options) {
272
264
  };
273
265
  return {
274
266
  success: false,
275
- error: __optique_core_message.message`Remote ${(0, __optique_core_message.value)(input)} does not exist. Available remotes: ${formatChoiceList(names)}`
267
+ error: __optique_core_message.message`Remote ${(0, __optique_core_message.value)(input)} does not exist. Available remotes: ${(0, __optique_core_message.valueSet)(names)}`
276
268
  };
277
269
  } catch (error) {
278
270
  const fallback = __optique_core_message.message`Failed to list remotes. Ensure ${(0, __optique_core_message.value)(dir)} is a valid git repository.`;
@@ -349,6 +341,23 @@ function gitCommit(options) {
349
341
  error: __optique_core_message.message`Commit ${(0, __optique_core_message.value)(input)} does not exist. Provide a valid commit SHA.`
350
342
  };
351
343
  }
344
+ }, async function* suggestCommit(dir, prefix) {
345
+ try {
346
+ const commits = await isomorphic_git.log({
347
+ fs: gitFs,
348
+ dir,
349
+ depth: 15
350
+ });
351
+ for (const commit of commits) if (commit.oid.startsWith(prefix)) {
352
+ const shortOid = commit.oid.slice(0, 7);
353
+ const firstLine = commit.commit.message.split("\n")[0];
354
+ yield {
355
+ kind: "literal",
356
+ text: shortOid,
357
+ description: __optique_core_message.message`${firstLine}`
358
+ };
359
+ }
360
+ } catch {}
352
361
  });
353
362
  }
354
363
  /**
@@ -398,13 +407,21 @@ function gitRef(options) {
398
407
  }
399
408
  }, async function* suggestRef(dir, prefix) {
400
409
  try {
401
- const [branches, tags] = await Promise.all([isomorphic_git.listBranches({
402
- fs: gitFs,
403
- dir
404
- }), isomorphic_git.listTags({
405
- fs: gitFs,
406
- dir
407
- })]);
410
+ const [branches, tags, commits] = await Promise.all([
411
+ isomorphic_git.listBranches({
412
+ fs: gitFs,
413
+ dir
414
+ }),
415
+ isomorphic_git.listTags({
416
+ fs: gitFs,
417
+ dir
418
+ }),
419
+ isomorphic_git.log({
420
+ fs: gitFs,
421
+ dir,
422
+ depth: 10
423
+ })
424
+ ]);
408
425
  for (const branch of branches) if (branch.startsWith(prefix)) yield {
409
426
  kind: "literal",
410
427
  text: branch
@@ -413,6 +430,15 @@ function gitRef(options) {
413
430
  kind: "literal",
414
431
  text: tag
415
432
  };
433
+ for (const commit of commits) if (commit.oid.startsWith(prefix)) {
434
+ const shortOid = commit.oid.slice(0, 7);
435
+ const firstLine = commit.commit.message.split("\n")[0];
436
+ yield {
437
+ kind: "literal",
438
+ text: shortOid,
439
+ description: __optique_core_message.message`${firstLine}`
440
+ };
441
+ }
416
442
  } catch {}
417
443
  });
418
444
  }
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { message, value } from "@optique/core/message";
1
+ import { message, value, valueSet } from "@optique/core/message";
2
2
  import { ensureNonEmptyString } from "@optique/core/nonempty";
3
3
  import * as git from "isomorphic-git";
4
4
  import { expandOid, listBranches, listRemotes, listTags, readObject, resolveRef } from "isomorphic-git";
@@ -32,14 +32,6 @@ function listFailureMessage(error, dir, errors, fallback) {
32
32
  if (hasErrorCode(error, "NotAGitRepositoryError") || hasErrorCode(error, "NotFoundError")) return message`${value(dir)} is not a git repository.`;
33
33
  return fallback;
34
34
  }
35
- function formatChoiceList(choices) {
36
- let result = [];
37
- for (let i = 0; i < choices.length; i++) {
38
- if (i > 0) result = [...result, ...message`, `];
39
- result = [...result, ...message`${choices[i]}`];
40
- }
41
- return result;
42
- }
43
35
  function createAsyncValueParser(options, metavar, parseFn, suggestFn) {
44
36
  ensureNonEmptyString(metavar);
45
37
  return {
@@ -94,7 +86,7 @@ function gitBranch(options) {
94
86
  };
95
87
  return {
96
88
  success: false,
97
- error: message`Branch ${value(input)} does not exist. Available branches: ${formatChoiceList(branches)}`
89
+ error: message`Branch ${value(input)} does not exist. Available branches: ${valueSet(branches)}`
98
90
  };
99
91
  } catch (error) {
100
92
  const fallback = message`Failed to list branches. Ensure ${value(dir)} is a valid git repository.`;
@@ -154,7 +146,7 @@ function gitRemoteBranch(remote, options) {
154
146
  };
155
147
  return {
156
148
  success: false,
157
- error: message`Remote branch ${value(input)} does not exist on remote ${value(remote)}. Available branches: ${formatChoiceList(branches)}`
149
+ error: message`Remote branch ${value(input)} does not exist on remote ${value(remote)}. Available branches: ${valueSet(branches)}`
158
150
  };
159
151
  } catch (error) {
160
152
  const fallback = message`Failed to list remote branches. Ensure remote ${value(remote)} exists.`;
@@ -202,7 +194,7 @@ function gitTag(options) {
202
194
  };
203
195
  return {
204
196
  success: false,
205
- error: message`Tag ${value(input)} does not exist. Available tags: ${formatChoiceList(tags)}`
197
+ error: message`Tag ${value(input)} does not exist. Available tags: ${valueSet(tags)}`
206
198
  };
207
199
  } catch (error) {
208
200
  const fallback = message`Failed to list tags. Ensure ${value(dir)} is a valid git repository.`;
@@ -250,7 +242,7 @@ function gitRemote(options) {
250
242
  };
251
243
  return {
252
244
  success: false,
253
- error: message`Remote ${value(input)} does not exist. Available remotes: ${formatChoiceList(names)}`
245
+ error: message`Remote ${value(input)} does not exist. Available remotes: ${valueSet(names)}`
254
246
  };
255
247
  } catch (error) {
256
248
  const fallback = message`Failed to list remotes. Ensure ${value(dir)} is a valid git repository.`;
@@ -327,6 +319,23 @@ function gitCommit(options) {
327
319
  error: message`Commit ${value(input)} does not exist. Provide a valid commit SHA.`
328
320
  };
329
321
  }
322
+ }, async function* suggestCommit(dir, prefix) {
323
+ try {
324
+ const commits = await git.log({
325
+ fs: gitFs,
326
+ dir,
327
+ depth: 15
328
+ });
329
+ for (const commit of commits) if (commit.oid.startsWith(prefix)) {
330
+ const shortOid = commit.oid.slice(0, 7);
331
+ const firstLine = commit.commit.message.split("\n")[0];
332
+ yield {
333
+ kind: "literal",
334
+ text: shortOid,
335
+ description: message`${firstLine}`
336
+ };
337
+ }
338
+ } catch {}
330
339
  });
331
340
  }
332
341
  /**
@@ -376,13 +385,21 @@ function gitRef(options) {
376
385
  }
377
386
  }, async function* suggestRef(dir, prefix) {
378
387
  try {
379
- const [branches, tags] = await Promise.all([git.listBranches({
380
- fs: gitFs,
381
- dir
382
- }), git.listTags({
383
- fs: gitFs,
384
- dir
385
- })]);
388
+ const [branches, tags, commits] = await Promise.all([
389
+ git.listBranches({
390
+ fs: gitFs,
391
+ dir
392
+ }),
393
+ git.listTags({
394
+ fs: gitFs,
395
+ dir
396
+ }),
397
+ git.log({
398
+ fs: gitFs,
399
+ dir,
400
+ depth: 10
401
+ })
402
+ ]);
386
403
  for (const branch of branches) if (branch.startsWith(prefix)) yield {
387
404
  kind: "literal",
388
405
  text: branch
@@ -391,6 +408,15 @@ function gitRef(options) {
391
408
  kind: "literal",
392
409
  text: tag
393
410
  };
411
+ for (const commit of commits) if (commit.oid.startsWith(prefix)) {
412
+ const shortOid = commit.oid.slice(0, 7);
413
+ const firstLine = commit.commit.message.split("\n")[0];
414
+ yield {
415
+ kind: "literal",
416
+ text: shortOid,
417
+ description: message`${firstLine}`
418
+ };
419
+ }
394
420
  } catch {}
395
421
  });
396
422
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/git",
3
- "version": "0.9.0-dev.254+390a74da",
3
+ "version": "0.9.0-dev.258+a42f88c2",
4
4
  "description": "Git value parsers for Optique",
5
5
  "keywords": [
6
6
  "CLI",