gitx.do 0.1.1 → 0.1.2

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 (356) hide show
  1. package/README.md +40 -353
  2. package/dist/do/logger.d.ts +50 -0
  3. package/dist/do/logger.d.ts.map +1 -0
  4. package/dist/do/logger.js +122 -0
  5. package/dist/do/logger.js.map +1 -0
  6. package/dist/{durable-object → do}/schema.d.ts +3 -3
  7. package/dist/do/schema.d.ts.map +1 -0
  8. package/dist/{durable-object → do}/schema.js +4 -3
  9. package/dist/do/schema.js.map +1 -0
  10. package/dist/do/types.d.ts +267 -0
  11. package/dist/do/types.d.ts.map +1 -0
  12. package/dist/do/types.js +62 -0
  13. package/dist/do/types.js.map +1 -0
  14. package/dist/index.d.ts +14 -469
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +31 -483
  17. package/dist/index.js.map +1 -1
  18. package/package.json +13 -21
  19. package/dist/cli/commands/add.d.ts +0 -176
  20. package/dist/cli/commands/add.d.ts.map +0 -1
  21. package/dist/cli/commands/add.js +0 -979
  22. package/dist/cli/commands/add.js.map +0 -1
  23. package/dist/cli/commands/blame.d.ts +0 -259
  24. package/dist/cli/commands/blame.d.ts.map +0 -1
  25. package/dist/cli/commands/blame.js +0 -609
  26. package/dist/cli/commands/blame.js.map +0 -1
  27. package/dist/cli/commands/branch.d.ts +0 -249
  28. package/dist/cli/commands/branch.d.ts.map +0 -1
  29. package/dist/cli/commands/branch.js +0 -693
  30. package/dist/cli/commands/branch.js.map +0 -1
  31. package/dist/cli/commands/checkout.d.ts +0 -73
  32. package/dist/cli/commands/checkout.d.ts.map +0 -1
  33. package/dist/cli/commands/checkout.js +0 -725
  34. package/dist/cli/commands/checkout.js.map +0 -1
  35. package/dist/cli/commands/commit.d.ts +0 -182
  36. package/dist/cli/commands/commit.d.ts.map +0 -1
  37. package/dist/cli/commands/commit.js +0 -457
  38. package/dist/cli/commands/commit.js.map +0 -1
  39. package/dist/cli/commands/diff.d.ts +0 -464
  40. package/dist/cli/commands/diff.d.ts.map +0 -1
  41. package/dist/cli/commands/diff.js +0 -959
  42. package/dist/cli/commands/diff.js.map +0 -1
  43. package/dist/cli/commands/log.d.ts +0 -239
  44. package/dist/cli/commands/log.d.ts.map +0 -1
  45. package/dist/cli/commands/log.js +0 -535
  46. package/dist/cli/commands/log.js.map +0 -1
  47. package/dist/cli/commands/merge.d.ts +0 -106
  48. package/dist/cli/commands/merge.d.ts.map +0 -1
  49. package/dist/cli/commands/merge.js +0 -852
  50. package/dist/cli/commands/merge.js.map +0 -1
  51. package/dist/cli/commands/review.d.ts +0 -457
  52. package/dist/cli/commands/review.d.ts.map +0 -1
  53. package/dist/cli/commands/review.js +0 -558
  54. package/dist/cli/commands/review.js.map +0 -1
  55. package/dist/cli/commands/stash.d.ts +0 -157
  56. package/dist/cli/commands/stash.d.ts.map +0 -1
  57. package/dist/cli/commands/stash.js +0 -655
  58. package/dist/cli/commands/stash.js.map +0 -1
  59. package/dist/cli/commands/status.d.ts +0 -269
  60. package/dist/cli/commands/status.d.ts.map +0 -1
  61. package/dist/cli/commands/status.js +0 -492
  62. package/dist/cli/commands/status.js.map +0 -1
  63. package/dist/cli/commands/web.d.ts +0 -199
  64. package/dist/cli/commands/web.d.ts.map +0 -1
  65. package/dist/cli/commands/web.js +0 -697
  66. package/dist/cli/commands/web.js.map +0 -1
  67. package/dist/cli/fs-adapter.d.ts +0 -656
  68. package/dist/cli/fs-adapter.d.ts.map +0 -1
  69. package/dist/cli/fs-adapter.js +0 -1177
  70. package/dist/cli/fs-adapter.js.map +0 -1
  71. package/dist/cli/fsx-cli-adapter.d.ts +0 -359
  72. package/dist/cli/fsx-cli-adapter.d.ts.map +0 -1
  73. package/dist/cli/fsx-cli-adapter.js +0 -619
  74. package/dist/cli/fsx-cli-adapter.js.map +0 -1
  75. package/dist/cli/index.d.ts +0 -387
  76. package/dist/cli/index.d.ts.map +0 -1
  77. package/dist/cli/index.js +0 -579
  78. package/dist/cli/index.js.map +0 -1
  79. package/dist/cli/ui/components/DiffView.d.ts +0 -12
  80. package/dist/cli/ui/components/DiffView.d.ts.map +0 -1
  81. package/dist/cli/ui/components/DiffView.js +0 -11
  82. package/dist/cli/ui/components/DiffView.js.map +0 -1
  83. package/dist/cli/ui/components/ErrorDisplay.d.ts +0 -10
  84. package/dist/cli/ui/components/ErrorDisplay.d.ts.map +0 -1
  85. package/dist/cli/ui/components/ErrorDisplay.js +0 -11
  86. package/dist/cli/ui/components/ErrorDisplay.js.map +0 -1
  87. package/dist/cli/ui/components/FuzzySearch.d.ts +0 -15
  88. package/dist/cli/ui/components/FuzzySearch.d.ts.map +0 -1
  89. package/dist/cli/ui/components/FuzzySearch.js +0 -12
  90. package/dist/cli/ui/components/FuzzySearch.js.map +0 -1
  91. package/dist/cli/ui/components/LoadingSpinner.d.ts +0 -10
  92. package/dist/cli/ui/components/LoadingSpinner.d.ts.map +0 -1
  93. package/dist/cli/ui/components/LoadingSpinner.js +0 -10
  94. package/dist/cli/ui/components/LoadingSpinner.js.map +0 -1
  95. package/dist/cli/ui/components/NavigationList.d.ts +0 -14
  96. package/dist/cli/ui/components/NavigationList.d.ts.map +0 -1
  97. package/dist/cli/ui/components/NavigationList.js +0 -11
  98. package/dist/cli/ui/components/NavigationList.js.map +0 -1
  99. package/dist/cli/ui/components/ScrollableContent.d.ts +0 -13
  100. package/dist/cli/ui/components/ScrollableContent.d.ts.map +0 -1
  101. package/dist/cli/ui/components/ScrollableContent.js +0 -11
  102. package/dist/cli/ui/components/ScrollableContent.js.map +0 -1
  103. package/dist/cli/ui/components/index.d.ts +0 -7
  104. package/dist/cli/ui/components/index.d.ts.map +0 -1
  105. package/dist/cli/ui/components/index.js +0 -9
  106. package/dist/cli/ui/components/index.js.map +0 -1
  107. package/dist/cli/ui/terminal-ui.d.ts +0 -85
  108. package/dist/cli/ui/terminal-ui.d.ts.map +0 -1
  109. package/dist/cli/ui/terminal-ui.js +0 -121
  110. package/dist/cli/ui/terminal-ui.js.map +0 -1
  111. package/dist/do/BashModule.d.ts +0 -871
  112. package/dist/do/BashModule.d.ts.map +0 -1
  113. package/dist/do/BashModule.js +0 -1143
  114. package/dist/do/BashModule.js.map +0 -1
  115. package/dist/do/FsModule.d.ts +0 -612
  116. package/dist/do/FsModule.d.ts.map +0 -1
  117. package/dist/do/FsModule.js +0 -1120
  118. package/dist/do/FsModule.js.map +0 -1
  119. package/dist/do/GitModule.d.ts +0 -635
  120. package/dist/do/GitModule.d.ts.map +0 -1
  121. package/dist/do/GitModule.js +0 -784
  122. package/dist/do/GitModule.js.map +0 -1
  123. package/dist/do/GitRepoDO.d.ts +0 -281
  124. package/dist/do/GitRepoDO.d.ts.map +0 -1
  125. package/dist/do/GitRepoDO.js +0 -479
  126. package/dist/do/GitRepoDO.js.map +0 -1
  127. package/dist/do/bash-ast.d.ts +0 -246
  128. package/dist/do/bash-ast.d.ts.map +0 -1
  129. package/dist/do/bash-ast.js +0 -888
  130. package/dist/do/bash-ast.js.map +0 -1
  131. package/dist/do/container-executor.d.ts +0 -491
  132. package/dist/do/container-executor.d.ts.map +0 -1
  133. package/dist/do/container-executor.js +0 -731
  134. package/dist/do/container-executor.js.map +0 -1
  135. package/dist/do/index.d.ts +0 -53
  136. package/dist/do/index.d.ts.map +0 -1
  137. package/dist/do/index.js +0 -91
  138. package/dist/do/index.js.map +0 -1
  139. package/dist/do/tiered-storage.d.ts +0 -403
  140. package/dist/do/tiered-storage.d.ts.map +0 -1
  141. package/dist/do/tiered-storage.js +0 -689
  142. package/dist/do/tiered-storage.js.map +0 -1
  143. package/dist/do/withBash.d.ts +0 -231
  144. package/dist/do/withBash.d.ts.map +0 -1
  145. package/dist/do/withBash.js +0 -244
  146. package/dist/do/withBash.js.map +0 -1
  147. package/dist/do/withFs.d.ts +0 -237
  148. package/dist/do/withFs.d.ts.map +0 -1
  149. package/dist/do/withFs.js +0 -387
  150. package/dist/do/withFs.js.map +0 -1
  151. package/dist/do/withGit.d.ts +0 -180
  152. package/dist/do/withGit.d.ts.map +0 -1
  153. package/dist/do/withGit.js +0 -271
  154. package/dist/do/withGit.js.map +0 -1
  155. package/dist/durable-object/object-store.d.ts +0 -633
  156. package/dist/durable-object/object-store.d.ts.map +0 -1
  157. package/dist/durable-object/object-store.js +0 -1164
  158. package/dist/durable-object/object-store.js.map +0 -1
  159. package/dist/durable-object/schema.d.ts.map +0 -1
  160. package/dist/durable-object/schema.js.map +0 -1
  161. package/dist/durable-object/wal.d.ts +0 -416
  162. package/dist/durable-object/wal.d.ts.map +0 -1
  163. package/dist/durable-object/wal.js +0 -445
  164. package/dist/durable-object/wal.js.map +0 -1
  165. package/dist/mcp/adapter.d.ts +0 -772
  166. package/dist/mcp/adapter.d.ts.map +0 -1
  167. package/dist/mcp/adapter.js +0 -895
  168. package/dist/mcp/adapter.js.map +0 -1
  169. package/dist/mcp/sandbox/miniflare-evaluator.d.ts +0 -22
  170. package/dist/mcp/sandbox/miniflare-evaluator.d.ts.map +0 -1
  171. package/dist/mcp/sandbox/miniflare-evaluator.js +0 -140
  172. package/dist/mcp/sandbox/miniflare-evaluator.js.map +0 -1
  173. package/dist/mcp/sandbox/object-store-proxy.d.ts +0 -32
  174. package/dist/mcp/sandbox/object-store-proxy.d.ts.map +0 -1
  175. package/dist/mcp/sandbox/object-store-proxy.js +0 -30
  176. package/dist/mcp/sandbox/object-store-proxy.js.map +0 -1
  177. package/dist/mcp/sandbox/template.d.ts +0 -17
  178. package/dist/mcp/sandbox/template.d.ts.map +0 -1
  179. package/dist/mcp/sandbox/template.js +0 -71
  180. package/dist/mcp/sandbox/template.js.map +0 -1
  181. package/dist/mcp/sandbox.d.ts +0 -764
  182. package/dist/mcp/sandbox.d.ts.map +0 -1
  183. package/dist/mcp/sandbox.js +0 -1362
  184. package/dist/mcp/sandbox.js.map +0 -1
  185. package/dist/mcp/sdk-adapter.d.ts +0 -835
  186. package/dist/mcp/sdk-adapter.d.ts.map +0 -1
  187. package/dist/mcp/sdk-adapter.js +0 -974
  188. package/dist/mcp/sdk-adapter.js.map +0 -1
  189. package/dist/mcp/tools/do.d.ts +0 -32
  190. package/dist/mcp/tools/do.d.ts.map +0 -1
  191. package/dist/mcp/tools/do.js +0 -117
  192. package/dist/mcp/tools/do.js.map +0 -1
  193. package/dist/mcp/tools.d.ts +0 -548
  194. package/dist/mcp/tools.d.ts.map +0 -1
  195. package/dist/mcp/tools.js +0 -3170
  196. package/dist/mcp/tools.js.map +0 -1
  197. package/dist/ops/blame.d.ts +0 -551
  198. package/dist/ops/blame.d.ts.map +0 -1
  199. package/dist/ops/blame.js +0 -1037
  200. package/dist/ops/blame.js.map +0 -1
  201. package/dist/ops/branch.d.ts +0 -766
  202. package/dist/ops/branch.d.ts.map +0 -1
  203. package/dist/ops/branch.js +0 -950
  204. package/dist/ops/branch.js.map +0 -1
  205. package/dist/ops/commit-traversal.d.ts +0 -349
  206. package/dist/ops/commit-traversal.d.ts.map +0 -1
  207. package/dist/ops/commit-traversal.js +0 -821
  208. package/dist/ops/commit-traversal.js.map +0 -1
  209. package/dist/ops/commit.d.ts +0 -555
  210. package/dist/ops/commit.d.ts.map +0 -1
  211. package/dist/ops/commit.js +0 -826
  212. package/dist/ops/commit.js.map +0 -1
  213. package/dist/ops/merge-base.d.ts +0 -397
  214. package/dist/ops/merge-base.d.ts.map +0 -1
  215. package/dist/ops/merge-base.js +0 -691
  216. package/dist/ops/merge-base.js.map +0 -1
  217. package/dist/ops/merge.d.ts +0 -855
  218. package/dist/ops/merge.d.ts.map +0 -1
  219. package/dist/ops/merge.js +0 -1551
  220. package/dist/ops/merge.js.map +0 -1
  221. package/dist/ops/tag.d.ts +0 -247
  222. package/dist/ops/tag.d.ts.map +0 -1
  223. package/dist/ops/tag.js +0 -649
  224. package/dist/ops/tag.js.map +0 -1
  225. package/dist/ops/tree-builder.d.ts +0 -178
  226. package/dist/ops/tree-builder.d.ts.map +0 -1
  227. package/dist/ops/tree-builder.js +0 -271
  228. package/dist/ops/tree-builder.js.map +0 -1
  229. package/dist/ops/tree-diff.d.ts +0 -291
  230. package/dist/ops/tree-diff.d.ts.map +0 -1
  231. package/dist/ops/tree-diff.js +0 -705
  232. package/dist/ops/tree-diff.js.map +0 -1
  233. package/dist/pack/delta.d.ts +0 -248
  234. package/dist/pack/delta.d.ts.map +0 -1
  235. package/dist/pack/delta.js +0 -740
  236. package/dist/pack/delta.js.map +0 -1
  237. package/dist/pack/format.d.ts +0 -446
  238. package/dist/pack/format.d.ts.map +0 -1
  239. package/dist/pack/format.js +0 -572
  240. package/dist/pack/format.js.map +0 -1
  241. package/dist/pack/full-generation.d.ts +0 -612
  242. package/dist/pack/full-generation.d.ts.map +0 -1
  243. package/dist/pack/full-generation.js +0 -1378
  244. package/dist/pack/full-generation.js.map +0 -1
  245. package/dist/pack/generation.d.ts +0 -441
  246. package/dist/pack/generation.d.ts.map +0 -1
  247. package/dist/pack/generation.js +0 -707
  248. package/dist/pack/generation.js.map +0 -1
  249. package/dist/pack/index.d.ts +0 -502
  250. package/dist/pack/index.d.ts.map +0 -1
  251. package/dist/pack/index.js +0 -833
  252. package/dist/pack/index.js.map +0 -1
  253. package/dist/refs/branch.d.ts +0 -683
  254. package/dist/refs/branch.d.ts.map +0 -1
  255. package/dist/refs/branch.js +0 -881
  256. package/dist/refs/branch.js.map +0 -1
  257. package/dist/refs/storage.d.ts +0 -833
  258. package/dist/refs/storage.d.ts.map +0 -1
  259. package/dist/refs/storage.js +0 -1023
  260. package/dist/refs/storage.js.map +0 -1
  261. package/dist/refs/tag.d.ts +0 -860
  262. package/dist/refs/tag.d.ts.map +0 -1
  263. package/dist/refs/tag.js +0 -996
  264. package/dist/refs/tag.js.map +0 -1
  265. package/dist/storage/backend.d.ts +0 -425
  266. package/dist/storage/backend.d.ts.map +0 -1
  267. package/dist/storage/backend.js +0 -41
  268. package/dist/storage/backend.js.map +0 -1
  269. package/dist/storage/fsx-adapter.d.ts +0 -204
  270. package/dist/storage/fsx-adapter.d.ts.map +0 -1
  271. package/dist/storage/fsx-adapter.js +0 -518
  272. package/dist/storage/fsx-adapter.js.map +0 -1
  273. package/dist/storage/lru-cache.d.ts +0 -691
  274. package/dist/storage/lru-cache.d.ts.map +0 -1
  275. package/dist/storage/lru-cache.js +0 -813
  276. package/dist/storage/lru-cache.js.map +0 -1
  277. package/dist/storage/object-index.d.ts +0 -585
  278. package/dist/storage/object-index.d.ts.map +0 -1
  279. package/dist/storage/object-index.js +0 -532
  280. package/dist/storage/object-index.js.map +0 -1
  281. package/dist/storage/r2-pack.d.ts +0 -1257
  282. package/dist/storage/r2-pack.d.ts.map +0 -1
  283. package/dist/storage/r2-pack.js +0 -1773
  284. package/dist/storage/r2-pack.js.map +0 -1
  285. package/dist/tiered/cdc-pipeline.d.ts +0 -1888
  286. package/dist/tiered/cdc-pipeline.d.ts.map +0 -1
  287. package/dist/tiered/cdc-pipeline.js +0 -1880
  288. package/dist/tiered/cdc-pipeline.js.map +0 -1
  289. package/dist/tiered/migration.d.ts +0 -1104
  290. package/dist/tiered/migration.d.ts.map +0 -1
  291. package/dist/tiered/migration.js +0 -1217
  292. package/dist/tiered/migration.js.map +0 -1
  293. package/dist/tiered/parquet-writer.d.ts +0 -1145
  294. package/dist/tiered/parquet-writer.d.ts.map +0 -1
  295. package/dist/tiered/parquet-writer.js +0 -1183
  296. package/dist/tiered/parquet-writer.js.map +0 -1
  297. package/dist/tiered/read-path.d.ts +0 -835
  298. package/dist/tiered/read-path.d.ts.map +0 -1
  299. package/dist/tiered/read-path.js +0 -487
  300. package/dist/tiered/read-path.js.map +0 -1
  301. package/dist/types/capability.d.ts +0 -1385
  302. package/dist/types/capability.d.ts.map +0 -1
  303. package/dist/types/capability.js +0 -36
  304. package/dist/types/capability.js.map +0 -1
  305. package/dist/types/index.d.ts +0 -13
  306. package/dist/types/index.d.ts.map +0 -1
  307. package/dist/types/index.js +0 -18
  308. package/dist/types/index.js.map +0 -1
  309. package/dist/types/interfaces.d.ts +0 -673
  310. package/dist/types/interfaces.d.ts.map +0 -1
  311. package/dist/types/interfaces.js +0 -26
  312. package/dist/types/interfaces.js.map +0 -1
  313. package/dist/types/objects.d.ts +0 -692
  314. package/dist/types/objects.d.ts.map +0 -1
  315. package/dist/types/objects.js +0 -837
  316. package/dist/types/objects.js.map +0 -1
  317. package/dist/types/storage.d.ts +0 -603
  318. package/dist/types/storage.d.ts.map +0 -1
  319. package/dist/types/storage.js +0 -191
  320. package/dist/types/storage.js.map +0 -1
  321. package/dist/types/worker-loader.d.ts +0 -60
  322. package/dist/types/worker-loader.d.ts.map +0 -1
  323. package/dist/types/worker-loader.js +0 -62
  324. package/dist/types/worker-loader.js.map +0 -1
  325. package/dist/utils/hash.d.ts +0 -198
  326. package/dist/utils/hash.d.ts.map +0 -1
  327. package/dist/utils/hash.js +0 -272
  328. package/dist/utils/hash.js.map +0 -1
  329. package/dist/utils/sha1.d.ts +0 -325
  330. package/dist/utils/sha1.d.ts.map +0 -1
  331. package/dist/utils/sha1.js +0 -635
  332. package/dist/utils/sha1.js.map +0 -1
  333. package/dist/wire/capabilities.d.ts +0 -1044
  334. package/dist/wire/capabilities.d.ts.map +0 -1
  335. package/dist/wire/capabilities.js +0 -941
  336. package/dist/wire/capabilities.js.map +0 -1
  337. package/dist/wire/path-security.d.ts +0 -157
  338. package/dist/wire/path-security.d.ts.map +0 -1
  339. package/dist/wire/path-security.js +0 -307
  340. package/dist/wire/path-security.js.map +0 -1
  341. package/dist/wire/pkt-line.d.ts +0 -345
  342. package/dist/wire/pkt-line.d.ts.map +0 -1
  343. package/dist/wire/pkt-line.js +0 -381
  344. package/dist/wire/pkt-line.js.map +0 -1
  345. package/dist/wire/receive-pack.d.ts +0 -1059
  346. package/dist/wire/receive-pack.d.ts.map +0 -1
  347. package/dist/wire/receive-pack.js +0 -1414
  348. package/dist/wire/receive-pack.js.map +0 -1
  349. package/dist/wire/smart-http.d.ts +0 -799
  350. package/dist/wire/smart-http.d.ts.map +0 -1
  351. package/dist/wire/smart-http.js +0 -945
  352. package/dist/wire/smart-http.js.map +0 -1
  353. package/dist/wire/upload-pack.d.ts +0 -727
  354. package/dist/wire/upload-pack.d.ts.map +0 -1
  355. package/dist/wire/upload-pack.js +0 -1141
  356. package/dist/wire/upload-pack.js.map +0 -1
