@hyperfrontend/versioning 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.
Files changed (353) hide show
  1. package/ARCHITECTURE.md +593 -0
  2. package/CHANGELOG.md +35 -0
  3. package/FUNDING.md +141 -0
  4. package/LICENSE.md +21 -0
  5. package/README.md +195 -0
  6. package/SECURITY.md +82 -0
  7. package/changelog/compare/diff.d.ts +128 -0
  8. package/changelog/compare/diff.d.ts.map +1 -0
  9. package/changelog/compare/index.cjs.js +628 -0
  10. package/changelog/compare/index.cjs.js.map +1 -0
  11. package/changelog/compare/index.d.ts +4 -0
  12. package/changelog/compare/index.d.ts.map +1 -0
  13. package/changelog/compare/index.esm.js +612 -0
  14. package/changelog/compare/index.esm.js.map +1 -0
  15. package/changelog/compare/is-equal.d.ts +114 -0
  16. package/changelog/compare/is-equal.d.ts.map +1 -0
  17. package/changelog/index.cjs.js +6448 -0
  18. package/changelog/index.cjs.js.map +1 -0
  19. package/changelog/index.d.ts +6 -0
  20. package/changelog/index.d.ts.map +1 -0
  21. package/changelog/index.esm.js +6358 -0
  22. package/changelog/index.esm.js.map +1 -0
  23. package/changelog/models/changelog.d.ts +86 -0
  24. package/changelog/models/changelog.d.ts.map +1 -0
  25. package/changelog/models/commit-ref.d.ts +51 -0
  26. package/changelog/models/commit-ref.d.ts.map +1 -0
  27. package/changelog/models/entry.d.ts +84 -0
  28. package/changelog/models/entry.d.ts.map +1 -0
  29. package/changelog/models/index.cjs.js +2043 -0
  30. package/changelog/models/index.cjs.js.map +1 -0
  31. package/changelog/models/index.d.ts +11 -0
  32. package/changelog/models/index.d.ts.map +1 -0
  33. package/changelog/models/index.esm.js +2026 -0
  34. package/changelog/models/index.esm.js.map +1 -0
  35. package/changelog/models/schema.d.ts +68 -0
  36. package/changelog/models/schema.d.ts.map +1 -0
  37. package/changelog/models/section.d.ts +25 -0
  38. package/changelog/models/section.d.ts.map +1 -0
  39. package/changelog/operations/add-entry.d.ts +56 -0
  40. package/changelog/operations/add-entry.d.ts.map +1 -0
  41. package/changelog/operations/add-item.d.ts +18 -0
  42. package/changelog/operations/add-item.d.ts.map +1 -0
  43. package/changelog/operations/filter-by-predicate.d.ts +81 -0
  44. package/changelog/operations/filter-by-predicate.d.ts.map +1 -0
  45. package/changelog/operations/filter-by-range.d.ts +63 -0
  46. package/changelog/operations/filter-by-range.d.ts.map +1 -0
  47. package/changelog/operations/filter-entries.d.ts +9 -0
  48. package/changelog/operations/filter-entries.d.ts.map +1 -0
  49. package/changelog/operations/index.cjs.js +2455 -0
  50. package/changelog/operations/index.cjs.js.map +1 -0
  51. package/changelog/operations/index.d.ts +15 -0
  52. package/changelog/operations/index.d.ts.map +1 -0
  53. package/changelog/operations/index.esm.js +2411 -0
  54. package/changelog/operations/index.esm.js.map +1 -0
  55. package/changelog/operations/merge.d.ts +88 -0
  56. package/changelog/operations/merge.d.ts.map +1 -0
  57. package/changelog/operations/remove-entry.d.ts +45 -0
  58. package/changelog/operations/remove-entry.d.ts.map +1 -0
  59. package/changelog/operations/remove-section.d.ts +50 -0
  60. package/changelog/operations/remove-section.d.ts.map +1 -0
  61. package/changelog/operations/transform.d.ts +143 -0
  62. package/changelog/operations/transform.d.ts.map +1 -0
  63. package/changelog/parse/index.cjs.js +1282 -0
  64. package/changelog/parse/index.cjs.js.map +1 -0
  65. package/changelog/parse/index.d.ts +5 -0
  66. package/changelog/parse/index.d.ts.map +1 -0
  67. package/changelog/parse/index.esm.js +1275 -0
  68. package/changelog/parse/index.esm.js.map +1 -0
  69. package/changelog/parse/line.d.ts +48 -0
  70. package/changelog/parse/line.d.ts.map +1 -0
  71. package/changelog/parse/parser.d.ts +16 -0
  72. package/changelog/parse/parser.d.ts.map +1 -0
  73. package/changelog/parse/tokenizer.d.ts +49 -0
  74. package/changelog/parse/tokenizer.d.ts.map +1 -0
  75. package/changelog/serialize/index.cjs.js +574 -0
  76. package/changelog/serialize/index.cjs.js.map +1 -0
  77. package/changelog/serialize/index.d.ts +6 -0
  78. package/changelog/serialize/index.d.ts.map +1 -0
  79. package/changelog/serialize/index.esm.js +564 -0
  80. package/changelog/serialize/index.esm.js.map +1 -0
  81. package/changelog/serialize/templates.d.ts +81 -0
  82. package/changelog/serialize/templates.d.ts.map +1 -0
  83. package/changelog/serialize/to-json.d.ts +57 -0
  84. package/changelog/serialize/to-json.d.ts.map +1 -0
  85. package/changelog/serialize/to-string.d.ts +30 -0
  86. package/changelog/serialize/to-string.d.ts.map +1 -0
  87. package/commits/index.cjs.js +648 -0
  88. package/commits/index.cjs.js.map +1 -0
  89. package/commits/index.d.ts +3 -0
  90. package/commits/index.d.ts.map +1 -0
  91. package/commits/index.esm.js +629 -0
  92. package/commits/index.esm.js.map +1 -0
  93. package/commits/models/breaking.d.ts +39 -0
  94. package/commits/models/breaking.d.ts.map +1 -0
  95. package/commits/models/commit-type.d.ts +32 -0
  96. package/commits/models/commit-type.d.ts.map +1 -0
  97. package/commits/models/conventional.d.ts +49 -0
  98. package/commits/models/conventional.d.ts.map +1 -0
  99. package/commits/models/index.cjs.js +207 -0
  100. package/commits/models/index.cjs.js.map +1 -0
  101. package/commits/models/index.d.ts +7 -0
  102. package/commits/models/index.d.ts.map +1 -0
  103. package/commits/models/index.esm.js +193 -0
  104. package/commits/models/index.esm.js.map +1 -0
  105. package/commits/parse/body.d.ts +18 -0
  106. package/commits/parse/body.d.ts.map +1 -0
  107. package/commits/parse/footer.d.ts +16 -0
  108. package/commits/parse/footer.d.ts.map +1 -0
  109. package/commits/parse/header.d.ts +15 -0
  110. package/commits/parse/header.d.ts.map +1 -0
  111. package/commits/parse/index.cjs.js +505 -0
  112. package/commits/parse/index.cjs.js.map +1 -0
  113. package/commits/parse/index.d.ts +5 -0
  114. package/commits/parse/index.d.ts.map +1 -0
  115. package/commits/parse/index.esm.js +499 -0
  116. package/commits/parse/index.esm.js.map +1 -0
  117. package/commits/parse/message.d.ts +17 -0
  118. package/commits/parse/message.d.ts.map +1 -0
  119. package/commits/utils/replace-char.d.ts +19 -0
  120. package/commits/utils/replace-char.d.ts.map +1 -0
  121. package/flow/executor/execute.d.ts +72 -0
  122. package/flow/executor/execute.d.ts.map +1 -0
  123. package/flow/executor/index.cjs.js +4402 -0
  124. package/flow/executor/index.cjs.js.map +1 -0
  125. package/flow/executor/index.d.ts +3 -0
  126. package/flow/executor/index.d.ts.map +1 -0
  127. package/flow/executor/index.esm.js +4398 -0
  128. package/flow/executor/index.esm.js.map +1 -0
  129. package/flow/factory.d.ts +58 -0
  130. package/flow/factory.d.ts.map +1 -0
  131. package/flow/index.cjs.js +8506 -0
  132. package/flow/index.cjs.js.map +1 -0
  133. package/flow/index.d.ts +7 -0
  134. package/flow/index.d.ts.map +1 -0
  135. package/flow/index.esm.js +8451 -0
  136. package/flow/index.esm.js.map +1 -0
  137. package/flow/models/flow.d.ts +130 -0
  138. package/flow/models/flow.d.ts.map +1 -0
  139. package/flow/models/index.cjs.js +285 -0
  140. package/flow/models/index.cjs.js.map +1 -0
  141. package/flow/models/index.d.ts +7 -0
  142. package/flow/models/index.d.ts.map +1 -0
  143. package/flow/models/index.esm.js +268 -0
  144. package/flow/models/index.esm.js.map +1 -0
  145. package/flow/models/step.d.ts +108 -0
  146. package/flow/models/step.d.ts.map +1 -0
  147. package/flow/models/types.d.ts +150 -0
  148. package/flow/models/types.d.ts.map +1 -0
  149. package/flow/presets/conventional.d.ts +59 -0
  150. package/flow/presets/conventional.d.ts.map +1 -0
  151. package/flow/presets/independent.d.ts +61 -0
  152. package/flow/presets/independent.d.ts.map +1 -0
  153. package/flow/presets/index.cjs.js +3903 -0
  154. package/flow/presets/index.cjs.js.map +1 -0
  155. package/flow/presets/index.d.ts +4 -0
  156. package/flow/presets/index.d.ts.map +1 -0
  157. package/flow/presets/index.esm.js +3889 -0
  158. package/flow/presets/index.esm.js.map +1 -0
  159. package/flow/presets/synced.d.ts +65 -0
  160. package/flow/presets/synced.d.ts.map +1 -0
  161. package/flow/steps/analyze-commits.d.ts +19 -0
  162. package/flow/steps/analyze-commits.d.ts.map +1 -0
  163. package/flow/steps/calculate-bump.d.ts +27 -0
  164. package/flow/steps/calculate-bump.d.ts.map +1 -0
  165. package/flow/steps/create-commit.d.ts +16 -0
  166. package/flow/steps/create-commit.d.ts.map +1 -0
  167. package/flow/steps/create-tag.d.ts +22 -0
  168. package/flow/steps/create-tag.d.ts.map +1 -0
  169. package/flow/steps/fetch-registry.d.ts +19 -0
  170. package/flow/steps/fetch-registry.d.ts.map +1 -0
  171. package/flow/steps/generate-changelog.d.ts +25 -0
  172. package/flow/steps/generate-changelog.d.ts.map +1 -0
  173. package/flow/steps/index.cjs.js +3523 -0
  174. package/flow/steps/index.cjs.js.map +1 -0
  175. package/flow/steps/index.d.ts +8 -0
  176. package/flow/steps/index.d.ts.map +1 -0
  177. package/flow/steps/index.esm.js +3504 -0
  178. package/flow/steps/index.esm.js.map +1 -0
  179. package/flow/steps/update-packages.d.ts +25 -0
  180. package/flow/steps/update-packages.d.ts.map +1 -0
  181. package/flow/utils/interpolate.d.ts +11 -0
  182. package/flow/utils/interpolate.d.ts.map +1 -0
  183. package/git/factory.d.ts +233 -0
  184. package/git/factory.d.ts.map +1 -0
  185. package/git/index.cjs.js +2863 -0
  186. package/git/index.cjs.js.map +1 -0
  187. package/git/index.d.ts +5 -0
  188. package/git/index.d.ts.map +1 -0
  189. package/git/index.esm.js +2785 -0
  190. package/git/index.esm.js.map +1 -0
  191. package/git/models/commit.d.ts +129 -0
  192. package/git/models/commit.d.ts.map +1 -0
  193. package/git/models/index.cjs.js +755 -0
  194. package/git/models/index.cjs.js.map +1 -0
  195. package/git/models/index.d.ts +7 -0
  196. package/git/models/index.d.ts.map +1 -0
  197. package/git/models/index.esm.js +729 -0
  198. package/git/models/index.esm.js.map +1 -0
  199. package/git/models/ref.d.ts +120 -0
  200. package/git/models/ref.d.ts.map +1 -0
  201. package/git/models/tag.d.ts +141 -0
  202. package/git/models/tag.d.ts.map +1 -0
  203. package/git/operations/commit.d.ts +97 -0
  204. package/git/operations/commit.d.ts.map +1 -0
  205. package/git/operations/head-info.d.ts +29 -0
  206. package/git/operations/head-info.d.ts.map +1 -0
  207. package/git/operations/index.cjs.js +1954 -0
  208. package/git/operations/index.cjs.js.map +1 -0
  209. package/git/operations/index.d.ts +14 -0
  210. package/git/operations/index.d.ts.map +1 -0
  211. package/git/operations/index.esm.js +1903 -0
  212. package/git/operations/index.esm.js.map +1 -0
  213. package/git/operations/log.d.ts +104 -0
  214. package/git/operations/log.d.ts.map +1 -0
  215. package/git/operations/manage-tags.d.ts +60 -0
  216. package/git/operations/manage-tags.d.ts.map +1 -0
  217. package/git/operations/query-tags.d.ts +88 -0
  218. package/git/operations/query-tags.d.ts.map +1 -0
  219. package/git/operations/stage.d.ts +66 -0
  220. package/git/operations/stage.d.ts.map +1 -0
  221. package/git/operations/status.d.ts +173 -0
  222. package/git/operations/status.d.ts.map +1 -0
  223. package/index.cjs.js +16761 -0
  224. package/index.cjs.js.map +1 -0
  225. package/index.d.ts +102 -0
  226. package/index.d.ts.map +1 -0
  227. package/index.esm.js +16427 -0
  228. package/index.esm.js.map +1 -0
  229. package/package.json +200 -0
  230. package/registry/factory.d.ts +18 -0
  231. package/registry/factory.d.ts.map +1 -0
  232. package/registry/index.cjs.js +543 -0
  233. package/registry/index.cjs.js.map +1 -0
  234. package/registry/index.d.ts +5 -0
  235. package/registry/index.d.ts.map +1 -0
  236. package/registry/index.esm.js +535 -0
  237. package/registry/index.esm.js.map +1 -0
  238. package/registry/models/index.cjs.js +69 -0
  239. package/registry/models/index.cjs.js.map +1 -0
  240. package/registry/models/index.d.ts +6 -0
  241. package/registry/models/index.d.ts.map +1 -0
  242. package/registry/models/index.esm.js +66 -0
  243. package/registry/models/index.esm.js.map +1 -0
  244. package/registry/models/package-info.d.ts +55 -0
  245. package/registry/models/package-info.d.ts.map +1 -0
  246. package/registry/models/registry.d.ts +62 -0
  247. package/registry/models/registry.d.ts.map +1 -0
  248. package/registry/models/version-info.d.ts +67 -0
  249. package/registry/models/version-info.d.ts.map +1 -0
  250. package/registry/npm/cache.d.ts +50 -0
  251. package/registry/npm/cache.d.ts.map +1 -0
  252. package/registry/npm/client.d.ts +30 -0
  253. package/registry/npm/client.d.ts.map +1 -0
  254. package/registry/npm/index.cjs.js +456 -0
  255. package/registry/npm/index.cjs.js.map +1 -0
  256. package/registry/npm/index.d.ts +4 -0
  257. package/registry/npm/index.d.ts.map +1 -0
  258. package/registry/npm/index.esm.js +451 -0
  259. package/registry/npm/index.esm.js.map +1 -0
  260. package/semver/compare/compare.d.ts +100 -0
  261. package/semver/compare/compare.d.ts.map +1 -0
  262. package/semver/compare/index.cjs.js +386 -0
  263. package/semver/compare/index.cjs.js.map +1 -0
  264. package/semver/compare/index.d.ts +3 -0
  265. package/semver/compare/index.d.ts.map +1 -0
  266. package/semver/compare/index.esm.js +370 -0
  267. package/semver/compare/index.esm.js.map +1 -0
  268. package/semver/compare/sort.d.ts +36 -0
  269. package/semver/compare/sort.d.ts.map +1 -0
  270. package/semver/format/index.cjs.js +58 -0
  271. package/semver/format/index.cjs.js.map +1 -0
  272. package/semver/format/index.d.ts +2 -0
  273. package/semver/format/index.d.ts.map +1 -0
  274. package/semver/format/index.esm.js +53 -0
  275. package/semver/format/index.esm.js.map +1 -0
  276. package/semver/format/to-string.d.ts +31 -0
  277. package/semver/format/to-string.d.ts.map +1 -0
  278. package/semver/increment/bump.d.ts +37 -0
  279. package/semver/increment/bump.d.ts.map +1 -0
  280. package/semver/increment/index.cjs.js +223 -0
  281. package/semver/increment/index.cjs.js.map +1 -0
  282. package/semver/increment/index.d.ts +2 -0
  283. package/semver/increment/index.d.ts.map +1 -0
  284. package/semver/increment/index.esm.js +219 -0
  285. package/semver/increment/index.esm.js.map +1 -0
  286. package/semver/index.cjs.js +1499 -0
  287. package/semver/index.cjs.js.map +1 -0
  288. package/semver/index.d.ts +6 -0
  289. package/semver/index.d.ts.map +1 -0
  290. package/semver/index.esm.js +1458 -0
  291. package/semver/index.esm.js.map +1 -0
  292. package/semver/models/index.cjs.js +153 -0
  293. package/semver/models/index.cjs.js.map +1 -0
  294. package/semver/models/index.d.ts +5 -0
  295. package/semver/models/index.d.ts.map +1 -0
  296. package/semver/models/index.esm.js +139 -0
  297. package/semver/models/index.esm.js.map +1 -0
  298. package/semver/models/range.d.ts +83 -0
  299. package/semver/models/range.d.ts.map +1 -0
  300. package/semver/models/version.d.ts +78 -0
  301. package/semver/models/version.d.ts.map +1 -0
  302. package/semver/parse/index.cjs.js +799 -0
  303. package/semver/parse/index.cjs.js.map +1 -0
  304. package/semver/parse/index.d.ts +5 -0
  305. package/semver/parse/index.d.ts.map +1 -0
  306. package/semver/parse/index.esm.js +793 -0
  307. package/semver/parse/index.esm.js.map +1 -0
  308. package/semver/parse/range.d.ts +38 -0
  309. package/semver/parse/range.d.ts.map +1 -0
  310. package/semver/parse/version.d.ts +49 -0
  311. package/semver/parse/version.d.ts.map +1 -0
  312. package/workspace/discovery/changelog-path.d.ts +21 -0
  313. package/workspace/discovery/changelog-path.d.ts.map +1 -0
  314. package/workspace/discovery/dependencies.d.ts +145 -0
  315. package/workspace/discovery/dependencies.d.ts.map +1 -0
  316. package/workspace/discovery/discover-changelogs.d.ts +76 -0
  317. package/workspace/discovery/discover-changelogs.d.ts.map +1 -0
  318. package/workspace/discovery/index.cjs.js +2300 -0
  319. package/workspace/discovery/index.cjs.js.map +1 -0
  320. package/workspace/discovery/index.d.ts +13 -0
  321. package/workspace/discovery/index.d.ts.map +1 -0
  322. package/workspace/discovery/index.esm.js +2283 -0
  323. package/workspace/discovery/index.esm.js.map +1 -0
  324. package/workspace/discovery/packages.d.ts +83 -0
  325. package/workspace/discovery/packages.d.ts.map +1 -0
  326. package/workspace/index.cjs.js +4445 -0
  327. package/workspace/index.cjs.js.map +1 -0
  328. package/workspace/index.d.ts +52 -0
  329. package/workspace/index.d.ts.map +1 -0
  330. package/workspace/index.esm.js +4394 -0
  331. package/workspace/index.esm.js.map +1 -0
  332. package/workspace/models/index.cjs.js +284 -0
  333. package/workspace/models/index.cjs.js.map +1 -0
  334. package/workspace/models/index.d.ts +10 -0
  335. package/workspace/models/index.d.ts.map +1 -0
  336. package/workspace/models/index.esm.js +261 -0
  337. package/workspace/models/index.esm.js.map +1 -0
  338. package/workspace/models/project.d.ts +118 -0
  339. package/workspace/models/project.d.ts.map +1 -0
  340. package/workspace/models/workspace.d.ts +139 -0
  341. package/workspace/models/workspace.d.ts.map +1 -0
  342. package/workspace/operations/batch-update.d.ts +99 -0
  343. package/workspace/operations/batch-update.d.ts.map +1 -0
  344. package/workspace/operations/cascade-bump.d.ts +125 -0
  345. package/workspace/operations/cascade-bump.d.ts.map +1 -0
  346. package/workspace/operations/index.cjs.js +2675 -0
  347. package/workspace/operations/index.cjs.js.map +1 -0
  348. package/workspace/operations/index.d.ts +12 -0
  349. package/workspace/operations/index.d.ts.map +1 -0
  350. package/workspace/operations/index.esm.js +2663 -0
  351. package/workspace/operations/index.esm.js.map +1 -0
  352. package/workspace/operations/validate.d.ts +85 -0
  353. package/workspace/operations/validate.d.ts.map +1 -0
@@ -0,0 +1,1954 @@
1
+ 'use strict';
2
+
3
+ var node_child_process = require('node:child_process');
4
+
5
+ /**
6
+ * Safe copies of Error built-ins via factory functions.
7
+ *
8
+ * Since constructors cannot be safely captured via Object.assign, this module
9
+ * provides factory functions that use Reflect.construct internally.
10
+ *
11
+ * These references are captured at module initialization time to protect against
12
+ * prototype pollution attacks. Import only what you need for tree-shaking.
13
+ *
14
+ * @module @hyperfrontend/immutable-api-utils/built-in-copy/error
15
+ */
16
+ // Capture references at module initialization time
17
+ const _Error = globalThis.Error;
18
+ const _Reflect$1 = globalThis.Reflect;
19
+ /**
20
+ * (Safe copy) Creates a new Error using the captured Error constructor.
21
+ * Use this instead of `new Error()`.
22
+ *
23
+ * @param message - Optional error message.
24
+ * @param options - Optional error options.
25
+ * @returns A new Error instance.
26
+ */
27
+ const createError = (message, options) => _Reflect$1.construct(_Error, [message, options]);
28
+
29
+ /**
30
+ * Creates a git commit model.
31
+ *
32
+ * @param options - Commit creation options
33
+ * @returns A new GitCommit object
34
+ *
35
+ * @example
36
+ * const commit = createGitCommit({
37
+ * hash: 'abc123...',
38
+ * authorName: 'John Doe',
39
+ * authorEmail: 'john@example.com',
40
+ * authorDate: '2026-03-12T10:00:00Z',
41
+ * subject: 'feat: add new feature',
42
+ * })
43
+ */
44
+ function createGitCommit(options) {
45
+ const body = options.body ?? '';
46
+ const subject = options.subject;
47
+ return {
48
+ hash: options.hash,
49
+ shortHash: getShortHash(options.hash),
50
+ authorName: options.authorName,
51
+ authorEmail: options.authorEmail,
52
+ authorDate: options.authorDate,
53
+ committerName: options.committerName ?? options.authorName,
54
+ committerEmail: options.committerEmail ?? options.authorEmail,
55
+ commitDate: options.commitDate ?? options.authorDate,
56
+ subject,
57
+ body,
58
+ message: body ? `${subject}\n\n${body}` : subject,
59
+ parents: options.parents ?? [],
60
+ refs: options.refs ?? [],
61
+ };
62
+ }
63
+ /**
64
+ * Gets a short hash (7 characters) from a full commit hash.
65
+ *
66
+ * @param hash - Full commit hash
67
+ * @returns Short hash (7 characters)
68
+ */
69
+ function getShortHash(hash) {
70
+ return hash.slice(0, 7);
71
+ }
72
+
73
+ /**
74
+ * Default log options.
75
+ */
76
+ const DEFAULT_LOG_OPTIONS = {
77
+ maxCount: 100,
78
+ includeMerges: true,
79
+ timeout: 30000,
80
+ };
81
+ /**
82
+ * Git log format string for structured output.
83
+ * Uses ASCII delimiters that won't appear in commit messages.
84
+ */
85
+ const LOG_FORMAT = [
86
+ '%H', // full hash
87
+ '%an', // author name
88
+ '%ae', // author email
89
+ '%aI', // author date (ISO 8601)
90
+ '%cn', // committer name
91
+ '%ce', // committer email
92
+ '%cI', // commit date (ISO 8601)
93
+ '%s', // subject
94
+ '%b', // body
95
+ '%P', // parent hashes
96
+ '%D', // refs
97
+ ].join('%x00'); // NUL separator
98
+ /**
99
+ * Record separator for commit entries.
100
+ */
101
+ const RECORD_SEPARATOR = '\x1e'; // ASCII Record Separator
102
+ /**
103
+ * Gets the commit log from a git repository.
104
+ *
105
+ * @param options - Configuration for retrieving the commit log
106
+ * @returns Array of GitCommit objects
107
+ *
108
+ * @example
109
+ * const commits = getCommitLog({ maxCount: 10 })
110
+ * const recentChanges = getCommitLog({ from: 'v1.0.0', to: 'HEAD' })
111
+ */
112
+ function getCommitLog(options = {}) {
113
+ const opts = { ...DEFAULT_LOG_OPTIONS, ...options };
114
+ const args = ['log', `--format=${RECORD_SEPARATOR}${LOG_FORMAT}`];
115
+ // Add options
116
+ if (opts.maxCount !== undefined && opts.maxCount > 0) {
117
+ args.push(`-n${opts.maxCount}`);
118
+ }
119
+ if (!opts.includeMerges) {
120
+ args.push('--no-merges');
121
+ }
122
+ if (opts.author) {
123
+ const safeAuthor = escapeGitArg(opts.author);
124
+ args.push(`--author=${safeAuthor}`);
125
+ }
126
+ // Add range
127
+ if (opts.from && opts.to) {
128
+ const safeFrom = escapeGitRef(opts.from);
129
+ const safeTo = escapeGitRef(opts.to);
130
+ args.push(`${safeFrom}..${safeTo}`);
131
+ }
132
+ else if (opts.from) {
133
+ const safeFrom = escapeGitRef(opts.from);
134
+ args.push(`${safeFrom}..HEAD`);
135
+ }
136
+ else if (opts.to) {
137
+ const safeTo = escapeGitRef(opts.to);
138
+ args.push(safeTo);
139
+ }
140
+ // Add path filter
141
+ if (opts.path) {
142
+ const safePath = escapeGitPath(opts.path);
143
+ args.push('--', safePath);
144
+ }
145
+ try {
146
+ const output = node_child_process.execSync(`git ${args.join(' ')}`, {
147
+ encoding: 'utf-8',
148
+ cwd: opts.cwd,
149
+ timeout: opts.timeout,
150
+ stdio: ['pipe', 'pipe', 'pipe'],
151
+ maxBuffer: 50 * 1024 * 1024, // 50MB
152
+ });
153
+ return parseCommitLog(output);
154
+ }
155
+ catch (error) {
156
+ // Check if error is due to no commits
157
+ if (error instanceof Error && error.message.includes('does not have any commits')) {
158
+ return [];
159
+ }
160
+ throw error;
161
+ }
162
+ }
163
+ /**
164
+ * Gets commits between two references.
165
+ *
166
+ * @param from - Starting reference (exclusive)
167
+ * @param to - Ending reference (inclusive, default: HEAD)
168
+ * @param options - Additional options
169
+ * @returns Array of GitCommit objects
170
+ *
171
+ * @example
172
+ * const commits = getCommitsBetween('v1.0.0', 'v1.1.0')
173
+ */
174
+ function getCommitsBetween(from, to = 'HEAD', options = {}) {
175
+ return getCommitLog({ ...options, from, to });
176
+ }
177
+ /**
178
+ * Gets commits since a specific tag or reference.
179
+ *
180
+ * @param since - Reference to start from (exclusive)
181
+ * @param options - Additional options
182
+ * @returns Array of GitCommit objects
183
+ *
184
+ * @example
185
+ * const commits = getCommitsSince('v1.0.0')
186
+ */
187
+ function getCommitsSince(since, options = {}) {
188
+ return getCommitLog({ ...options, from: since });
189
+ }
190
+ /**
191
+ * Gets a single commit by its hash.
192
+ *
193
+ * @param hash - Commit hash (full or short)
194
+ * @param options - Additional options
195
+ * @returns GitCommit or null if not found
196
+ *
197
+ * @example
198
+ * const commit = getCommit('abc1234')
199
+ */
200
+ function getCommit(hash, options = {}) {
201
+ const safeHash = escapeGitRef(hash);
202
+ try {
203
+ const commits = getCommitLog({
204
+ ...options,
205
+ to: safeHash,
206
+ maxCount: 1,
207
+ });
208
+ return commits[0] ?? null;
209
+ }
210
+ catch {
211
+ return null;
212
+ }
213
+ }
214
+ /**
215
+ * Checks if a commit exists in the repository.
216
+ *
217
+ * @param hash - Commit hash to check
218
+ * @param options - Additional options
219
+ * @returns True if commit exists
220
+ */
221
+ function commitExists(hash, options = {}) {
222
+ const safeHash = escapeGitRef(hash);
223
+ try {
224
+ node_child_process.execSync(`git cat-file -t ${safeHash}`, {
225
+ encoding: 'utf-8',
226
+ cwd: options.cwd,
227
+ timeout: options.timeout ?? 5000,
228
+ stdio: ['pipe', 'pipe', 'pipe'],
229
+ });
230
+ return true;
231
+ }
232
+ catch {
233
+ return false;
234
+ }
235
+ }
236
+ /**
237
+ * Parses raw git log output into GitCommit objects.
238
+ *
239
+ * @param output - Raw git log output
240
+ * @returns Array of GitCommit objects
241
+ */
242
+ function parseCommitLog(output) {
243
+ const commits = [];
244
+ if (!output.trim()) {
245
+ return commits;
246
+ }
247
+ // Split by record separator
248
+ const records = splitByDelimiter(output, RECORD_SEPARATOR);
249
+ for (const record of records) {
250
+ const trimmed = record.trim();
251
+ if (!trimmed)
252
+ continue;
253
+ // Split by NUL character
254
+ const fields = splitByDelimiter(trimmed, '\x00');
255
+ if (fields.length < 10)
256
+ continue;
257
+ const [hash, authorName, authorEmail, authorDate, committerName, committerEmail, commitDate, subject, body, parentsStr, refsStr] = fields;
258
+ // Parse parents (space-separated hashes)
259
+ const parents = parentsStr ? splitByDelimiter(parentsStr, ' ').filter((p) => p.trim()) : [];
260
+ // Parse refs (comma-separated, may have prefixes like 'HEAD -> ')
261
+ const refs = parseRefs(refsStr || '');
262
+ commits.push(createGitCommit({
263
+ hash,
264
+ authorName,
265
+ authorEmail,
266
+ authorDate,
267
+ committerName,
268
+ committerEmail,
269
+ commitDate,
270
+ subject,
271
+ body: body || undefined,
272
+ parents,
273
+ refs,
274
+ }));
275
+ }
276
+ return commits;
277
+ }
278
+ /**
279
+ * Parses ref string from git log.
280
+ *
281
+ * @param refsStr - Raw refs string from git log
282
+ * @returns Array of ref names
283
+ */
284
+ function parseRefs(refsStr) {
285
+ if (!refsStr.trim()) {
286
+ return [];
287
+ }
288
+ const refs = [];
289
+ const parts = splitByDelimiter(refsStr, ',');
290
+ for (const part of parts) {
291
+ let ref = part.trim();
292
+ // Handle 'HEAD -> branch' format
293
+ const arrowIndex = findSubstring(ref, ' -> ');
294
+ if (arrowIndex !== -1) {
295
+ refs.push('HEAD');
296
+ ref = ref.slice(arrowIndex + 4);
297
+ }
298
+ // Handle 'tag: tagname' format
299
+ if (startsWithPrefix$2(ref, 'tag: ')) {
300
+ ref = ref.slice(5);
301
+ }
302
+ if (ref) {
303
+ refs.push(ref);
304
+ }
305
+ }
306
+ return refs;
307
+ }
308
+ /**
309
+ * Splits string by delimiter (no regex).
310
+ *
311
+ * @param str - String to split
312
+ * @param delimiter - Delimiter to split by
313
+ * @returns Array of parts
314
+ */
315
+ function splitByDelimiter(str, delimiter) {
316
+ const parts = [];
317
+ let current = '';
318
+ let i = 0;
319
+ while (i < str.length) {
320
+ if (matchesAt(str, i, delimiter)) {
321
+ parts.push(current);
322
+ current = '';
323
+ i += delimiter.length;
324
+ }
325
+ else {
326
+ current += str[i];
327
+ i++;
328
+ }
329
+ }
330
+ parts.push(current);
331
+ return parts;
332
+ }
333
+ /**
334
+ * Checks if string matches at position.
335
+ *
336
+ * @param str - String to check
337
+ * @param pos - Position to check at
338
+ * @param pattern - Pattern to match
339
+ * @returns True if matches
340
+ */
341
+ function matchesAt(str, pos, pattern) {
342
+ if (pos + pattern.length > str.length)
343
+ return false;
344
+ for (let i = 0; i < pattern.length; i++) {
345
+ if (str[pos + i] !== pattern[i])
346
+ return false;
347
+ }
348
+ return true;
349
+ }
350
+ /**
351
+ * Finds substring position (no regex).
352
+ *
353
+ * @param str - String to search
354
+ * @param pattern - Pattern to find
355
+ * @returns Position or -1 if not found
356
+ */
357
+ function findSubstring(str, pattern) {
358
+ for (let i = 0; i <= str.length - pattern.length; i++) {
359
+ if (matchesAt(str, i, pattern)) {
360
+ return i;
361
+ }
362
+ }
363
+ return -1;
364
+ }
365
+ /**
366
+ * Checks if string starts with prefix (no regex).
367
+ *
368
+ * @param str - String to check
369
+ * @param prefix - Prefix to check for
370
+ * @returns True if starts with prefix
371
+ */
372
+ function startsWithPrefix$2(str, prefix) {
373
+ return matchesAt(str, 0, prefix);
374
+ }
375
+ // ============================================================================
376
+ // Security helpers - character-by-character validation (no regex)
377
+ // ============================================================================
378
+ /**
379
+ * Maximum allowed git reference length.
380
+ */
381
+ const MAX_REF_LENGTH = 256;
382
+ /**
383
+ * Escapes a git reference for safe use in shell commands.
384
+ *
385
+ * @param ref - Reference to escape
386
+ * @returns Safe reference string
387
+ * @throws {Error} If reference contains invalid characters
388
+ */
389
+ function escapeGitRef(ref) {
390
+ if (!ref || typeof ref !== 'string') {
391
+ throw createError('Git reference is required');
392
+ }
393
+ if (ref.length > MAX_REF_LENGTH) {
394
+ throw createError(`Git reference exceeds maximum length of ${MAX_REF_LENGTH}`);
395
+ }
396
+ const safe = [];
397
+ for (let i = 0; i < ref.length; i++) {
398
+ const code = ref.charCodeAt(i);
399
+ // Allow: a-z, A-Z, 0-9, /, -, _, ., ~, ^, @, {, }
400
+ if ((code >= 97 && code <= 122) || // a-z
401
+ (code >= 65 && code <= 90) || // A-Z
402
+ (code >= 48 && code <= 57) || // 0-9
403
+ code === 47 || // /
404
+ code === 45 || // -
405
+ code === 95 || // _
406
+ code === 46 || // .
407
+ code === 126 || // ~
408
+ code === 94 || // ^
409
+ code === 64 || // @
410
+ code === 123 || // {
411
+ code === 125 // }
412
+ ) {
413
+ safe.push(ref[i]);
414
+ }
415
+ else {
416
+ throw createError(`Invalid character in git reference at position ${i}: "${ref[i]}"`);
417
+ }
418
+ }
419
+ return safe.join('');
420
+ }
421
+ /**
422
+ * Maximum allowed git path length.
423
+ */
424
+ const MAX_PATH_LENGTH$1 = 4096;
425
+ /**
426
+ * Escapes a file path for safe use in git commands.
427
+ *
428
+ * @param path - Path to escape
429
+ * @returns Safe path string
430
+ * @throws {Error} If path contains invalid characters
431
+ */
432
+ function escapeGitPath(path) {
433
+ if (!path || typeof path !== 'string') {
434
+ throw createError('Path is required');
435
+ }
436
+ if (path.length > MAX_PATH_LENGTH$1) {
437
+ throw createError(`Path exceeds maximum length of ${MAX_PATH_LENGTH$1}`);
438
+ }
439
+ const safe = [];
440
+ for (let i = 0; i < path.length; i++) {
441
+ const code = path.charCodeAt(i);
442
+ // Allow: a-z, A-Z, 0-9, /, \, -, _, ., space
443
+ if ((code >= 97 && code <= 122) || // a-z
444
+ (code >= 65 && code <= 90) || // A-Z
445
+ (code >= 48 && code <= 57) || // 0-9
446
+ code === 47 || // /
447
+ code === 92 || // \
448
+ code === 45 || // -
449
+ code === 95 || // _
450
+ code === 46 || // .
451
+ code === 32 // space
452
+ ) {
453
+ safe.push(path[i]);
454
+ }
455
+ else {
456
+ throw createError(`Invalid character in path at position ${i}: "${path[i]}"`);
457
+ }
458
+ }
459
+ return safe.join('');
460
+ }
461
+ /**
462
+ * Maximum allowed argument length.
463
+ */
464
+ const MAX_ARG_LENGTH = 1000;
465
+ /**
466
+ * Escapes a general git argument for safe use in shell commands.
467
+ *
468
+ * @param arg - Argument to escape
469
+ * @returns Safe argument string
470
+ * @throws {Error} If argument contains invalid characters
471
+ */
472
+ function escapeGitArg(arg) {
473
+ if (!arg || typeof arg !== 'string') {
474
+ throw createError('Argument is required');
475
+ }
476
+ if (arg.length > MAX_ARG_LENGTH) {
477
+ throw createError(`Argument exceeds maximum length of ${MAX_ARG_LENGTH}`);
478
+ }
479
+ const safe = [];
480
+ for (let i = 0; i < arg.length; i++) {
481
+ const code = arg.charCodeAt(i);
482
+ // Allow: a-z, A-Z, 0-9, space, @, ., -, _, <, >, +
483
+ if ((code >= 97 && code <= 122) || // a-z
484
+ (code >= 65 && code <= 90) || // A-Z
485
+ (code >= 48 && code <= 57) || // 0-9
486
+ code === 32 || // space
487
+ code === 64 || // @
488
+ code === 46 || // .
489
+ code === 45 || // -
490
+ code === 95 || // _
491
+ code === 60 || // <
492
+ code === 62 || // >
493
+ code === 43 // +
494
+ ) {
495
+ safe.push(arg[i]);
496
+ }
497
+ else {
498
+ throw createError(`Invalid character in argument at position ${i}: "${arg[i]}"`);
499
+ }
500
+ }
501
+ return safe.join('');
502
+ }
503
+
504
+ /**
505
+ * Safe copies of Date built-in via factory function and static methods.
506
+ *
507
+ * Since constructors cannot be safely captured via Object.assign, this module
508
+ * provides a factory function that uses Reflect.construct internally.
509
+ *
510
+ * These references are captured at module initialization time to protect against
511
+ * prototype pollution attacks. Import only what you need for tree-shaking.
512
+ *
513
+ * @module @hyperfrontend/immutable-api-utils/built-in-copy/date
514
+ */
515
+ // Capture references at module initialization time
516
+ const _Date = globalThis.Date;
517
+ const _Reflect = globalThis.Reflect;
518
+ function createDate(...args) {
519
+ return _Reflect.construct(_Date, args);
520
+ }
521
+
522
+ /**
523
+ * Safe copies of Number built-in methods and constants.
524
+ *
525
+ * These references are captured at module initialization time to protect against
526
+ * prototype pollution attacks. Import only what you need for tree-shaking.
527
+ *
528
+ * @module @hyperfrontend/immutable-api-utils/built-in-copy/number
529
+ */
530
+ // Capture references at module initialization time
531
+ const _parseInt = globalThis.parseInt;
532
+ const _isNaN = globalThis.isNaN;
533
+ // ============================================================================
534
+ // Parsing
535
+ // ============================================================================
536
+ /**
537
+ * (Safe copy) Parses a string and returns an integer.
538
+ */
539
+ const parseInt = _parseInt;
540
+ // ============================================================================
541
+ // Global Type Checking (legacy, less strict)
542
+ // ============================================================================
543
+ /**
544
+ * (Safe copy) Global isNaN function (coerces to number first, less strict than Number.isNaN).
545
+ */
546
+ const globalIsNaN = _isNaN;
547
+
548
+ /**
549
+ * Creates a lightweight git tag.
550
+ *
551
+ * @param options - Tag creation options
552
+ * @returns A new GitTag object
553
+ *
554
+ * @example
555
+ * const tag = createLightweightTag({
556
+ * name: 'v1.0.0',
557
+ * commitHash: 'abc123...',
558
+ * })
559
+ */
560
+ function createLightweightTag(options) {
561
+ return {
562
+ name: options.name,
563
+ commitHash: options.commitHash,
564
+ type: 'lightweight',
565
+ };
566
+ }
567
+ /**
568
+ * Creates an annotated git tag.
569
+ *
570
+ * @param options - Tag creation options
571
+ * @returns A new GitTag object
572
+ *
573
+ * @example
574
+ * const tag = createAnnotatedTag({
575
+ * name: 'v1.0.0',
576
+ * commitHash: 'abc123...',
577
+ * message: 'Release v1.0.0',
578
+ * taggerName: 'John Doe',
579
+ * taggerEmail: 'john@example.com',
580
+ * tagDate: '2026-03-12T10:00:00Z',
581
+ * })
582
+ */
583
+ function createAnnotatedTag(options) {
584
+ return {
585
+ name: options.name,
586
+ commitHash: options.commitHash,
587
+ type: 'annotated',
588
+ message: options.message,
589
+ taggerName: options.taggerName,
590
+ taggerEmail: options.taggerEmail,
591
+ tagDate: options.tagDate,
592
+ };
593
+ }
594
+
595
+ /**
596
+ * Default tag options.
597
+ */
598
+ const DEFAULT_TAG_OPTIONS = {
599
+ timeout: 10000,
600
+ };
601
+ /**
602
+ * Gets all tags from the repository.
603
+ *
604
+ * @param options - Tag listing options
605
+ * @returns Array of GitTag objects
606
+ *
607
+ * @example
608
+ * const tags = getTags()
609
+ * const versionTags = getTags({ pattern: 'v' })
610
+ */
611
+ function getTags(options = {}) {
612
+ const opts = { ...DEFAULT_TAG_OPTIONS, ...options };
613
+ const args = ['tag', '-l', '--sort=-creatordate'];
614
+ if (opts.pattern) {
615
+ const safePattern = escapeGitTagPattern(opts.pattern);
616
+ args.push(safePattern + '*');
617
+ }
618
+ try {
619
+ const output = node_child_process.execSync(`git ${args.join(' ')}`, {
620
+ encoding: 'utf-8',
621
+ cwd: opts.cwd,
622
+ timeout: opts.timeout,
623
+ stdio: ['pipe', 'pipe', 'pipe'],
624
+ });
625
+ const tagNames = output
626
+ .split('\n')
627
+ .map((line) => line.trim())
628
+ .filter((line) => line.length > 0);
629
+ // Limit results if requested
630
+ const limitedNames = opts.maxCount ? tagNames.slice(0, opts.maxCount) : tagNames;
631
+ // Get details for each tag
632
+ const tags = [];
633
+ for (const name of limitedNames) {
634
+ const tag = getTagDetails(name, opts);
635
+ if (tag) {
636
+ tags.push(tag);
637
+ }
638
+ }
639
+ return tags;
640
+ }
641
+ catch {
642
+ return [];
643
+ }
644
+ }
645
+ /**
646
+ * Gets detailed information about a specific tag.
647
+ *
648
+ * @param name - The tag name to look up
649
+ * @param options - Configuration for the tag operation
650
+ * @returns GitTag or null if not found
651
+ *
652
+ * @example
653
+ * const tag = getTag('v1.0.0')
654
+ */
655
+ function getTag(name, options = {}) {
656
+ return getTagDetails(name, { ...DEFAULT_TAG_OPTIONS, ...options });
657
+ }
658
+ /**
659
+ * Gets tag details including type and commit hash.
660
+ *
661
+ * @param name - The tag name to retrieve details for
662
+ * @param options - Configuration for the tag operation
663
+ * @returns GitTag or null
664
+ */
665
+ function getTagDetails(name, options) {
666
+ const safeName = escapeGitRef(name);
667
+ try {
668
+ // Get the commit hash the tag points to
669
+ const commitHash = node_child_process.execSync(`git rev-list -1 ${safeName}`, {
670
+ encoding: 'utf-8',
671
+ cwd: options.cwd,
672
+ timeout: options.timeout,
673
+ stdio: ['pipe', 'pipe', 'pipe'],
674
+ }).trim();
675
+ // Check if it's an annotated tag by trying to get tag message
676
+ try {
677
+ const tagInfo = node_child_process.execSync(`git cat-file tag ${safeName}`, {
678
+ encoding: 'utf-8',
679
+ cwd: options.cwd,
680
+ timeout: options.timeout,
681
+ stdio: ['pipe', 'pipe', 'pipe'],
682
+ });
683
+ // Parse annotated tag info
684
+ const parsed = parseAnnotatedTagInfo(tagInfo);
685
+ return createAnnotatedTag({
686
+ name,
687
+ commitHash,
688
+ message: parsed.message,
689
+ taggerName: parsed.taggerName,
690
+ taggerEmail: parsed.taggerEmail,
691
+ tagDate: parsed.tagDate,
692
+ });
693
+ }
694
+ catch {
695
+ // Not an annotated tag, it's lightweight
696
+ return createLightweightTag({
697
+ name,
698
+ commitHash,
699
+ });
700
+ }
701
+ }
702
+ catch {
703
+ return null;
704
+ }
705
+ }
706
+ /**
707
+ * Parses annotated tag info from git cat-file output.
708
+ *
709
+ * @param info - Raw tag info
710
+ * @returns Parsed info
711
+ */
712
+ function parseAnnotatedTagInfo(info) {
713
+ const lines = info.split('\n');
714
+ let taggerName = '';
715
+ let taggerEmail = '';
716
+ let tagDate = '';
717
+ let messageStart = -1;
718
+ for (let i = 0; i < lines.length; i++) {
719
+ const line = lines[i];
720
+ if (startsWithPrefix$1(line, 'tagger ')) {
721
+ const taggerLine = line.slice(7);
722
+ const parsed = parseTaggerLine(taggerLine);
723
+ taggerName = parsed.name;
724
+ taggerEmail = parsed.email;
725
+ tagDate = parsed.date;
726
+ }
727
+ // Empty line marks start of message
728
+ if (line === '' && messageStart === -1) {
729
+ messageStart = i + 1;
730
+ break;
731
+ }
732
+ }
733
+ const message = messageStart >= 0 ? lines.slice(messageStart).join('\n').trim() : '';
734
+ return {
735
+ message,
736
+ taggerName,
737
+ taggerEmail,
738
+ tagDate,
739
+ };
740
+ }
741
+ /**
742
+ * Parses tagger line from annotated tag.
743
+ * Format: Name <email> timestamp timezone
744
+ *
745
+ * @param line - Raw tagger line from git output
746
+ * @returns Parsed tagger info with name, email, and date
747
+ */
748
+ function parseTaggerLine(line) {
749
+ let name = '';
750
+ let email = '';
751
+ let date = '';
752
+ // Find email in angle brackets
753
+ let emailStart = -1;
754
+ let emailEnd = -1;
755
+ for (let i = 0; i < line.length; i++) {
756
+ if (line[i] === '<') {
757
+ emailStart = i + 1;
758
+ }
759
+ else if (line[i] === '>' && emailStart !== -1) {
760
+ emailEnd = i;
761
+ break;
762
+ }
763
+ }
764
+ if (emailStart !== -1 && emailEnd !== -1) {
765
+ name = line.slice(0, emailStart - 1).trim();
766
+ email = line.slice(emailStart, emailEnd);
767
+ // Rest is timestamp and timezone
768
+ const rest = line.slice(emailEnd + 1).trim();
769
+ const parts = rest.split(' ');
770
+ if (parts.length >= 1) {
771
+ // Convert Unix timestamp to ISO 8601
772
+ const timestamp = parseInt(parts[0], 10);
773
+ if (!globalIsNaN(timestamp)) {
774
+ date = createDate(timestamp * 1000).toISOString();
775
+ }
776
+ }
777
+ }
778
+ return { name, email, date };
779
+ }
780
+ /**
781
+ * Checks if a tag exists.
782
+ *
783
+ * @param name - The tag name to verify
784
+ * @param options - Configuration for the tag operation
785
+ * @returns True if tag exists
786
+ *
787
+ * @example
788
+ * if (tagExists('v1.0.0')) { ... }
789
+ */
790
+ function tagExists(name, options = {}) {
791
+ const opts = { ...DEFAULT_TAG_OPTIONS, ...options };
792
+ const safeName = escapeGitRef(name);
793
+ try {
794
+ node_child_process.execSync(`git rev-parse ${safeName}`, {
795
+ encoding: 'utf-8',
796
+ cwd: opts.cwd,
797
+ timeout: opts.timeout,
798
+ stdio: ['pipe', 'pipe', 'pipe'],
799
+ });
800
+ return true;
801
+ }
802
+ catch {
803
+ return false;
804
+ }
805
+ }
806
+ /**
807
+ * Gets the latest tag (by creation date).
808
+ *
809
+ * @param options - Tag options with optional pattern
810
+ * @returns Latest GitTag or null
811
+ *
812
+ * @example
813
+ * const latest = getLatestTag()
814
+ * const latestVersion = getLatestTag({ pattern: 'v' })
815
+ */
816
+ function getLatestTag(options = {}) {
817
+ const tags = getTags({ ...options, maxCount: 1 });
818
+ return tags[0] ?? null;
819
+ }
820
+ /**
821
+ * Gets tags that match a package name.
822
+ *
823
+ * @param packageName - Package name to match
824
+ * @param options - Tag options
825
+ * @returns Array of matching tags
826
+ *
827
+ * @example
828
+ * const tags = getTagsForPackage('@scope/pkg')
829
+ */
830
+ function getTagsForPackage(packageName, options = {}) {
831
+ // Common patterns: @scope/pkg@version, pkg@version, pkg-vversion
832
+ const allTags = getTags(options);
833
+ return allTags.filter((tag) => {
834
+ // Check if tag starts with package name followed by @ or -v
835
+ const name = tag.name;
836
+ // Pattern: package@version
837
+ if (startsWithPrefix$1(name, packageName + '@')) {
838
+ return true;
839
+ }
840
+ // Pattern: package-v
841
+ if (startsWithPrefix$1(name, packageName + '-v')) {
842
+ return true;
843
+ }
844
+ return false;
845
+ });
846
+ }
847
+ // ============================================================================
848
+ // Helper functions
849
+ // ============================================================================
850
+ /**
851
+ * Checks if string starts with prefix (no regex).
852
+ *
853
+ * @param str - The string to check
854
+ * @param prefix - The prefix to look for
855
+ * @returns True if str starts with the given prefix
856
+ */
857
+ function startsWithPrefix$1(str, prefix) {
858
+ if (prefix.length > str.length)
859
+ return false;
860
+ for (let i = 0; i < prefix.length; i++) {
861
+ if (str[i] !== prefix[i])
862
+ return false;
863
+ }
864
+ return true;
865
+ }
866
+ /**
867
+ * Maximum tag pattern length.
868
+ */
869
+ const MAX_PATTERN_LENGTH = 256;
870
+ /**
871
+ * Escapes a tag pattern for safe use in git commands.
872
+ *
873
+ * @param pattern - Pattern to escape
874
+ * @returns Safe pattern string
875
+ */
876
+ function escapeGitTagPattern(pattern) {
877
+ if (!pattern || typeof pattern !== 'string') {
878
+ throw createError('Pattern is required');
879
+ }
880
+ if (pattern.length > MAX_PATTERN_LENGTH) {
881
+ throw createError(`Pattern exceeds maximum length of ${MAX_PATTERN_LENGTH}`);
882
+ }
883
+ const safe = [];
884
+ for (let i = 0; i < pattern.length; i++) {
885
+ const code = pattern.charCodeAt(i);
886
+ // Allow: a-z, A-Z, 0-9, /, -, _, ., @
887
+ if ((code >= 97 && code <= 122) || // a-z
888
+ (code >= 65 && code <= 90) || // A-Z
889
+ (code >= 48 && code <= 57) || // 0-9
890
+ code === 47 || // /
891
+ code === 45 || // -
892
+ code === 95 || // _
893
+ code === 46 || // .
894
+ code === 64 // @
895
+ ) {
896
+ safe.push(pattern[i]);
897
+ }
898
+ else {
899
+ throw createError(`Invalid character in pattern at position ${i}: "${pattern[i]}"`);
900
+ }
901
+ }
902
+ return safe.join('');
903
+ }
904
+
905
+ /**
906
+ * Creates a new tag.
907
+ *
908
+ * @param name - The name for the new tag
909
+ * @param options - Configuration including optional message for annotated tags
910
+ * @returns Created GitTag
911
+ *
912
+ * @example
913
+ * // Create lightweight tag
914
+ * const tag = createTag('v1.0.0')
915
+ *
916
+ * // Create annotated tag
917
+ * const tag = createTag('v1.0.0', { message: 'Release v1.0.0' })
918
+ */
919
+ function createTag(name, options = {}) {
920
+ const opts = { ...DEFAULT_TAG_OPTIONS, ...options };
921
+ const safeName = escapeGitRef(name);
922
+ const args = ['tag'];
923
+ if (opts.force) {
924
+ args.push('-f');
925
+ }
926
+ if (opts.message) {
927
+ // Annotated tag
928
+ args.push('-a');
929
+ args.push(safeName);
930
+ args.push('-m');
931
+ args.push(`"${escapeGitMessage(opts.message)}"`);
932
+ }
933
+ else {
934
+ // Lightweight tag
935
+ args.push(safeName);
936
+ }
937
+ if (opts.target) {
938
+ args.push(escapeGitRef(opts.target));
939
+ }
940
+ try {
941
+ node_child_process.execSync(`git ${args.join(' ')}`, {
942
+ encoding: 'utf-8',
943
+ cwd: opts.cwd,
944
+ timeout: opts.timeout,
945
+ stdio: ['pipe', 'pipe', 'pipe'],
946
+ });
947
+ // Get the created tag
948
+ const tag = getTag(name, opts);
949
+ if (!tag) {
950
+ throw createError(`Failed to retrieve created tag: ${name}`);
951
+ }
952
+ return tag;
953
+ }
954
+ catch (error) {
955
+ if (error instanceof Error) {
956
+ throw createError(`Failed to create tag ${name}: ${error.message}`);
957
+ }
958
+ throw error;
959
+ }
960
+ }
961
+ /**
962
+ * Deletes a tag.
963
+ *
964
+ * @param name - The tag name to delete
965
+ * @param options - Configuration for the tag operation
966
+ * @returns True if deleted
967
+ *
968
+ * @example
969
+ * const deleted = deleteTag('v1.0.0')
970
+ */
971
+ function deleteTag(name, options = {}) {
972
+ const opts = { ...DEFAULT_TAG_OPTIONS, ...options };
973
+ const safeName = escapeGitRef(name);
974
+ try {
975
+ node_child_process.execSync(`git tag -d ${safeName}`, {
976
+ encoding: 'utf-8',
977
+ cwd: opts.cwd,
978
+ timeout: opts.timeout,
979
+ stdio: ['pipe', 'pipe', 'pipe'],
980
+ });
981
+ return true;
982
+ }
983
+ catch {
984
+ return false;
985
+ }
986
+ }
987
+ /**
988
+ * Pushes a tag to a remote.
989
+ *
990
+ * @param name - The tag to push to the remote
991
+ * @param remote - Remote name (defaults to 'origin')
992
+ * @param options - Configuration for the tag operation
993
+ * @returns True if pushed successfully
994
+ *
995
+ * @example
996
+ * pushTag('v1.0.0')
997
+ * pushTag('v1.0.0', 'upstream')
998
+ */
999
+ function pushTag(name, remote = 'origin', options = {}) {
1000
+ const opts = { ...DEFAULT_TAG_OPTIONS, ...options };
1001
+ const safeName = escapeGitRef(name);
1002
+ const safeRemote = escapeGitRef(remote);
1003
+ try {
1004
+ node_child_process.execSync(`git push ${safeRemote} ${safeName}`, {
1005
+ encoding: 'utf-8',
1006
+ cwd: opts.cwd,
1007
+ timeout: opts.timeout * 3, // Allow more time for network
1008
+ stdio: ['pipe', 'pipe', 'pipe'],
1009
+ });
1010
+ return true;
1011
+ }
1012
+ catch {
1013
+ return false;
1014
+ }
1015
+ }
1016
+ // ============================================================================
1017
+ // Security helpers
1018
+ // ============================================================================
1019
+ /**
1020
+ * Maximum message length.
1021
+ */
1022
+ const MAX_MESSAGE_LENGTH = 10000;
1023
+ /**
1024
+ * Escapes a message for safe use in git commands.
1025
+ *
1026
+ * @param message - Message to escape
1027
+ * @returns Safe message string
1028
+ */
1029
+ function escapeGitMessage(message) {
1030
+ if (!message || typeof message !== 'string') {
1031
+ throw createError('Message is required');
1032
+ }
1033
+ if (message.length > MAX_MESSAGE_LENGTH) {
1034
+ throw createError(`Message exceeds maximum length of ${MAX_MESSAGE_LENGTH}`);
1035
+ }
1036
+ const safe = [];
1037
+ for (let i = 0; i < message.length; i++) {
1038
+ const char = message[i];
1039
+ const code = message.charCodeAt(i);
1040
+ // Escape double quotes and backslashes
1041
+ if (char === '"' || char === '\\') {
1042
+ safe.push('\\');
1043
+ safe.push(char);
1044
+ }
1045
+ // Allow printable ASCII and common whitespace
1046
+ else if ((code >= 32 && code <= 126) || // Printable ASCII
1047
+ code === 10 || // newline
1048
+ code === 13 || // carriage return
1049
+ code === 9 // tab
1050
+ ) {
1051
+ safe.push(char);
1052
+ }
1053
+ // Skip other control characters
1054
+ }
1055
+ return safe.join('');
1056
+ }
1057
+
1058
+ /**
1059
+ * Default commit options.
1060
+ */
1061
+ const DEFAULT_COMMIT_OPTIONS = {
1062
+ timeout: 30000,
1063
+ };
1064
+ /**
1065
+ * Creates a new commit.
1066
+ *
1067
+ * @param message - Commit message (subject line)
1068
+ * @param options - Create options
1069
+ * @returns Created GitCommit
1070
+ *
1071
+ * @example
1072
+ * const commit = createCommit('feat: add new feature')
1073
+ * const commit = createCommit('fix: resolve bug', { body: 'Detailed description' })
1074
+ */
1075
+ function commit(message, options = {}) {
1076
+ const opts = { ...DEFAULT_COMMIT_OPTIONS, ...options };
1077
+ // noEdit is only valid when amending - reuse existing commit message
1078
+ const isNoEditAmend = opts.amend && opts.noEdit;
1079
+ if (!isNoEditAmend && (!message || typeof message !== 'string')) {
1080
+ throw createError('Commit message is required');
1081
+ }
1082
+ const args = ['commit'];
1083
+ if (isNoEditAmend) {
1084
+ // Amend without changing the message
1085
+ args.push('--amend', '--no-edit');
1086
+ }
1087
+ else {
1088
+ const safeMessage = escapeGitMessage(message);
1089
+ // Build message with optional body
1090
+ let fullMessage = safeMessage;
1091
+ if (opts.body) {
1092
+ const safeBody = escapeGitMessage(opts.body);
1093
+ fullMessage = `${safeMessage}\n\n${safeBody}`;
1094
+ }
1095
+ args.push('-m', `"${fullMessage}"`);
1096
+ if (opts.amend) {
1097
+ args.push('--amend');
1098
+ }
1099
+ }
1100
+ if (opts.allowEmpty) {
1101
+ args.push('--allow-empty');
1102
+ }
1103
+ if (opts.sign) {
1104
+ args.push('-S');
1105
+ }
1106
+ if (opts.noVerify) {
1107
+ args.push('--no-verify');
1108
+ }
1109
+ if (opts.author) {
1110
+ const safeAuthor = escapeAuthor(opts.author);
1111
+ args.push(`--author="${safeAuthor}"`);
1112
+ }
1113
+ // Add specific files if provided
1114
+ if (opts.files && opts.files.length > 0) {
1115
+ args.push('--');
1116
+ for (const file of opts.files) {
1117
+ args.push(escapeFilePath(file));
1118
+ }
1119
+ }
1120
+ try {
1121
+ node_child_process.execSync(`git ${args.join(' ')}`, {
1122
+ encoding: 'utf-8',
1123
+ cwd: opts.cwd,
1124
+ timeout: opts.timeout,
1125
+ stdio: ['pipe', 'pipe', 'pipe'],
1126
+ });
1127
+ // Get the created commit
1128
+ const commit = getCommit('HEAD', opts);
1129
+ if (!commit) {
1130
+ throw createError('Failed to retrieve created commit');
1131
+ }
1132
+ return commit;
1133
+ }
1134
+ catch (error) {
1135
+ if (error instanceof Error) {
1136
+ throw createError(`Failed to create commit: ${error.message}`);
1137
+ }
1138
+ throw error;
1139
+ }
1140
+ }
1141
+ /**
1142
+ * Amends the last commit with new message.
1143
+ *
1144
+ * @param message - The new commit message to use
1145
+ * @param options - Configuration for the commit operation
1146
+ * @returns GitCommit object representing the amended commit
1147
+ *
1148
+ * @example
1149
+ * const commit = amendCommit('feat: improved feature')
1150
+ */
1151
+ function amendCommit(message, options = {}) {
1152
+ return commit(message, { ...options, amend: true });
1153
+ }
1154
+ /**
1155
+ * Amends the last commit without changing the message.
1156
+ * Useful for adding staged changes to the previous commit.
1157
+ *
1158
+ * @param options - Configuration for the commit operation
1159
+ * @returns GitCommit object representing the amended commit
1160
+ *
1161
+ * @example
1162
+ * stage(['extra-file.ts'])
1163
+ * amendCommitNoEdit() // adds staged files to last commit
1164
+ */
1165
+ function amendCommitNoEdit(options = {}) {
1166
+ return commit('', { ...options, amend: true, noEdit: true });
1167
+ }
1168
+ /**
1169
+ * Creates an empty commit (useful for CI triggers).
1170
+ *
1171
+ * @param message - Text for the empty commit
1172
+ * @param options - Configuration for the commit operation
1173
+ * @returns GitCommit object representing the new empty commit
1174
+ *
1175
+ * @example
1176
+ * const commit = createEmptyCommit('chore: trigger CI')
1177
+ */
1178
+ function createEmptyCommit(message, options = {}) {
1179
+ return commit(message, { ...options, allowEmpty: true });
1180
+ }
1181
+ // ============================================================================
1182
+ // Security helpers - character-by-character validation (no regex)
1183
+ // ============================================================================
1184
+ /**
1185
+ * Maximum file path length.
1186
+ */
1187
+ const MAX_PATH_LENGTH = 4096;
1188
+ /**
1189
+ * Escapes a file path for safe use in git commands.
1190
+ *
1191
+ * @param path - Path to escape
1192
+ * @returns Safe path string
1193
+ */
1194
+ function escapeFilePath(path) {
1195
+ if (!path || typeof path !== 'string') {
1196
+ throw createError('File path is required');
1197
+ }
1198
+ if (path.length > MAX_PATH_LENGTH) {
1199
+ throw createError(`Path exceeds maximum length of ${MAX_PATH_LENGTH}`);
1200
+ }
1201
+ const safe = [];
1202
+ for (let i = 0; i < path.length; i++) {
1203
+ const code = path.charCodeAt(i);
1204
+ // Allow: a-z, A-Z, 0-9, /, \, -, _, ., space
1205
+ if ((code >= 97 && code <= 122) || // a-z
1206
+ (code >= 65 && code <= 90) || // A-Z
1207
+ (code >= 48 && code <= 57) || // 0-9
1208
+ code === 47 || // /
1209
+ code === 92 || // \
1210
+ code === 45 || // -
1211
+ code === 95 || // _
1212
+ code === 46 || // .
1213
+ code === 32 // space
1214
+ ) {
1215
+ safe.push(path[i]);
1216
+ }
1217
+ else {
1218
+ throw createError(`Invalid character in path at position ${i}: "${path[i]}"`);
1219
+ }
1220
+ }
1221
+ return safe.join('');
1222
+ }
1223
+ /**
1224
+ * Maximum author length.
1225
+ */
1226
+ const MAX_AUTHOR_LENGTH = 500;
1227
+ /**
1228
+ * Escapes an author string for safe use in git commands.
1229
+ * Format: "Name <email>"
1230
+ *
1231
+ * @param author - Author to escape
1232
+ * @returns Safe author string
1233
+ */
1234
+ function escapeAuthor(author) {
1235
+ if (!author || typeof author !== 'string') {
1236
+ throw createError('Author is required');
1237
+ }
1238
+ if (author.length > MAX_AUTHOR_LENGTH) {
1239
+ throw createError(`Author exceeds maximum length of ${MAX_AUTHOR_LENGTH}`);
1240
+ }
1241
+ const safe = [];
1242
+ for (let i = 0; i < author.length; i++) {
1243
+ const code = author.charCodeAt(i);
1244
+ // Allow: a-z, A-Z, 0-9, space, @, ., -, _, <, >
1245
+ if ((code >= 97 && code <= 122) || // a-z
1246
+ (code >= 65 && code <= 90) || // A-Z
1247
+ (code >= 48 && code <= 57) || // 0-9
1248
+ code === 32 || // space
1249
+ code === 64 || // @
1250
+ code === 46 || // .
1251
+ code === 45 || // -
1252
+ code === 95 || // _
1253
+ code === 60 || // <
1254
+ code === 62 // >
1255
+ ) {
1256
+ safe.push(author[i]);
1257
+ }
1258
+ else {
1259
+ throw createError(`Invalid character in author at position ${i}: "${author[i]}"`);
1260
+ }
1261
+ }
1262
+ return safe.join('');
1263
+ }
1264
+
1265
+ /**
1266
+ * Stages files for commit.
1267
+ *
1268
+ * @param files - Array of file paths relative to working directory
1269
+ * @param options - Configuration for the staging operation
1270
+ * @returns True if staging succeeded
1271
+ *
1272
+ * @example
1273
+ * stage(['package.json', 'CHANGELOG.md'])
1274
+ * stage(['.'], { all: true })
1275
+ */
1276
+ function stage(files, options = {}) {
1277
+ const opts = { ...DEFAULT_COMMIT_OPTIONS, ...options };
1278
+ const args = ['add'];
1279
+ if (opts.all) {
1280
+ args.push('-A');
1281
+ }
1282
+ else if (opts.update) {
1283
+ args.push('-u');
1284
+ }
1285
+ if (opts.force) {
1286
+ args.push('-f');
1287
+ }
1288
+ // Add files
1289
+ for (const file of files) {
1290
+ args.push(escapeFilePath(file));
1291
+ }
1292
+ try {
1293
+ node_child_process.execSync(`git ${args.join(' ')}`, {
1294
+ encoding: 'utf-8',
1295
+ cwd: opts.cwd,
1296
+ timeout: opts.timeout,
1297
+ stdio: ['pipe', 'pipe', 'pipe'],
1298
+ });
1299
+ return true;
1300
+ }
1301
+ catch {
1302
+ return false;
1303
+ }
1304
+ }
1305
+ /**
1306
+ * Unstages files.
1307
+ *
1308
+ * @param files - Array of file paths to remove from staging area
1309
+ * @param options - Configuration for the unstage operation
1310
+ * @returns True if unstaging succeeded
1311
+ *
1312
+ * @example
1313
+ * unstage(['package.json'])
1314
+ */
1315
+ function unstage(files, options = {}) {
1316
+ const opts = { ...DEFAULT_COMMIT_OPTIONS, ...options };
1317
+ const args = ['reset', 'HEAD', '--'];
1318
+ for (const file of files) {
1319
+ args.push(escapeFilePath(file));
1320
+ }
1321
+ try {
1322
+ node_child_process.execSync(`git ${args.join(' ')}`, {
1323
+ encoding: 'utf-8',
1324
+ cwd: opts.cwd,
1325
+ timeout: opts.timeout,
1326
+ stdio: ['pipe', 'pipe', 'pipe'],
1327
+ });
1328
+ return true;
1329
+ }
1330
+ catch {
1331
+ return false;
1332
+ }
1333
+ }
1334
+ /**
1335
+ * Stages all changes (tracked and untracked).
1336
+ *
1337
+ * @param options - Configuration for the staging operation
1338
+ * @returns True if all changes were successfully added to the index
1339
+ *
1340
+ * @example
1341
+ * stageAll() // stages all tracked and untracked changes
1342
+ */
1343
+ function stageAll(options = {}) {
1344
+ return stage(['.'], { ...options, all: true });
1345
+ }
1346
+ /**
1347
+ * Checks if there are staged changes.
1348
+ *
1349
+ * @param options - Configuration for the operation
1350
+ * @returns True if there are staged changes ready to commit
1351
+ *
1352
+ * @example
1353
+ * if (hasStagedChanges()) { createCommit('...') }
1354
+ */
1355
+ function hasStagedChanges(options = {}) {
1356
+ const opts = { ...DEFAULT_COMMIT_OPTIONS, ...options };
1357
+ try {
1358
+ node_child_process.execSync('git diff --cached --quiet', {
1359
+ encoding: 'utf-8',
1360
+ cwd: opts.cwd,
1361
+ timeout: opts.timeout,
1362
+ stdio: ['pipe', 'pipe', 'pipe'],
1363
+ });
1364
+ // Exit code 0 means no changes
1365
+ return false;
1366
+ }
1367
+ catch {
1368
+ // Exit code 1 means there are changes
1369
+ return true;
1370
+ }
1371
+ }
1372
+ /**
1373
+ * Checks if there are unstaged changes (working tree dirty).
1374
+ *
1375
+ * @param options - Configuration for the operation
1376
+ * @returns True if there are unstaged changes in the working tree
1377
+ *
1378
+ * @example
1379
+ * if (hasUnstagedChanges()) { stage(['.']) }
1380
+ */
1381
+ function hasUnstagedChanges(options = {}) {
1382
+ const opts = { ...DEFAULT_COMMIT_OPTIONS, ...options };
1383
+ try {
1384
+ node_child_process.execSync('git diff --quiet', {
1385
+ encoding: 'utf-8',
1386
+ cwd: opts.cwd,
1387
+ timeout: opts.timeout,
1388
+ stdio: ['pipe', 'pipe', 'pipe'],
1389
+ });
1390
+ // Exit code 0 means no changes
1391
+ return false;
1392
+ }
1393
+ catch {
1394
+ // Exit code 1 means there are changes
1395
+ return true;
1396
+ }
1397
+ }
1398
+
1399
+ /**
1400
+ * Gets the current HEAD commit hash.
1401
+ *
1402
+ * @param options - Git operation configuration
1403
+ * @returns HEAD commit hash or null
1404
+ *
1405
+ * @example
1406
+ * const head = getHead()
1407
+ */
1408
+ function getHead(options = {}) {
1409
+ const opts = { ...DEFAULT_COMMIT_OPTIONS, ...options };
1410
+ try {
1411
+ return node_child_process.execSync('git rev-parse HEAD', {
1412
+ encoding: 'utf-8',
1413
+ cwd: opts.cwd,
1414
+ timeout: opts.timeout,
1415
+ stdio: ['pipe', 'pipe', 'pipe'],
1416
+ }).trim();
1417
+ }
1418
+ catch {
1419
+ return null;
1420
+ }
1421
+ }
1422
+ /**
1423
+ * Gets the current branch name.
1424
+ *
1425
+ * @param options - Configuration for the operation
1426
+ * @returns Branch name or null if detached
1427
+ *
1428
+ * @example
1429
+ * const branch = getCurrentBranch()
1430
+ */
1431
+ function getCurrentBranch(options = {}) {
1432
+ const opts = { ...DEFAULT_COMMIT_OPTIONS, ...options };
1433
+ try {
1434
+ const result = node_child_process.execSync('git symbolic-ref --short HEAD', {
1435
+ encoding: 'utf-8',
1436
+ cwd: opts.cwd,
1437
+ timeout: opts.timeout,
1438
+ stdio: ['pipe', 'pipe', 'pipe'],
1439
+ }).trim();
1440
+ return result || null;
1441
+ }
1442
+ catch {
1443
+ // Detached HEAD or not a git repo
1444
+ return null;
1445
+ }
1446
+ }
1447
+ /**
1448
+ * Checks if there are untracked files.
1449
+ *
1450
+ * @param options - Configuration for the operation
1451
+ * @returns True if there are untracked files in the working directory
1452
+ */
1453
+ function hasUntrackedFiles(options = {}) {
1454
+ const opts = { ...DEFAULT_COMMIT_OPTIONS, ...options };
1455
+ try {
1456
+ const result = node_child_process.execSync('git ls-files --others --exclude-standard', {
1457
+ encoding: 'utf-8',
1458
+ cwd: opts.cwd,
1459
+ timeout: opts.timeout,
1460
+ stdio: ['pipe', 'pipe', 'pipe'],
1461
+ }).trim();
1462
+ return result.length > 0;
1463
+ }
1464
+ catch {
1465
+ return false;
1466
+ }
1467
+ }
1468
+
1469
+ /**
1470
+ * Default status options.
1471
+ */
1472
+ const DEFAULT_STATUS_OPTIONS = {
1473
+ timeout: 10000,
1474
+ };
1475
+ /**
1476
+ * Gets the full repository status.
1477
+ *
1478
+ * @param options - Configuration for the status query
1479
+ * @returns Comprehensive repository status information
1480
+ *
1481
+ * @example
1482
+ * const status = getStatus()
1483
+ * if (!status.clean) {
1484
+ * console.log('Working tree has changes')
1485
+ * }
1486
+ */
1487
+ function getStatus(options = {}) {
1488
+ const opts = { ...DEFAULT_STATUS_OPTIONS, ...options };
1489
+ // Get porcelain status with branch info
1490
+ const output = node_child_process.execSync('git status --porcelain=v2 --branch', {
1491
+ encoding: 'utf-8',
1492
+ cwd: opts.cwd,
1493
+ timeout: opts.timeout,
1494
+ stdio: ['pipe', 'pipe', 'pipe'],
1495
+ });
1496
+ return parseStatus(output);
1497
+ }
1498
+ /**
1499
+ * Parses git status porcelain v2 output.
1500
+ *
1501
+ * @param output - Raw status output
1502
+ * @returns Parsed status
1503
+ */
1504
+ function parseStatus(output) {
1505
+ const lines = output.split('\n');
1506
+ let branch = null;
1507
+ let detached = false;
1508
+ let upstream;
1509
+ let ahead = 0;
1510
+ let behind = 0;
1511
+ const staged = [];
1512
+ const modified = [];
1513
+ const untracked = [];
1514
+ let hasConflicts = false;
1515
+ for (const line of lines) {
1516
+ if (!line)
1517
+ continue;
1518
+ // Branch headers
1519
+ if (startsWithPrefix(line, '# branch.head ')) {
1520
+ const branchName = line.slice(14);
1521
+ if (branchName === '(detached)') {
1522
+ detached = true;
1523
+ }
1524
+ else {
1525
+ branch = branchName;
1526
+ }
1527
+ }
1528
+ else if (startsWithPrefix(line, '# branch.upstream ')) {
1529
+ upstream = line.slice(18);
1530
+ }
1531
+ else if (startsWithPrefix(line, '# branch.ab ')) {
1532
+ const ab = parseAheadBehind(line.slice(12));
1533
+ ahead = ab.ahead;
1534
+ behind = ab.behind;
1535
+ }
1536
+ // Changed entries (ordinary changed)
1537
+ else if (line[0] === '1') {
1538
+ const entry = parseChangedEntry(line);
1539
+ if (entry) {
1540
+ if (entry.indexStatus) {
1541
+ staged.push(entry);
1542
+ }
1543
+ if (entry.workTreeStatus && entry.workTreeStatus !== 'untracked') {
1544
+ modified.push(entry);
1545
+ }
1546
+ }
1547
+ }
1548
+ // Renamed/copied entries
1549
+ else if (line[0] === '2') {
1550
+ const entry = parseRenamedEntry(line);
1551
+ if (entry) {
1552
+ if (entry.indexStatus) {
1553
+ staged.push(entry);
1554
+ }
1555
+ if (entry.workTreeStatus) {
1556
+ modified.push(entry);
1557
+ }
1558
+ }
1559
+ }
1560
+ // Unmerged entries
1561
+ else if (line[0] === 'u') {
1562
+ hasConflicts = true;
1563
+ const entry = parseUnmergedEntry(line);
1564
+ if (entry) {
1565
+ staged.push(entry);
1566
+ }
1567
+ }
1568
+ // Untracked entries
1569
+ else if (line[0] === '?') {
1570
+ const path = line.slice(2);
1571
+ untracked.push(path);
1572
+ }
1573
+ }
1574
+ const clean = staged.length === 0 && modified.length === 0 && untracked.length === 0 && !hasConflicts;
1575
+ return {
1576
+ branch,
1577
+ detached,
1578
+ upstream,
1579
+ ahead,
1580
+ behind,
1581
+ staged,
1582
+ modified,
1583
+ untracked,
1584
+ clean,
1585
+ hasConflicts,
1586
+ };
1587
+ }
1588
+ /**
1589
+ * Parses ahead/behind string.
1590
+ *
1591
+ * @param str - String like "+5 -2"
1592
+ * @returns Parsed values
1593
+ */
1594
+ function parseAheadBehind(str) {
1595
+ let ahead = 0;
1596
+ let behind = 0;
1597
+ const parts = str.split(' ');
1598
+ for (const part of parts) {
1599
+ if (part[0] === '+') {
1600
+ ahead = parseInt(part.slice(1), 10) || 0;
1601
+ }
1602
+ else if (part[0] === '-') {
1603
+ behind = parseInt(part.slice(1), 10) || 0;
1604
+ }
1605
+ }
1606
+ return { ahead, behind };
1607
+ }
1608
+ /**
1609
+ * Parses a changed entry line.
1610
+ *
1611
+ * @param line - Status line starting with '1'
1612
+ * @returns Parsed entry or null
1613
+ */
1614
+ function parseChangedEntry(line) {
1615
+ // Format: 1 <XY> <sub> <mH> <mI> <mW> <hH> <hI> <path>
1616
+ const parts = line.split(' ');
1617
+ if (parts.length < 9)
1618
+ return null;
1619
+ const xy = parts[1];
1620
+ const path = parts.slice(8).join(' ');
1621
+ const indexStatus = statusFromChar(xy[0]);
1622
+ const workTreeStatus = statusFromChar(xy[1]);
1623
+ return {
1624
+ path,
1625
+ indexStatus,
1626
+ workTreeStatus,
1627
+ };
1628
+ }
1629
+ /**
1630
+ * Parses a renamed entry line.
1631
+ *
1632
+ * @param line - Status line starting with '2'
1633
+ * @returns Parsed entry or null
1634
+ */
1635
+ function parseRenamedEntry(line) {
1636
+ // Format: 2 <XY> <sub> <mH> <mI> <mW> <hH> <hI> <X><score> <path><tab><origPath>
1637
+ const parts = line.split(' ');
1638
+ if (parts.length < 10)
1639
+ return null;
1640
+ const xy = parts[1];
1641
+ const pathPart = parts.slice(9).join(' ');
1642
+ // Split by tab
1643
+ const tabIndex = pathPart.indexOf('\t');
1644
+ const path = tabIndex >= 0 ? pathPart.slice(0, tabIndex) : pathPart;
1645
+ const origPath = tabIndex >= 0 ? pathPart.slice(tabIndex + 1) : undefined;
1646
+ const indexStatus = statusFromChar(xy[0]);
1647
+ const workTreeStatus = statusFromChar(xy[1]);
1648
+ return {
1649
+ path,
1650
+ indexStatus,
1651
+ workTreeStatus,
1652
+ origPath,
1653
+ };
1654
+ }
1655
+ /**
1656
+ * Parses an unmerged entry line.
1657
+ *
1658
+ * @param line - Status line starting with 'u'
1659
+ * @returns Parsed entry or null
1660
+ */
1661
+ function parseUnmergedEntry(line) {
1662
+ // Format: u <XY> <sub> <m1> <m2> <m3> <mW> <h1> <h2> <h3> <path>
1663
+ const parts = line.split(' ');
1664
+ if (parts.length < 11)
1665
+ return null;
1666
+ const path = parts.slice(10).join(' ');
1667
+ return {
1668
+ path,
1669
+ indexStatus: 'unmerged',
1670
+ workTreeStatus: 'unmerged',
1671
+ };
1672
+ }
1673
+ /**
1674
+ * Converts status character to FileStatus.
1675
+ *
1676
+ * @param char - Status character
1677
+ * @returns FileStatus or null
1678
+ */
1679
+ function statusFromChar(char) {
1680
+ switch (char) {
1681
+ case 'M':
1682
+ return 'modified';
1683
+ case 'T':
1684
+ return 'modified'; // Type change
1685
+ case 'A':
1686
+ return 'added';
1687
+ case 'D':
1688
+ return 'deleted';
1689
+ case 'R':
1690
+ return 'renamed';
1691
+ case 'C':
1692
+ return 'copied';
1693
+ case 'U':
1694
+ return 'unmerged';
1695
+ case '?':
1696
+ return 'untracked';
1697
+ case '!':
1698
+ return 'ignored';
1699
+ case '.':
1700
+ return null;
1701
+ default:
1702
+ return null;
1703
+ }
1704
+ }
1705
+ /**
1706
+ * Checks if string starts with prefix (no regex).
1707
+ *
1708
+ * @param str - The string to check
1709
+ * @param prefix - The prefix to look for
1710
+ * @returns True if str starts with the given prefix
1711
+ */
1712
+ function startsWithPrefix(str, prefix) {
1713
+ if (prefix.length > str.length)
1714
+ return false;
1715
+ for (let i = 0; i < prefix.length; i++) {
1716
+ if (str[i] !== prefix[i])
1717
+ return false;
1718
+ }
1719
+ return true;
1720
+ }
1721
+ /**
1722
+ * Checks if the working tree is clean (no changes).
1723
+ *
1724
+ * @param options - Configuration for the status check
1725
+ * @returns True if working tree is clean with no uncommitted changes
1726
+ *
1727
+ * @example
1728
+ * if (!isClean()) {
1729
+ * throw new Error('Working tree has changes')
1730
+ * }
1731
+ */
1732
+ function isClean(options = {}) {
1733
+ const status = getStatus(options);
1734
+ return status.clean;
1735
+ }
1736
+ /**
1737
+ * Checks if the directory is a git repository.
1738
+ *
1739
+ * @param options - Status options
1740
+ * @returns True if in a git repository
1741
+ *
1742
+ * @example
1743
+ * if (!isGitRepository()) {
1744
+ * throw new Error('Not a git repository')
1745
+ * }
1746
+ */
1747
+ function isGitRepository(options = {}) {
1748
+ const opts = { ...DEFAULT_STATUS_OPTIONS, ...options };
1749
+ try {
1750
+ node_child_process.execSync('git rev-parse --is-inside-work-tree', {
1751
+ encoding: 'utf-8',
1752
+ cwd: opts.cwd,
1753
+ timeout: opts.timeout,
1754
+ stdio: ['pipe', 'pipe', 'pipe'],
1755
+ });
1756
+ return true;
1757
+ }
1758
+ catch {
1759
+ return false;
1760
+ }
1761
+ }
1762
+ /**
1763
+ * Gets the repository root directory.
1764
+ *
1765
+ * @param options - Status options
1766
+ * @returns Root directory path or null
1767
+ *
1768
+ * @example
1769
+ * const root = getRepositoryRoot()
1770
+ */
1771
+ function getRepositoryRoot(options = {}) {
1772
+ const opts = { ...DEFAULT_STATUS_OPTIONS, ...options };
1773
+ try {
1774
+ return node_child_process.execSync('git rev-parse --show-toplevel', {
1775
+ encoding: 'utf-8',
1776
+ cwd: opts.cwd,
1777
+ timeout: opts.timeout,
1778
+ stdio: ['pipe', 'pipe', 'pipe'],
1779
+ }).trim();
1780
+ }
1781
+ catch {
1782
+ return null;
1783
+ }
1784
+ }
1785
+ /**
1786
+ * Gets the current commit hash (HEAD).
1787
+ *
1788
+ * @param options - Status options
1789
+ * @returns Commit hash or null
1790
+ */
1791
+ function getHeadHash(options = {}) {
1792
+ const opts = { ...DEFAULT_STATUS_OPTIONS, ...options };
1793
+ try {
1794
+ return node_child_process.execSync('git rev-parse HEAD', {
1795
+ encoding: 'utf-8',
1796
+ cwd: opts.cwd,
1797
+ timeout: opts.timeout,
1798
+ stdio: ['pipe', 'pipe', 'pipe'],
1799
+ }).trim();
1800
+ }
1801
+ catch {
1802
+ return null;
1803
+ }
1804
+ }
1805
+ /**
1806
+ * Gets the short current commit hash.
1807
+ *
1808
+ * @param options - Status options
1809
+ * @returns Short hash or null
1810
+ */
1811
+ function getHeadShortHash(options = {}) {
1812
+ const opts = { ...DEFAULT_STATUS_OPTIONS, ...options };
1813
+ try {
1814
+ return node_child_process.execSync('git rev-parse --short HEAD', {
1815
+ encoding: 'utf-8',
1816
+ cwd: opts.cwd,
1817
+ timeout: opts.timeout,
1818
+ stdio: ['pipe', 'pipe', 'pipe'],
1819
+ }).trim();
1820
+ }
1821
+ catch {
1822
+ return null;
1823
+ }
1824
+ }
1825
+ /**
1826
+ * Checks if there are merge conflicts.
1827
+ *
1828
+ * @param options - Status options
1829
+ * @returns True if there are conflicts
1830
+ */
1831
+ function hasConflicts(options = {}) {
1832
+ const status = getStatus(options);
1833
+ return status.hasConflicts;
1834
+ }
1835
+ /**
1836
+ * Gets the number of commits ahead of upstream.
1837
+ *
1838
+ * @param options - Status options
1839
+ * @returns Number of commits ahead
1840
+ */
1841
+ function getAheadCount(options = {}) {
1842
+ const status = getStatus(options);
1843
+ return status.ahead;
1844
+ }
1845
+ /**
1846
+ * Gets the number of commits behind upstream.
1847
+ *
1848
+ * @param options - Status options
1849
+ * @returns Number of commits behind
1850
+ */
1851
+ function getBehindCount(options = {}) {
1852
+ const status = getStatus(options);
1853
+ return status.behind;
1854
+ }
1855
+ /**
1856
+ * Checks if the repository needs to be pushed.
1857
+ *
1858
+ * @param options - Status options
1859
+ * @returns True if there are unpushed commits
1860
+ */
1861
+ function needsPush(options = {}) {
1862
+ return getAheadCount(options) > 0;
1863
+ }
1864
+ /**
1865
+ * Checks if the repository needs to be pulled.
1866
+ *
1867
+ * @param options - Status options
1868
+ * @returns True if there are commits to pull
1869
+ */
1870
+ function needsPull(options = {}) {
1871
+ return getBehindCount(options) > 0;
1872
+ }
1873
+ /**
1874
+ * Gets list of staged file paths.
1875
+ *
1876
+ * @param options - Status options
1877
+ * @returns Array of staged file paths
1878
+ */
1879
+ function getStagedFiles(options = {}) {
1880
+ const status = getStatus(options);
1881
+ return status.staged.map((e) => e.path);
1882
+ }
1883
+ /**
1884
+ * Gets list of modified file paths (unstaged).
1885
+ *
1886
+ * @param options - Status options
1887
+ * @returns Array of modified file paths
1888
+ */
1889
+ function getModifiedFiles(options = {}) {
1890
+ const status = getStatus(options);
1891
+ return status.modified.map((e) => e.path);
1892
+ }
1893
+ /**
1894
+ * Gets list of untracked file paths.
1895
+ *
1896
+ * @param options - Status options
1897
+ * @returns Array of untracked file paths
1898
+ */
1899
+ function getUntrackedFiles(options = {}) {
1900
+ const status = getStatus(options);
1901
+ return status.untracked;
1902
+ }
1903
+
1904
+ exports.DEFAULT_COMMIT_OPTIONS = DEFAULT_COMMIT_OPTIONS;
1905
+ exports.DEFAULT_LOG_OPTIONS = DEFAULT_LOG_OPTIONS;
1906
+ exports.DEFAULT_STATUS_OPTIONS = DEFAULT_STATUS_OPTIONS;
1907
+ exports.DEFAULT_TAG_OPTIONS = DEFAULT_TAG_OPTIONS;
1908
+ exports.amendCommit = amendCommit;
1909
+ exports.amendCommitNoEdit = amendCommitNoEdit;
1910
+ exports.commit = commit;
1911
+ exports.commitExists = commitExists;
1912
+ exports.createEmptyCommit = createEmptyCommit;
1913
+ exports.createTag = createTag;
1914
+ exports.deleteTag = deleteTag;
1915
+ exports.escapeAuthor = escapeAuthor;
1916
+ exports.escapeFilePath = escapeFilePath;
1917
+ exports.escapeGitArg = escapeGitArg;
1918
+ exports.escapeGitMessage = escapeGitMessage;
1919
+ exports.escapeGitPath = escapeGitPath;
1920
+ exports.escapeGitRef = escapeGitRef;
1921
+ exports.escapeGitTagPattern = escapeGitTagPattern;
1922
+ exports.getAheadCount = getAheadCount;
1923
+ exports.getBehindCount = getBehindCount;
1924
+ exports.getCommit = getCommit;
1925
+ exports.getCommitLog = getCommitLog;
1926
+ exports.getCommitsBetween = getCommitsBetween;
1927
+ exports.getCommitsSince = getCommitsSince;
1928
+ exports.getCurrentBranch = getCurrentBranch;
1929
+ exports.getHead = getHead;
1930
+ exports.getHeadHash = getHeadHash;
1931
+ exports.getHeadShortHash = getHeadShortHash;
1932
+ exports.getLatestTag = getLatestTag;
1933
+ exports.getModifiedFiles = getModifiedFiles;
1934
+ exports.getRepositoryRoot = getRepositoryRoot;
1935
+ exports.getStagedFiles = getStagedFiles;
1936
+ exports.getStatus = getStatus;
1937
+ exports.getTag = getTag;
1938
+ exports.getTags = getTags;
1939
+ exports.getTagsForPackage = getTagsForPackage;
1940
+ exports.getUntrackedFiles = getUntrackedFiles;
1941
+ exports.hasConflicts = hasConflicts;
1942
+ exports.hasStagedChanges = hasStagedChanges;
1943
+ exports.hasUnstagedChanges = hasUnstagedChanges;
1944
+ exports.hasUntrackedFiles = hasUntrackedFiles;
1945
+ exports.isClean = isClean;
1946
+ exports.isGitRepository = isGitRepository;
1947
+ exports.needsPull = needsPull;
1948
+ exports.needsPush = needsPush;
1949
+ exports.pushTag = pushTag;
1950
+ exports.stage = stage;
1951
+ exports.stageAll = stageAll;
1952
+ exports.tagExists = tagExists;
1953
+ exports.unstage = unstage;
1954
+ //# sourceMappingURL=index.cjs.js.map