@@ -1,881 +0,0 @@
1
- /**
2
- * @fileoverview Git Branch Operations
3
- *
4
- * This module provides comprehensive branch management functionality including
5
- * creation, deletion, renaming, listing, and upstream tracking configuration.
6
- *
7
- * Branches in Git are simply refs under `refs/heads/` that point to commits.
8
- * This module provides a higher-level API that handles the ref manipulation
9
- * and adds branch-specific features like tracking information.
10
- *
11
- * **Key Features**:
12
- * - Branch CRUD operations (create, read, update, delete)
13
- * - Upstream tracking configuration
14
- * - Merge status checking
15
- * - Branch name validation and normalization
16
- *
17
- * @module refs/branch
18
- *
19
- * @example
20
- * ```typescript
21
- * import { BranchManager, createBranch, listBranches } from './refs/branch'
22
- *
23
- * // Using the manager
24
- * const manager = new BranchManager(refStorage)
25
- * const branch = await manager.createBranch('feature/new-thing', { startPoint: 'main' })
26
- *
27
- * // Or using convenience functions
28
- * const branches = await listBranches(refStorage)
29
- * ```
30
- */
31
- import { isValidSha } from './storage';
32
- import { isValidRefName as _isValidRefName } from './storage';
33
- void _isValidRefName;
34
- /**
35
- * Error thrown when a branch operation fails.
36
- *
37
- * @description
38
- * Provides structured error information with error code
39
- * for programmatic error handling.
40
- *
41
- * @example
42
- * ```typescript
43
- * try {
44
- * await manager.deleteBranch('main')
45
- * } catch (e) {
46
- * if (e instanceof BranchError) {
47
- * if (e.code === 'CANNOT_DELETE_CURRENT') {
48
- * console.log('Cannot delete the branch you are on')
49
- * }
50
- * }
51
- * }
52
- * ```
53
- */
54
- export class BranchError extends Error {
55
- code;
56
- branchName;
57
- /**
58
- * Create a new BranchError.
59
- *
60
- * @param message - Human-readable error description
61
- * @param code - Error code for programmatic handling
62
- * @param branchName - The branch that caused the error
63
- */
64
- constructor(message, code, branchName) {
65
- super(message);
66
- this.code = code;
67
- this.branchName = branchName;
68
- this.name = 'BranchError';
69
- }
70
- }
71
- export class BranchManager {
72
- storage;
73
- /** Storage for tracking information (simulated config) */
74
- trackingInfo = new Map();
75
- /** Optional callback to check if commits exist */
76
- commitExists;
77
- /**
78
- * Create a new BranchManager.
79
- *
80
- * @param storage - RefStorage instance for ref operations
81
- * @param options - Optional configuration
82
- */
83
- constructor(storage, options) {
84
- this.storage = storage;
85
- this.commitExists = options?.commitExists;
86
- }
87
- /**
88
- * Create a new branch.
89
- *
90
- * @description
91
- * Creates a new branch pointing to the specified start point.
92
- * By default, the branch starts at HEAD.
93
- *
94
- * @param name - Branch name (without refs/heads/ prefix)
95
- * @param options - Creation options
96
- * @returns The created branch
97
- * @throws BranchError with code 'INVALID_NAME' if name is invalid
98
- * @throws BranchError with code 'ALREADY_EXISTS' if branch exists and not forcing
99
- * @throws BranchError with code 'INVALID_START_POINT' if start point is invalid
100
- *
101
- * @example
102
- * ```typescript
103
- * // Create from HEAD
104
- * const branch = await manager.createBranch('feature')
105
- *
106
- * // Create from specific commit
107
- * const branch = await manager.createBranch('hotfix', { startPoint: 'abc123' })
108
- *
109
- * // Force overwrite existing
110
- * const branch = await manager.createBranch('main', { force: true, startPoint: 'HEAD' })
111
- * ```
112
- */
113
- async createBranch(name, options) {
114
- // Validate branch name
115
- const validation = validateBranchName(name);
116
- if (!validation.valid) {
117
- throw new BranchError(validation.error, 'INVALID_NAME', name);
118
- }
119
- const branchRef = getBranchRefName(name);
120
- const normalizedName = normalizeBranchName(name);
121
- // Check if branch already exists
122
- if (!options?.force) {
123
- const existing = await this.storage.getRef(branchRef);
124
- if (existing) {
125
- throw new BranchError(`Branch '${name}' already exists`, 'ALREADY_EXISTS', name);
126
- }
127
- }
128
- // Resolve start point to SHA
129
- const startPoint = options?.startPoint ?? 'HEAD';
130
- // Check for empty start point
131
- if (startPoint === '') {
132
- throw new BranchError('Start point cannot be empty', 'INVALID_START_POINT', name);
133
- }
134
- let sha;
135
- // If startPoint is a valid SHA, use it directly
136
- if (isValidSha(startPoint)) {
137
- // If we have a commitExists validator, verify the commit exists
138
- if (this.commitExists) {
139
- const exists = await this.commitExists(startPoint);
140
- if (!exists) {
141
- throw new BranchError(`Invalid start point: ${startPoint}`, 'INVALID_START_POINT', name);
142
- }
143
- }
144
- sha = startPoint;
145
- }
146
- else {
147
- // Try to resolve as ref
148
- try {
149
- // First try as branch name
150
- let resolved;
151
- try {
152
- resolved = await this.storage.resolveRef(getBranchRefName(startPoint));
153
- }
154
- catch {
155
- // Try as full ref path
156
- try {
157
- resolved = await this.storage.resolveRef(startPoint);
158
- }
159
- catch {
160
- throw new BranchError(`Invalid start point: ${startPoint}`, 'INVALID_START_POINT', name);
161
- }
162
- }
163
- sha = resolved.sha;
164
- }
165
- catch (e) {
166
- if (e instanceof BranchError)
167
- throw e;
168
- throw new BranchError(`Invalid start point: ${startPoint}`, 'INVALID_START_POINT', name);
169
- }
170
- }
171
- // Get current branch to check if new branch is current
172
- void await this.getCurrentBranch(); // Available for future use
173
- const isCurrent = false; // New branch is never current
174
- // Create tracking info if requested
175
- let tracking;
176
- if (options?.track) {
177
- const remoteBranch = typeof options.track === 'string'
178
- ? options.track
179
- : (startPoint.startsWith('refs/remotes/') ? startPoint : undefined);
180
- if (remoteBranch) {
181
- tracking = {
182
- remote: remoteBranch.split('/')[2] || 'origin',
183
- remoteBranch,
184
- ahead: 0,
185
- behind: 0,
186
- gone: false
187
- };
188
- // Store tracking info
189
- this.trackingInfo.set(normalizedName, tracking);
190
- }
191
- }
192
- // Build the branch object first (for dryRun)
193
- const branch = {
194
- name: normalizedName,
195
- ref: branchRef,
196
- sha,
197
- isCurrent,
198
- isRemote: false,
199
- tracking
200
- };
201
- // If dryRun, return without actually creating
202
- if (options?.dryRun) {
203
- return branch;
204
- }
205
- // Create the ref
206
- await this.storage.updateRef(branchRef, sha, { create: true, force: options?.force });
207
- return branch;
208
- }
209
- /**
210
- * Delete a branch.
211
- *
212
- * @description
213
- * Removes a branch ref. By default, refuses to delete unmerged branches.
214
- *
215
- * @param name - Branch name to delete
216
- * @param options - Deletion options
217
- * @throws BranchError with code 'NOT_FOUND' if branch doesn't exist
218
- * @throws BranchError with code 'CANNOT_DELETE_CURRENT' if branch is checked out
219
- * @throws BranchError with code 'NOT_FULLY_MERGED' if branch has unmerged commits
220
- *
221
- * @example
222
- * ```typescript
223
- * // Safe delete (only if merged)
224
- * await manager.deleteBranch('feature')
225
- *
226
- * // Force delete
227
- * await manager.deleteBranch('experiment', { force: true })
228
- * ```
229
- */
230
- async deleteBranch(name, options) {
231
- const normalizedName = normalizeBranchName(name);
232
- // Handle remote branch deletion
233
- if (options?.remote) {
234
- const remoteRef = `refs/remotes/${options.remote}/${normalizedName}`;
235
- const remoteExists = await this.storage.getRef(remoteRef);
236
- if (remoteExists) {
237
- if (!options?.dryRun) {
238
- await this.storage.deleteRef(remoteRef);
239
- }
240
- }
241
- return;
242
- }
243
- const branchRef = getBranchRefName(normalizedName);
244
- // Check if branch exists
245
- const existing = await this.storage.getRef(branchRef);
246
- if (!existing) {
247
- throw new BranchError(`Branch '${name}' not found`, 'NOT_FOUND', name);
248
- }
249
- // Check if this is the current branch
250
- const currentBranch = await this.getCurrentBranch();
251
- if (currentBranch && currentBranch.name === normalizedName) {
252
- throw new BranchError(`Cannot delete the checked out branch '${name}'`, 'CANNOT_DELETE_CURRENT', name);
253
- }
254
- // Check if branch is fully merged (unless force is true)
255
- if (!options?.force) {
256
- const isMerged = await this.isMerged(normalizedName);
257
- if (!isMerged) {
258
- throw new BranchError(`Branch '${name}' is not fully merged. Use force to delete anyway.`, 'NOT_FULLY_MERGED', name);
259
- }
260
- }
261
- // If dryRun, return without actually deleting
262
- if (options?.dryRun) {
263
- return;
264
- }
265
- // Delete the ref
266
- await this.storage.deleteRef(branchRef);
267
- // Remove tracking info
268
- this.trackingInfo.delete(normalizedName);
269
- }
270
- /**
271
- * Rename a branch.
272
- *
273
- * @description
274
- * Renames a branch, updating the ref name. If the branch is the current
275
- * branch, HEAD is updated accordingly.
276
- *
277
- * @param oldName - Current branch name
278
- * @param newName - New branch name
279
- * @param options - Rename options
280
- * @returns The renamed branch
281
- * @throws BranchError with code 'NOT_FOUND' if old branch doesn't exist
282
- * @throws BranchError with code 'ALREADY_EXISTS' if new name exists and not forcing
283
- * @throws BranchError with code 'INVALID_NAME' if new name is invalid
284
- *
285
- * @example
286
- * ```typescript
287
- * const branch = await manager.renameBranch('old-name', 'new-name')
288
- * ```
289
- */
290
- async renameBranch(oldName, newName, options) {
291
- // Validate new branch name
292
- const validation = validateBranchName(newName);
293
- if (!validation.valid) {
294
- throw new BranchError(validation.error, 'INVALID_NAME', newName);
295
- }
296
- const oldNormalized = normalizeBranchName(oldName);
297
- const newNormalized = normalizeBranchName(newName);
298
- const oldRef = getBranchRefName(oldNormalized);
299
- const newRef = getBranchRefName(newNormalized);
300
- // Check if old branch exists
301
- const oldBranch = await this.storage.getRef(oldRef);
302
- if (!oldBranch) {
303
- throw new BranchError(`Branch '${oldName}' not found`, 'NOT_FOUND', oldName);
304
- }
305
- // Check if new branch already exists (unless force)
306
- if (!options?.force) {
307
- const existingNew = await this.storage.getRef(newRef);
308
- if (existingNew) {
309
- throw new BranchError(`Branch '${newName}' already exists`, 'ALREADY_EXISTS', newName);
310
- }
311
- }
312
- // Get the SHA from old branch
313
- const sha = oldBranch.target;
314
- // Check if this is the current branch
315
- const currentBranch = await this.getCurrentBranch();
316
- const wasCurrent = currentBranch && currentBranch.name === oldNormalized;
317
- // Get tracking info from old branch
318
- const oldTracking = this.trackingInfo.get(oldNormalized);
319
- // Build result branch object
320
- const branch = {
321
- name: newNormalized,
322
- ref: newRef,
323
- sha,
324
- isCurrent: wasCurrent ?? false,
325
- isRemote: false,
326
- tracking: oldTracking
327
- };
328
- // If dryRun, return without actually renaming
329
- if (options?.dryRun) {
330
- return branch;
331
- }
332
- // Create new ref with the same SHA
333
- await this.storage.updateRef(newRef, sha, { create: true, force: options?.force });
334
- // Delete old ref
335
- await this.storage.deleteRef(oldRef);
336
- // If this was the current branch, update HEAD to point to new branch
337
- if (wasCurrent) {
338
- await this.storage.updateHead(newRef, true);
339
- }
340
- // Transfer tracking info
341
- if (oldTracking) {
342
- this.trackingInfo.delete(oldNormalized);
343
- this.trackingInfo.set(newNormalized, oldTracking);
344
- }
345
- return branch;
346
- }
347
- /**
348
- * List all branches.
349
- *
350
- * @description
351
- * Returns branches matching the specified criteria.
352
- * By default, returns only local branches.
353
- *
354
- * @param options - Listing options
355
- * @returns Array of branches matching criteria
356
- *
357
- * @example
358
- * ```typescript
359
- * // List local branches
360
- * const local = await manager.listBranches()
361
- *
362
- * // List all branches including remotes
363
- * const all = await manager.listBranches({ includeRemotes: true })
364
- *
365
- * // List merged branches
366
- * const merged = await manager.listBranches({ mergedInto: 'main' })
367
- * ```
368
- */
369
- async listBranches(options) {
370
- const branches = [];
371
- // Get current branch for isCurrent flag
372
- const currentBranch = await this.getCurrentBranch();
373
- // List local branches
374
- if (!options?.remotesOnly) {
375
- const localRefs = await this.storage.listRefs({ pattern: 'refs/heads/*' });
376
- for (const ref of localRefs) {
377
- const name = normalizeBranchName(ref.name);
378
- // Apply pattern filter if specified
379
- if (options?.pattern) {
380
- const regex = new RegExp('^' + options.pattern.replace(/\*/g, '.*') + '$');
381
- if (!regex.test(name))
382
- continue;
383
- }
384
- branches.push({
385
- name,
386
- ref: ref.name,
387
- sha: ref.target,
388
- isCurrent: currentBranch?.name === name,
389
- isRemote: false,
390
- tracking: options?.includeTracking ? this.trackingInfo.get(name) : undefined
391
- });
392
- }
393
- }
394
- // List remote branches if requested
395
- if (options?.includeRemotes || options?.remotesOnly) {
396
- const remoteRefs = await this.storage.listRefs({ pattern: 'refs/remotes/*' });
397
- for (const ref of remoteRefs) {
398
- const name = ref.name.replace(/^refs\/remotes\//, '');
399
- branches.push({
400
- name,
401
- ref: ref.name,
402
- sha: ref.target,
403
- isCurrent: false,
404
- isRemote: true
405
- });
406
- }
407
- }
408
- return branches;
409
- }
410
- /**
411
- * Get the current branch.
412
- *
413
- * @description
414
- * Returns the branch that HEAD points to, or null if HEAD is detached.
415
- *
416
- * @returns Current branch or null if detached
417
- *
418
- * @example
419
- * ```typescript
420
- * const current = await manager.getCurrentBranch()
421
- * if (current) {
422
- * console.log(`On branch: ${current.name}`)
423
- * } else {
424
- * console.log('HEAD is detached')
425
- * }
426
- * ```
427
- */
428
- async getCurrentBranch() {
429
- const head = await this.storage.getRef('HEAD');
430
- if (!head)
431
- return null;
432
- // If HEAD is direct (detached), there is no current branch
433
- if (head.type === 'direct') {
434
- return null;
435
- }
436
- // HEAD is symbolic, pointing to a branch
437
- const branchRef = head.target;
438
- if (!branchRef.startsWith('refs/heads/')) {
439
- return null;
440
- }
441
- const ref = await this.storage.getRef(branchRef);
442
- if (!ref)
443
- return null;
444
- const name = normalizeBranchName(branchRef);
445
- return {
446
- name,
447
- ref: branchRef,
448
- sha: ref.target,
449
- isCurrent: true,
450
- isRemote: false,
451
- tracking: this.trackingInfo.get(name)
452
- };
453
- }
454
- /**
455
- * Get a specific branch by name.
456
- *
457
- * @description
458
- * Retrieves branch information for a specific branch.
459
- *
460
- * @param name - Branch name
461
- * @returns Branch info or null if not found
462
- *
463
- * @example
464
- * ```typescript
465
- * const branch = await manager.getBranch('main')
466
- * if (branch) {
467
- * console.log(`main is at ${branch.sha}`)
468
- * }
469
- * ```
470
- */
471
- async getBranch(name) {
472
- const normalizedName = normalizeBranchName(name);
473
- const branchRef = getBranchRefName(normalizedName);
474
- const ref = await this.storage.getRef(branchRef);
475
- if (!ref)
476
- return null;
477
- const currentBranch = await this.getCurrentBranch();
478
- return {
479
- name: normalizedName,
480
- ref: branchRef,
481
- sha: ref.target,
482
- isCurrent: currentBranch?.name === normalizedName,
483
- isRemote: false,
484
- tracking: this.trackingInfo.get(normalizedName)
485
- };
486
- }
487
- /**
488
- * Check if a branch exists.
489
- *
490
- * @description
491
- * Quick check for branch existence without fetching full info.
492
- *
493
- * @param name - Branch name
494
- * @returns True if branch exists
495
- *
496
- * @example
497
- * ```typescript
498
- * if (await manager.branchExists('feature')) {
499
- * console.log('Branch already exists')
500
- * }
501
- * ```
502
- */
503
- async branchExists(name) {
504
- // Handle remote branch names like 'origin/main'
505
- if (name.includes('/') && !name.startsWith('refs/')) {
506
- const parts = name.split('/');
507
- if (parts.length >= 2) {
508
- // Check if it's a remote reference
509
- const remoteRef = `refs/remotes/${name}`;
510
- const remoteExists = await this.storage.getRef(remoteRef);
511
- if (remoteExists)
512
- return true;
513
- }
514
- }
515
- const normalizedName = normalizeBranchName(name);
516
- const branchRef = getBranchRefName(normalizedName);
517
- const ref = await this.storage.getRef(branchRef);
518
- return ref !== null;
519
- }
520
- /**
521
- * Set upstream branch for tracking.
522
- *
523
- * @description
524
- * Configures or removes upstream tracking for a branch.
525
- *
526
- * @param branchName - Local branch to configure
527
- * @param options - Tracking options
528
- * @throws BranchError with code 'NOT_FOUND' if branch doesn't exist
529
- *
530
- * @example
531
- * ```typescript
532
- * // Set upstream
533
- * await manager.setUpstream('feature', {
534
- * remote: 'origin',
535
- * remoteBranch: 'feature'
536
- * })
537
- *
538
- * // Remove upstream
539
- * await manager.setUpstream('feature', { unset: true })
540
- * ```
541
- */
542
- async setUpstream(branchName, options) {
543
- const normalizedName = normalizeBranchName(branchName);
544
- const branchRef = getBranchRefName(normalizedName);
545
- // Check if branch exists
546
- const existing = await this.storage.getRef(branchRef);
547
- if (!existing) {
548
- throw new BranchError(`Branch '${branchName}' not found`, 'NOT_FOUND', branchName);
549
- }
550
- // If unset, remove tracking info
551
- if (options.unset) {
552
- this.trackingInfo.delete(normalizedName);
553
- return;
554
- }
555
- // Build the remote branch ref
556
- const remote = options.remote || 'origin';
557
- const remoteBranchName = options.remoteBranch || normalizedName;
558
- const remoteBranch = `refs/remotes/${remote}/${remoteBranchName}`;
559
- const tracking = {
560
- remote,
561
- remoteBranch,
562
- ahead: 0,
563
- behind: 0,
564
- gone: false
565
- };
566
- this.trackingInfo.set(normalizedName, tracking);
567
- }
568
- /**
569
- * Get tracking info for a branch.
570
- *
571
- * @description
572
- * Returns upstream tracking information including ahead/behind counts.
573
- *
574
- * @param branchName - Branch to check
575
- * @returns Tracking info or null if not tracking
576
- *
577
- * @example
578
- * ```typescript
579
- * const tracking = await manager.getTrackingInfo('main')
580
- * if (tracking) {
581
- * console.log(`${tracking.ahead} ahead, ${tracking.behind} behind ${tracking.remoteBranch}`)
582
- * }
583
- * ```
584
- */
585
- async getTrackingInfo(branchName) {
586
- const normalizedName = normalizeBranchName(branchName);
587
- return this.trackingInfo.get(normalizedName) ?? null;
588
- }
589
- /**
590
- * Check if a branch is fully merged into another branch.
591
- *
592
- * @description
593
- * Determines if all commits on the branch are reachable from the target.
594
- *
595
- * @param branchName - Branch to check
596
- * @param into - Target branch (defaults to current branch)
597
- * @returns True if fully merged
598
- *
599
- * @example
600
- * ```typescript
601
- * if (await manager.isMerged('feature', 'main')) {
602
- * console.log('Safe to delete feature branch')
603
- * }
604
- * ```
605
- */
606
- async isMerged(branchName, into) {
607
- const normalizedName = normalizeBranchName(branchName);
608
- const branchRef = getBranchRefName(normalizedName);
609
- // Get the branch SHA
610
- const branchSha = await this.storage.getRef(branchRef);
611
- if (!branchSha) {
612
- throw new BranchError(`Branch '${branchName}' not found`, 'NOT_FOUND', branchName);
613
- }
614
- // Get the target branch SHA
615
- let targetSha;
616
- if (into) {
617
- const targetRef = getBranchRefName(normalizeBranchName(into));
618
- const resolved = await this.storage.getRef(targetRef);
619
- if (!resolved) {
620
- throw new BranchError(`Branch '${into}' not found`, 'NOT_FOUND', into);
621
- }
622
- targetSha = resolved.target;
623
- }
624
- else {
625
- // Use current branch
626
- const current = await this.getCurrentBranch();
627
- if (!current) {
628
- throw new BranchError('No current branch', 'DETACHED_HEAD');
629
- }
630
- targetSha = current.sha;
631
- }
632
- // Simple check: if the branch points to the same SHA as target, it's merged
633
- // For a more accurate check, we'd need to walk the commit graph
634
- return branchSha.target === targetSha;
635
- }
636
- /**
637
- * Force delete an unmerged branch.
638
- *
639
- * @description
640
- * Deletes a branch even if it has unmerged commits. Use with caution
641
- * as this can result in lost commits.
642
- *
643
- * @param name - Branch name to delete
644
- * @throws BranchError with code 'NOT_FOUND' if branch doesn't exist
645
- * @throws BranchError with code 'CANNOT_DELETE_CURRENT' if branch is checked out
646
- *
647
- * @example
648
- * ```typescript
649
- * await manager.forceDeleteBranch('abandoned-feature')
650
- * ```
651
- */
652
- async forceDeleteBranch(name) {
653
- return this.deleteBranch(name, { force: true });
654
- }
655
- }
656
- // ============================================================================
657
- // Validation Functions
658
- // ============================================================================
659
- /**
660
- * Validate a branch name according to Git rules.
661
- *
662
- * @description
663
- * Checks if a branch name is valid and returns detailed validation results
664
- * including the normalized form of the name.
665
- *
666
- * @param name - Branch name to validate
667
- * @returns Validation result with valid flag, error message, and normalized name
668
- *
669
- * @see https://git-scm.com/docs/git-check-ref-format
670
- *
671
- * @example
672
- * ```typescript
673
- * const result = validateBranchName('feature/auth')
674
- * if (result.valid) {
675
- * console.log(`Valid: ${result.normalized}`)
676
- * } else {
677
- * console.log(`Invalid: ${result.error}`)
678
- * }
679
- * ```
680
- */
681
- export function validateBranchName(name) {
682
- // Empty name is invalid
683
- if (!name || name.length === 0) {
684
- return { valid: false, error: 'Branch name cannot be empty' };
685
- }
686
- // HEAD is not a valid branch name
687
- if (name === 'HEAD') {
688
- return { valid: false, error: 'HEAD is not a valid branch name' };
689
- }
690
- // Cannot start with dash
691
- if (name.startsWith('-')) {
692
- return { valid: false, error: 'Branch name cannot start with a dash' };
693
- }
694
- // Cannot contain spaces
695
- if (name.includes(' ')) {
696
- return { valid: false, error: 'Branch name cannot contain spaces' };
697
- }
698
- // Cannot contain double dots
699
- if (name.includes('..')) {
700
- return { valid: false, error: 'Branch name cannot contain double dots (..)' };
701
- }
702
- // Cannot end with .lock
703
- if (name.endsWith('.lock')) {
704
- return { valid: false, error: 'Branch name cannot end with .lock' };
705
- }
706
- // Cannot contain control characters (ASCII 0-31, 127)
707
- const controlCharRegex = /[\x00-\x1f\x7f]/;
708
- if (controlCharRegex.test(name)) {
709
- return { valid: false, error: 'Branch name cannot contain control characters' };
710
- }
711
- // Cannot contain ~, ^, :, ?, *, [, ], \
712
- const invalidChars = /[~^:?*[\]\\]/;
713
- if (invalidChars.test(name)) {
714
- return { valid: false, error: 'Branch name contains invalid characters (~, ^, :, ?, *, [, ], \\)' };
715
- }
716
- // Normalize the name (strip refs/heads/ if present)
717
- const normalized = normalizeBranchName(name);
718
- return { valid: true, normalized };
719
- }
720
- /**
721
- * Check if a string is a valid branch name.
722
- *
723
- * @description
724
- * Simple boolean check for branch name validity.
725
- *
726
- * @param name - Branch name to check
727
- * @returns True if valid
728
- *
729
- * @example
730
- * ```typescript
731
- * if (isValidBranchName('feature/new')) {
732
- * // Create the branch
733
- * }
734
- * ```
735
- */
736
- export function isValidBranchName(name) {
737
- return validateBranchName(name).valid;
738
- }
739
- /**
740
- * Normalize a branch name.
741
- *
742
- * @description
743
- * Removes refs/heads/ prefix if present, cleans up the name.
744
- *
745
- * @param name - Branch name or ref
746
- * @returns Normalized short branch name
747
- *
748
- * @example
749
- * ```typescript
750
- * normalizeBranchName('refs/heads/main') // 'main'
751
- * normalizeBranchName('main') // 'main'
752
- * ```
753
- */
754
- export function normalizeBranchName(name) {
755
- if (name.startsWith('refs/heads/')) {
756
- return name.slice('refs/heads/'.length);
757
- }
758
- return name;
759
- }
760
- /**
761
- * Get the full ref name for a branch.
762
- *
763
- * @description
764
- * Adds refs/heads/ prefix if not present.
765
- *
766
- * @param name - Short branch name
767
- * @returns Full ref name
768
- *
769
- * @example
770
- * ```typescript
771
- * getBranchRefName('main') // 'refs/heads/main'
772
- * getBranchRefName('refs/heads/main') // 'refs/heads/main'
773
- * ```
774
- */
775
- export function getBranchRefName(name) {
776
- if (name.startsWith('refs/heads/')) {
777
- return name;
778
- }
779
- return `refs/heads/${name}`;
780
- }
781
- // ============================================================================
782
- // Convenience Functions
783
- // ============================================================================
784
- /**
785
- * Create a new branch.
786
- *
787
- * @description
788
- * Convenience function that creates a BranchManager and calls createBranch.
789
- *
790
- * @param storage - RefStorage instance
791
- * @param name - Branch name
792
- * @param options - Creation options
793
- * @returns Created branch
794
- *
795
- * @example
796
- * ```typescript
797
- * const branch = await createBranch(storage, 'feature', { startPoint: 'main' })
798
- * ```
799
- */
800
- export async function createBranch(storage, name, options) {
801
- const manager = new BranchManager(storage);
802
- return manager.createBranch(name, options);
803
- }
804
- /**
805
- * Delete a branch.
806
- *
807
- * @description
808
- * Convenience function that creates a BranchManager and calls deleteBranch.
809
- *
810
- * @param storage - RefStorage instance
811
- * @param name - Branch name to delete
812
- * @param options - Deletion options
813
- *
814
- * @example
815
- * ```typescript
816
- * await deleteBranch(storage, 'feature', { force: true })
817
- * ```
818
- */
819
- export async function deleteBranch(storage, name, options) {
820
- const manager = new BranchManager(storage);
821
- return manager.deleteBranch(name, options);
822
- }
823
- /**
824
- * Rename a branch.
825
- *
826
- * @description
827
- * Convenience function that creates a BranchManager and calls renameBranch.
828
- *
829
- * @param storage - RefStorage instance
830
- * @param oldName - Current branch name
831
- * @param newName - New branch name
832
- * @param options - Rename options
833
- * @returns Renamed branch
834
- *
835
- * @example
836
- * ```typescript
837
- * const branch = await renameBranch(storage, 'old', 'new')
838
- * ```
839
- */
840
- export async function renameBranch(storage, oldName, newName, options) {
841
- const manager = new BranchManager(storage);
842
- return manager.renameBranch(oldName, newName, options);
843
- }
844
- /**
845
- * List all branches.
846
- *
847
- * @description
848
- * Convenience function that creates a BranchManager and calls listBranches.
849
- *
850
- * @param storage - RefStorage instance
851
- * @param options - Listing options
852
- * @returns Array of branches
853
- *
854
- * @example
855
- * ```typescript
856
- * const branches = await listBranches(storage, { includeRemotes: true })
857
- * ```
858
- */
859
- export async function listBranches(storage, options) {
860
- const manager = new BranchManager(storage);
861
- return manager.listBranches(options);
862
- }
863
- /**
864
- * Get the current branch.
865
- *
866
- * @description
867
- * Convenience function that creates a BranchManager and calls getCurrentBranch.
868
- *
869
- * @param storage - RefStorage instance
870
- * @returns Current branch or null if detached
871
- *
872
- * @example
873
- * ```typescript
874
- * const current = await getCurrentBranch(storage)
875
- * ```
876
- */
877
- export async function getCurrentBranch(storage) {
878
- const manager = new BranchManager(storage);
879
- return manager.getCurrentBranch();
880
- }
881
- //# sourceMappingURL=branch.js.map