@statewalker/vcs-commands 0.9.0 → 0.11.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 (468) hide show
  1. package/README.md +1 -1
  2. package/dist/commands/add-command.d.ts.map +1 -1
  3. package/dist/commands/add-patch/patch-backend.d.ts +2 -0
  4. package/dist/commands/add-patch/patch-backend.d.ts.map +1 -1
  5. package/dist/commands/add-patch/patch-modes.d.ts +6 -2
  6. package/dist/commands/add-patch/patch-modes.d.ts.map +1 -1
  7. package/dist/commands/add-patch/patch-session.d.ts +4 -0
  8. package/dist/commands/add-patch/patch-session.d.ts.map +1 -1
  9. package/dist/commands/am/am-command.d.ts +41 -2
  10. package/dist/commands/am/am-command.d.ts.map +1 -1
  11. package/dist/commands/apply/index.d.ts +1 -1
  12. package/dist/commands/apply/index.d.ts.map +1 -1
  13. package/dist/commands/archive/archive-command.d.ts +169 -0
  14. package/dist/commands/archive/archive-command.d.ts.map +1 -0
  15. package/dist/commands/archive/archive-entry.d.ts +60 -0
  16. package/dist/commands/archive/archive-entry.d.ts.map +1 -0
  17. package/dist/commands/archive/index.d.ts +8 -0
  18. package/dist/commands/archive/index.d.ts.map +1 -0
  19. package/dist/commands/archive/remote-archive-command.d.ts +56 -0
  20. package/dist/commands/archive/remote-archive-command.d.ts.map +1 -0
  21. package/dist/commands/archive/tar-archive.d.ts +31 -0
  22. package/dist/commands/archive/tar-archive.d.ts.map +1 -0
  23. package/dist/commands/archive/tar-commit-id.d.ts +13 -0
  24. package/dist/commands/archive/tar-commit-id.d.ts.map +1 -0
  25. package/dist/commands/archive/upload-archive-writer.d.ts +48 -0
  26. package/dist/commands/archive/upload-archive-writer.d.ts.map +1 -0
  27. package/dist/commands/archive/zip-archive.d.ts +42 -0
  28. package/dist/commands/archive/zip-archive.d.ts.map +1 -0
  29. package/dist/commands/attributes-source.d.ts +10 -0
  30. package/dist/commands/attributes-source.d.ts.map +1 -1
  31. package/dist/commands/blame-command.d.ts +43 -1
  32. package/dist/commands/blame-command.d.ts.map +1 -1
  33. package/dist/commands/bundle/bundle-create-command.d.ts +67 -0
  34. package/dist/commands/bundle/bundle-create-command.d.ts.map +1 -0
  35. package/dist/commands/bundle/bundle-format.d.ts +89 -0
  36. package/dist/commands/bundle/bundle-format.d.ts.map +1 -0
  37. package/dist/commands/bundle/bundle-list.d.ts +92 -0
  38. package/dist/commands/bundle/bundle-list.d.ts.map +1 -0
  39. package/dist/commands/bundle/bundle-read-commands.d.ts +81 -0
  40. package/dist/commands/bundle/bundle-read-commands.d.ts.map +1 -0
  41. package/dist/commands/bundle/bundle-support.d.ts +32 -0
  42. package/dist/commands/bundle/bundle-support.d.ts.map +1 -0
  43. package/dist/commands/bundle/bundle-transport.d.ts +38 -0
  44. package/dist/commands/bundle/bundle-transport.d.ts.map +1 -0
  45. package/dist/commands/bundle/bundle-uri-host.d.ts +43 -0
  46. package/dist/commands/bundle/bundle-uri-host.d.ts.map +1 -0
  47. package/dist/commands/bundle/bundle-uri.d.ts +55 -0
  48. package/dist/commands/bundle/bundle-uri.d.ts.map +1 -0
  49. package/dist/commands/bundle/bundle-verify.d.ts +63 -0
  50. package/dist/commands/bundle/bundle-verify.d.ts.map +1 -0
  51. package/dist/commands/bundle/index.d.ts +14 -0
  52. package/dist/commands/bundle/index.d.ts.map +1 -0
  53. package/dist/commands/cat-file/batch-format.d.ts +58 -0
  54. package/dist/commands/cat-file/batch-format.d.ts.map +1 -0
  55. package/dist/commands/cat-file/cat-file-command.d.ts +144 -0
  56. package/dist/commands/cat-file/cat-file-command.d.ts.map +1 -0
  57. package/dist/commands/cat-file/index.d.ts +3 -0
  58. package/dist/commands/cat-file/index.d.ts.map +1 -0
  59. package/dist/commands/check-attr-command.d.ts +66 -0
  60. package/dist/commands/check-attr-command.d.ts.map +1 -0
  61. package/dist/commands/check-ignore-command.d.ts +58 -0
  62. package/dist/commands/check-ignore-command.d.ts.map +1 -0
  63. package/dist/commands/check-ref-format-command.d.ts +60 -0
  64. package/dist/commands/check-ref-format-command.d.ts.map +1 -0
  65. package/dist/commands/checkout-command.d.ts.map +1 -1
  66. package/dist/commands/checkout-index-command.d.ts +96 -0
  67. package/dist/commands/checkout-index-command.d.ts.map +1 -0
  68. package/dist/commands/cherry-pick-command.d.ts +10 -0
  69. package/dist/commands/cherry-pick-command.d.ts.map +1 -1
  70. package/dist/commands/clone-command.d.ts +28 -0
  71. package/dist/commands/clone-command.d.ts.map +1 -1
  72. package/dist/commands/commit-command.d.ts +9 -1
  73. package/dist/commands/commit-command.d.ts.map +1 -1
  74. package/dist/commands/config-command.d.ts +2 -0
  75. package/dist/commands/config-command.d.ts.map +1 -1
  76. package/dist/commands/daemon-access-hook.d.ts +36 -0
  77. package/dist/commands/daemon-access-hook.d.ts.map +1 -0
  78. package/dist/commands/default-branch.d.ts +54 -0
  79. package/dist/commands/default-branch.d.ts.map +1 -1
  80. package/dist/commands/diff-command.d.ts +132 -5
  81. package/dist/commands/diff-command.d.ts.map +1 -1
  82. package/dist/commands/diff-external.d.ts +43 -0
  83. package/dist/commands/diff-external.d.ts.map +1 -0
  84. package/dist/commands/diff-plumbing/diff-pairs-command.d.ts +27 -0
  85. package/dist/commands/diff-plumbing/diff-pairs-command.d.ts.map +1 -0
  86. package/dist/commands/diff-plumbing/diff-plumbing-command.d.ts +129 -0
  87. package/dist/commands/diff-plumbing/diff-plumbing-command.d.ts.map +1 -0
  88. package/dist/commands/diff-plumbing/index.d.ts +3 -0
  89. package/dist/commands/diff-plumbing/index.d.ts.map +1 -0
  90. package/dist/commands/diff-textconv.d.ts +5 -1
  91. package/dist/commands/diff-textconv.d.ts.map +1 -1
  92. package/dist/commands/fast-export/fast-export-command.d.ts +135 -0
  93. package/dist/commands/fast-export/fast-export-command.d.ts.map +1 -0
  94. package/dist/commands/fast-export/fast-import-command.d.ts +182 -0
  95. package/dist/commands/fast-export/fast-import-command.d.ts.map +1 -0
  96. package/dist/commands/fast-export/fast-stream-support.d.ts +64 -0
  97. package/dist/commands/fast-export/fast-stream-support.d.ts.map +1 -0
  98. package/dist/commands/fast-export/index.d.ts +4 -0
  99. package/dist/commands/fast-export/index.d.ts.map +1 -0
  100. package/dist/commands/fetch-command.d.ts +65 -0
  101. package/dist/commands/fetch-command.d.ts.map +1 -1
  102. package/dist/commands/fetch-multiple-command.d.ts.map +1 -1
  103. package/dist/commands/format-rev-command.d.ts +60 -0
  104. package/dist/commands/format-rev-command.d.ts.map +1 -0
  105. package/dist/commands/fsck/fsck-command.d.ts.map +1 -1
  106. package/dist/commands/fsck/fsck-msg-ids.d.ts +18 -3
  107. package/dist/commands/fsck/fsck-msg-ids.d.ts.map +1 -1
  108. package/dist/commands/fsmonitor-ipc.d.ts +30 -0
  109. package/dist/commands/fsmonitor-ipc.d.ts.map +1 -0
  110. package/dist/commands/fsmonitor-refresh.d.ts +69 -0
  111. package/dist/commands/fsmonitor-refresh.d.ts.map +1 -0
  112. package/dist/commands/gc-command.d.ts +5 -0
  113. package/dist/commands/gc-command.d.ts.map +1 -1
  114. package/dist/commands/git-hooks.d.ts +32 -0
  115. package/dist/commands/git-hooks.d.ts.map +1 -1
  116. package/dist/commands/git-paths.d.ts +26 -0
  117. package/dist/commands/git-paths.d.ts.map +1 -0
  118. package/dist/commands/grep/grep-command.d.ts +2 -1
  119. package/dist/commands/grep/grep-command.d.ts.map +1 -1
  120. package/dist/commands/history-command.d.ts +156 -0
  121. package/dist/commands/history-command.d.ts.map +1 -0
  122. package/dist/commands/http-config.d.ts +38 -0
  123. package/dist/commands/http-config.d.ts.map +1 -0
  124. package/dist/commands/index-adder.d.ts +12 -1
  125. package/dist/commands/index-adder.d.ts.map +1 -1
  126. package/dist/commands/index-host.d.ts.map +1 -1
  127. package/dist/commands/index.d.ts +45 -1
  128. package/dist/commands/index.d.ts.map +1 -1
  129. package/dist/commands/index.js +6 -5
  130. package/dist/commands/init-command.d.ts.map +1 -1
  131. package/dist/commands/last-modified-command.d.ts +102 -0
  132. package/dist/commands/last-modified-command.d.ts.map +1 -0
  133. package/dist/commands/lfs/go-url.d.ts +43 -0
  134. package/dist/commands/lfs/go-url.d.ts.map +1 -0
  135. package/dist/commands/lfs/index.d.ts +3 -0
  136. package/dist/commands/lfs/index.d.ts.map +1 -0
  137. package/dist/commands/lfs/lfs-config.d.ts +174 -0
  138. package/dist/commands/lfs/lfs-config.d.ts.map +1 -0
  139. package/dist/commands/lfs/lfs-endpoint-command.d.ts +83 -0
  140. package/dist/commands/lfs/lfs-endpoint-command.d.ts.map +1 -0
  141. package/dist/commands/local-transport.d.ts.map +1 -1
  142. package/dist/commands/log-command.d.ts +26 -0
  143. package/dist/commands/log-command.d.ts.map +1 -1
  144. package/dist/commands/log-output.d.ts +28 -1
  145. package/dist/commands/log-output.d.ts.map +1 -1
  146. package/dist/commands/ls-files-command.d.ts +153 -0
  147. package/dist/commands/ls-files-command.d.ts.map +1 -0
  148. package/dist/commands/ls-remote-command.d.ts +5 -0
  149. package/dist/commands/ls-remote-command.d.ts.map +1 -1
  150. package/dist/commands/ls-tree-command.d.ts +105 -0
  151. package/dist/commands/ls-tree-command.d.ts.map +1 -0
  152. package/dist/commands/maintenance-run-command.d.ts +122 -0
  153. package/dist/commands/maintenance-run-command.d.ts.map +1 -0
  154. package/dist/commands/merge-command.d.ts +7 -0
  155. package/dist/commands/merge-command.d.ts.map +1 -1
  156. package/dist/commands/merge-config.d.ts +7 -0
  157. package/dist/commands/merge-config.d.ts.map +1 -1
  158. package/dist/commands/merge-drivers.d.ts +67 -5
  159. package/dist/commands/merge-drivers.d.ts.map +1 -1
  160. package/dist/commands/merge-support.d.ts +6 -0
  161. package/dist/commands/merge-support.d.ts.map +1 -1
  162. package/dist/commands/merge-tree-command.d.ts +122 -0
  163. package/dist/commands/merge-tree-command.d.ts.map +1 -0
  164. package/dist/commands/mktag-command.d.ts +51 -0
  165. package/dist/commands/mktag-command.d.ts.map +1 -0
  166. package/dist/commands/object-store/count-objects-command.d.ts +58 -0
  167. package/dist/commands/object-store/count-objects-command.d.ts.map +1 -0
  168. package/dist/commands/object-store/index.d.ts +5 -0
  169. package/dist/commands/object-store/index.d.ts.map +1 -0
  170. package/dist/commands/object-store/objects-directory.d.ts +12 -0
  171. package/dist/commands/object-store/objects-directory.d.ts.map +1 -0
  172. package/dist/commands/object-store/prune-command.d.ts +38 -0
  173. package/dist/commands/object-store/prune-command.d.ts.map +1 -0
  174. package/dist/commands/object-store/show-index-command.d.ts +23 -0
  175. package/dist/commands/object-store/show-index-command.d.ts.map +1 -0
  176. package/dist/commands/ort-merge.d.ts +24 -0
  177. package/dist/commands/ort-merge.d.ts.map +1 -1
  178. package/dist/commands/patch-id-command.d.ts +30 -0
  179. package/dist/commands/patch-id-command.d.ts.map +1 -0
  180. package/dist/commands/patch-id.d.ts +24 -0
  181. package/dist/commands/patch-id.d.ts.map +1 -1
  182. package/dist/commands/plumbing-command.d.ts +66 -0
  183. package/dist/commands/plumbing-command.d.ts.map +1 -0
  184. package/dist/commands/plumbing-input.d.ts +38 -0
  185. package/dist/commands/plumbing-input.d.ts.map +1 -0
  186. package/dist/commands/promisor-remote-reply.d.ts +35 -0
  187. package/dist/commands/promisor-remote-reply.d.ts.map +1 -0
  188. package/dist/commands/promisor-remote.d.ts.map +1 -1
  189. package/dist/commands/pull-command.d.ts.map +1 -1
  190. package/dist/commands/push-command.d.ts +17 -2
  191. package/dist/commands/push-command.d.ts.map +1 -1
  192. package/dist/commands/rebase-command.d.ts +108 -2
  193. package/dist/commands/rebase-command.d.ts.map +1 -1
  194. package/dist/commands/refs-command.d.ts +81 -0
  195. package/dist/commands/refs-command.d.ts.map +1 -0
  196. package/dist/commands/remote-object-info-command.d.ts +55 -0
  197. package/dist/commands/remote-object-info-command.d.ts.map +1 -0
  198. package/dist/commands/remote-transport.d.ts +40 -3
  199. package/dist/commands/remote-transport.d.ts.map +1 -1
  200. package/dist/commands/repack-command.d.ts +115 -0
  201. package/dist/commands/repack-command.d.ts.map +1 -0
  202. package/dist/commands/replace-command.d.ts +143 -0
  203. package/dist/commands/replace-command.d.ts.map +1 -0
  204. package/dist/commands/replay-command.d.ts +117 -0
  205. package/dist/commands/replay-command.d.ts.map +1 -0
  206. package/dist/commands/repo-command.d.ts +158 -0
  207. package/dist/commands/repo-command.d.ts.map +1 -0
  208. package/dist/commands/request-pull-command.d.ts +82 -0
  209. package/dist/commands/request-pull-command.d.ts.map +1 -0
  210. package/dist/commands/rerere-command.d.ts +36 -0
  211. package/dist/commands/rerere-command.d.ts.map +1 -0
  212. package/dist/commands/rerere.d.ts +102 -0
  213. package/dist/commands/rerere.d.ts.map +1 -0
  214. package/dist/commands/reset-command.d.ts +19 -2
  215. package/dist/commands/reset-command.d.ts.map +1 -1
  216. package/dist/commands/rev-filter/commit-grep.d.ts +3 -1
  217. package/dist/commands/rev-filter/commit-grep.d.ts.map +1 -1
  218. package/dist/commands/rev-list-command.d.ts +3 -0
  219. package/dist/commands/rev-list-command.d.ts.map +1 -1
  220. package/dist/commands/rev-parse-command.d.ts +5 -0
  221. package/dist/commands/rev-parse-command.d.ts.map +1 -1
  222. package/dist/commands/revert-command.d.ts +10 -0
  223. package/dist/commands/revert-command.d.ts.map +1 -1
  224. package/dist/commands/revision-range.d.ts +5 -0
  225. package/dist/commands/revision-range.d.ts.map +1 -1
  226. package/dist/commands/revision-resolver.d.ts +27 -1
  227. package/dist/commands/revision-resolver.d.ts.map +1 -1
  228. package/dist/commands/sequencer-pick.d.ts +18 -0
  229. package/dist/commands/sequencer-pick.d.ts.map +1 -1
  230. package/dist/commands/serve-repository.d.ts +23 -1
  231. package/dist/commands/serve-repository.d.ts.map +1 -1
  232. package/dist/commands/session-id.d.ts +18 -0
  233. package/dist/commands/session-id.d.ts.map +1 -0
  234. package/dist/commands/show-branch-command.d.ts +59 -0
  235. package/dist/commands/show-branch-command.d.ts.map +1 -0
  236. package/dist/commands/show-ref-command.d.ts +112 -0
  237. package/dist/commands/show-ref-command.d.ts.map +1 -0
  238. package/dist/commands/signature-check.d.ts +9 -2
  239. package/dist/commands/signature-check.d.ts.map +1 -1
  240. package/dist/commands/signing.d.ts +30 -2
  241. package/dist/commands/signing.d.ts.map +1 -1
  242. package/dist/commands/stash-apply-command.d.ts.map +1 -1
  243. package/dist/commands/stash-export-command.d.ts +115 -0
  244. package/dist/commands/stash-export-command.d.ts.map +1 -0
  245. package/dist/commands/status-command.d.ts +16 -2
  246. package/dist/commands/status-command.d.ts.map +1 -1
  247. package/dist/commands/stripspace-command.d.ts +44 -0
  248. package/dist/commands/stripspace-command.d.ts.map +1 -0
  249. package/dist/commands/submodule-add-command.d.ts +22 -1
  250. package/dist/commands/submodule-add-command.d.ts.map +1 -1
  251. package/dist/commands/submodule-auth.d.ts +3 -1
  252. package/dist/commands/submodule-auth.d.ts.map +1 -1
  253. package/dist/commands/submodule-commands.d.ts +9 -1
  254. package/dist/commands/submodule-commands.d.ts.map +1 -1
  255. package/dist/commands/submodule-update-command.d.ts +27 -1
  256. package/dist/commands/submodule-update-command.d.ts.map +1 -1
  257. package/dist/commands/tag-command.d.ts.map +1 -1
  258. package/dist/commands/textconv-cache.d.ts +58 -0
  259. package/dist/commands/textconv-cache.d.ts.map +1 -0
  260. package/dist/commands/tree-restore.d.ts +5 -0
  261. package/dist/commands/tree-restore.d.ts.map +1 -1
  262. package/dist/commands/unpack-objects-command.d.ts +47 -0
  263. package/dist/commands/unpack-objects-command.d.ts.map +1 -0
  264. package/dist/commands/update-index-command.d.ts +131 -0
  265. package/dist/commands/update-index-command.d.ts.map +1 -0
  266. package/dist/commands/uri-protocols.d.ts +13 -0
  267. package/dist/commands/uri-protocols.d.ts.map +1 -0
  268. package/dist/commands/url-parse-command.d.ts +30 -0
  269. package/dist/commands/url-parse-command.d.ts.map +1 -0
  270. package/dist/commands/var-command.d.ts +42 -0
  271. package/dist/commands/var-command.d.ts.map +1 -0
  272. package/dist/{commands-CNvli5bl.js → commands-bQQ9OmCh.js} +52514 -44630
  273. package/dist/errors/command-errors.d.ts +33 -0
  274. package/dist/errors/command-errors.d.ts.map +1 -1
  275. package/dist/errors/index.js +39 -1
  276. package/dist/{fsck-CPeDh9fh.js → fsck-BHT9bUS-.js} +184 -143
  277. package/dist/git-command.d.ts +66 -4
  278. package/dist/git-command.d.ts.map +1 -1
  279. package/dist/git.d.ts +532 -1
  280. package/dist/git.d.ts.map +1 -1
  281. package/dist/guarded-transport-command.d.ts +3 -1
  282. package/dist/guarded-transport-command.d.ts.map +1 -1
  283. package/dist/index.js +7 -6
  284. package/dist/maintenance-run-command-Cx2PlGV9.js +13544 -0
  285. package/dist/{remote-transport-CCmBadm-.js → remote-transport-BrQZfyHu.js} +1009 -10
  286. package/dist/results/cherry-pick-result.d.ts +6 -0
  287. package/dist/results/cherry-pick-result.d.ts.map +1 -1
  288. package/dist/results/diff-entry.d.ts +10 -0
  289. package/dist/results/diff-entry.d.ts.map +1 -1
  290. package/dist/results/diff-formatter.d.ts.map +1 -1
  291. package/dist/results/diff-output.d.ts +49 -3
  292. package/dist/results/diff-output.d.ts.map +1 -1
  293. package/dist/results/fetch-result.d.ts +12 -0
  294. package/dist/results/fetch-result.d.ts.map +1 -1
  295. package/dist/results/index.js +2 -2
  296. package/dist/results/merge-result.d.ts +5 -0
  297. package/dist/results/merge-result.d.ts.map +1 -1
  298. package/dist/results/push-result.d.ts +5 -0
  299. package/dist/results/push-result.d.ts.map +1 -1
  300. package/dist/results/rebase-result.d.ts +7 -0
  301. package/dist/results/rebase-result.d.ts.map +1 -1
  302. package/dist/results/revert-result.d.ts +6 -0
  303. package/dist/results/revert-result.d.ts.map +1 -1
  304. package/dist/results/stash-result.d.ts +5 -0
  305. package/dist/results/stash-result.d.ts.map +1 -1
  306. package/dist/{results-BDuEgdLU.js → results-CNHQnU5Y.js} +13707 -10608
  307. package/dist/transport-command.d.ts +79 -1
  308. package/dist/transport-command.d.ts.map +1 -1
  309. package/package.json +13 -13
  310. package/src/commands/add-command.ts +3 -0
  311. package/src/commands/add-patch/patch-backend.ts +4 -1
  312. package/src/commands/add-patch/patch-modes.ts +26 -2
  313. package/src/commands/add-patch/patch-session.ts +6 -0
  314. package/src/commands/am/am-command.ts +193 -22
  315. package/src/commands/apply/index.ts +1 -0
  316. package/src/commands/archive/archive-command.ts +1148 -0
  317. package/src/commands/archive/archive-entry.ts +93 -0
  318. package/src/commands/archive/index.ts +7 -0
  319. package/src/commands/archive/remote-archive-command.ts +140 -0
  320. package/src/commands/archive/tar-archive.ts +207 -0
  321. package/src/commands/archive/tar-commit-id.ts +72 -0
  322. package/src/commands/archive/upload-archive-writer.ts +213 -0
  323. package/src/commands/archive/zip-archive.ts +317 -0
  324. package/src/commands/attributes-source.ts +26 -12
  325. package/src/commands/blame-command.ts +118 -19
  326. package/src/commands/bundle/bundle-create-command.ts +405 -0
  327. package/src/commands/bundle/bundle-format.ts +228 -0
  328. package/src/commands/bundle/bundle-list.ts +276 -0
  329. package/src/commands/bundle/bundle-read-commands.ts +157 -0
  330. package/src/commands/bundle/bundle-support.ts +85 -0
  331. package/src/commands/bundle/bundle-transport.ts +107 -0
  332. package/src/commands/bundle/bundle-uri-host.ts +204 -0
  333. package/src/commands/bundle/bundle-uri.ts +236 -0
  334. package/src/commands/bundle/bundle-verify.ts +152 -0
  335. package/src/commands/bundle/index.ts +14 -0
  336. package/src/commands/cat-file/batch-format.ts +193 -0
  337. package/src/commands/cat-file/cat-file-command.ts +895 -0
  338. package/src/commands/cat-file/index.ts +2 -0
  339. package/src/commands/check-attr-command.ts +333 -0
  340. package/src/commands/check-ignore-command.ts +261 -0
  341. package/src/commands/check-ref-format-command.ts +129 -0
  342. package/src/commands/checkout-command.ts +61 -22
  343. package/src/commands/checkout-index-command.ts +568 -0
  344. package/src/commands/checkout-paths.ts +7 -0
  345. package/src/commands/cherry-pick-command.ts +21 -1
  346. package/src/commands/clone-command.ts +249 -9
  347. package/src/commands/commit-command.ts +22 -4
  348. package/src/commands/config-command.ts +9 -0
  349. package/src/commands/daemon-access-hook.ts +78 -0
  350. package/src/commands/default-branch.ts +118 -1
  351. package/src/commands/diff-command.ts +592 -47
  352. package/src/commands/diff-external.ts +131 -0
  353. package/src/commands/diff-plumbing/diff-pairs-command.ts +193 -0
  354. package/src/commands/diff-plumbing/diff-plumbing-command.ts +424 -0
  355. package/src/commands/diff-plumbing/index.ts +2 -0
  356. package/src/commands/diff-textconv.ts +5 -1
  357. package/src/commands/fast-export/fast-export-command.ts +911 -0
  358. package/src/commands/fast-export/fast-import-command.ts +1553 -0
  359. package/src/commands/fast-export/fast-stream-support.ts +162 -0
  360. package/src/commands/fast-export/index.ts +3 -0
  361. package/src/commands/fetch-command.ts +312 -8
  362. package/src/commands/fetch-multiple-command.ts +4 -1
  363. package/src/commands/format-rev-command.ts +267 -0
  364. package/src/commands/fsck/fsck-command.ts +47 -20
  365. package/src/commands/fsck/fsck-msg-ids.ts +19 -3
  366. package/src/commands/fsck/fsck-pack.ts +2 -2
  367. package/src/commands/fsmonitor-ipc.ts +121 -0
  368. package/src/commands/fsmonitor-refresh.ts +320 -0
  369. package/src/commands/gc-command.ts +10 -0
  370. package/src/commands/git-hooks.ts +123 -6
  371. package/src/commands/git-paths.ts +136 -0
  372. package/src/commands/grep/grep-command.ts +38 -15
  373. package/src/commands/history-command.ts +617 -0
  374. package/src/commands/http-config.ts +139 -0
  375. package/src/commands/index-adder.ts +37 -3
  376. package/src/commands/index-host.ts +6 -1
  377. package/src/commands/index.ts +46 -0
  378. package/src/commands/init-command.ts +14 -0
  379. package/src/commands/last-modified-command.ts +804 -0
  380. package/src/commands/lfs/go-url.ts +370 -0
  381. package/src/commands/lfs/index.ts +2 -0
  382. package/src/commands/lfs/lfs-config.ts +738 -0
  383. package/src/commands/lfs/lfs-endpoint-command.ts +180 -0
  384. package/src/commands/local-transport.ts +252 -4
  385. package/src/commands/log-command.ts +104 -5
  386. package/src/commands/log-output.ts +66 -5
  387. package/src/commands/ls-files-command.ts +1177 -0
  388. package/src/commands/ls-remote-command.ts +6 -0
  389. package/src/commands/ls-tree-command.ts +708 -0
  390. package/src/commands/maintenance-run-command.ts +949 -0
  391. package/src/commands/merge-command.ts +78 -32
  392. package/src/commands/merge-config.ts +23 -1
  393. package/src/commands/merge-drivers.ts +109 -20
  394. package/src/commands/merge-support.ts +29 -5
  395. package/src/commands/merge-tree-command.ts +786 -0
  396. package/src/commands/mktag-command.ts +149 -0
  397. package/src/commands/object-store/count-objects-command.ts +404 -0
  398. package/src/commands/object-store/index.ts +4 -0
  399. package/src/commands/object-store/objects-directory.ts +24 -0
  400. package/src/commands/object-store/prune-command.ts +129 -0
  401. package/src/commands/object-store/show-index-command.ts +151 -0
  402. package/src/commands/ort-merge.ts +92 -25
  403. package/src/commands/patch-id-command.ts +65 -0
  404. package/src/commands/patch-id.ts +218 -0
  405. package/src/commands/plumbing-command.ts +141 -0
  406. package/src/commands/plumbing-input.ts +87 -0
  407. package/src/commands/promisor-remote-reply.ts +276 -0
  408. package/src/commands/promisor-remote.ts +25 -2
  409. package/src/commands/pull-command.ts +2 -0
  410. package/src/commands/push-command.ts +87 -5
  411. package/src/commands/rebase-command.ts +507 -19
  412. package/src/commands/refs-command.ts +274 -0
  413. package/src/commands/remote-object-info-command.ts +109 -0
  414. package/src/commands/remote-transport.ts +116 -1
  415. package/src/commands/repack-command.ts +383 -0
  416. package/src/commands/replace-command.ts +816 -0
  417. package/src/commands/replay-command.ts +674 -0
  418. package/src/commands/repo-command.ts +1066 -0
  419. package/src/commands/request-pull-command.ts +356 -0
  420. package/src/commands/rerere-command.ts +179 -0
  421. package/src/commands/rerere.ts +925 -0
  422. package/src/commands/reset-command.ts +75 -3
  423. package/src/commands/rev-filter/commit-grep.ts +7 -2
  424. package/src/commands/rev-list-command.ts +9 -0
  425. package/src/commands/rev-parse-command.ts +49 -5
  426. package/src/commands/revert-command.ts +21 -1
  427. package/src/commands/revision-range.ts +7 -2
  428. package/src/commands/revision-resolver.ts +97 -14
  429. package/src/commands/sequencer-pick.ts +47 -0
  430. package/src/commands/serve-repository.ts +65 -0
  431. package/src/commands/session-id.ts +31 -0
  432. package/src/commands/show-branch-command.ts +981 -0
  433. package/src/commands/show-command.ts +1 -1
  434. package/src/commands/show-ref-command.ts +439 -0
  435. package/src/commands/signature-check.ts +37 -5
  436. package/src/commands/signing.ts +176 -23
  437. package/src/commands/stash-apply-command.ts +3 -0
  438. package/src/commands/stash-export-command.ts +397 -0
  439. package/src/commands/status-command.ts +74 -8
  440. package/src/commands/stripspace-command.ts +118 -0
  441. package/src/commands/submodule-add-command.ts +40 -2
  442. package/src/commands/submodule-auth.ts +61 -6
  443. package/src/commands/submodule-commands.ts +12 -2
  444. package/src/commands/submodule-update-command.ts +47 -1
  445. package/src/commands/tag-command.ts +33 -11
  446. package/src/commands/textconv-cache.ts +143 -0
  447. package/src/commands/tree-restore.ts +14 -0
  448. package/src/commands/unpack-objects-command.ts +235 -0
  449. package/src/commands/update-index-command.ts +1148 -0
  450. package/src/commands/uri-protocols.ts +13 -0
  451. package/src/commands/url-parse-command.ts +67 -0
  452. package/src/commands/var-command.ts +219 -0
  453. package/src/errors/command-errors.ts +45 -0
  454. package/src/git-command.ts +177 -3
  455. package/src/git.ts +808 -1
  456. package/src/guarded-transport-command.ts +6 -1
  457. package/src/results/cherry-pick-result.ts +6 -0
  458. package/src/results/diff-entry.ts +12 -0
  459. package/src/results/diff-formatter.ts +7 -4
  460. package/src/results/diff-output.ts +117 -11
  461. package/src/results/diff-pickaxe.ts +1 -1
  462. package/src/results/fetch-result.ts +12 -0
  463. package/src/results/merge-result.ts +5 -0
  464. package/src/results/push-result.ts +5 -0
  465. package/src/results/rebase-result.ts +7 -0
  466. package/src/results/revert-result.ts +6 -0
  467. package/src/results/stash-result.ts +6 -0
  468. package/src/transport-command.ts +182 -1
@@ -0,0 +1,1148 @@
1
+ /**
2
+ * `git update-index` (builtin/update-index.c): index entries added, replaced, removed or
3
+ * re-flagged one argument at a time, as git processes its command line in order.
4
+ *
5
+ * @example
6
+ * ```typescript
7
+ * // git update-index --add a --chmod=+x b
8
+ * await git.updateIndex().setAdd(true).addPath("a").setChmod("+x").addPath("b").call();
9
+ *
10
+ * // git update-index --cacheinfo 100644,<id>,c --assume-unchanged a
11
+ * await git.updateIndex().addCacheInfo(0o100644, id, "c").setAssumeUnchanged(true).addPath("a").call();
12
+ *
13
+ * // git update-index --refresh
14
+ * const { output, exitCode } = await git.updateIndex().refresh().call();
15
+ *
16
+ * // git update-index --fsmonitor, then --fsmonitor-valid a
17
+ * await git.updateIndex().setFsmonitor(true).call();
18
+ * await git.updateIndex().setFsmonitorValid(true).addPath("a").call();
19
+ * ```
20
+ */
21
+
22
+ import {
23
+ FileMode,
24
+ type FileModeValue,
25
+ isValidWorktreePath,
26
+ type ObjectId,
27
+ } from "@statewalker/vcs-core";
28
+ import { encodeGitPath } from "@statewalker/vcs-utils/encoding";
29
+ import {
30
+ basicStatMatches,
31
+ compareWithWorktree,
32
+ entryStatOf,
33
+ FsmonitorState,
34
+ invalidateCacheTreePath,
35
+ modeFromWorktree,
36
+ type ResolveUndoRecord,
37
+ type StagingEntry,
38
+ storeWorktreeFile,
39
+ type Worktree,
40
+ type WorktreeEntry,
41
+ type WorktreeModeTrust,
42
+ wholeSeconds,
43
+ } from "@statewalker/vcs-working-tree";
44
+ import { UpdateIndexFailedError } from "../errors/index.js";
45
+ import { GitCommand } from "../git-command.js";
46
+ import { RemoteConfigStore } from "../remote-config/index.js";
47
+ import { worktreeModeTrust } from "./core-config.js";
48
+ import { fsmonitorModeOf } from "./fsmonitor-refresh.js";
49
+ import { hookHostOf } from "./git-hooks.js";
50
+ import { hostEnvironmentOf } from "./git-ident.js";
51
+ import { configBool } from "./merge-config.js";
52
+ import { inputLines, inputPaths, unquoteLine } from "./plumbing-input.js";
53
+ import { worktreePathRules } from "./worktree-path-rules.js";
54
+
55
+ /** Result of {@link UpdateIndexCommand}. */
56
+ export interface UpdateIndexResult {
57
+ /** What git prints on stdout: `--verbose`'s report, the refresh's `<path>: needs update` */
58
+ output: string;
59
+ /** What git prints on stderr without dying (`Ignoring path <path>`, `error:` lines) */
60
+ errors: string;
61
+ /** git's exit status: 1 when a refresh found entries to update or merge, else 0 */
62
+ exitCode: 0 | 1;
63
+ }
64
+
65
+ /** One index entry as the command edits it (a stage-0 entry or a conflict stage). */
66
+ type Entry = StagingEntry;
67
+
68
+ type Step =
69
+ | { kind: "set"; apply: (state: State) => void }
70
+ | { kind: "path"; path: string }
71
+ | { kind: "cacheinfo"; mode: number; id: string; path: string }
72
+ | { kind: "refresh"; really: boolean };
73
+
74
+ /** The flags git keeps in its globals as it parses the command line. */
75
+ interface State {
76
+ add: boolean;
77
+ remove: boolean;
78
+ replace: boolean;
79
+ forceRemove: boolean;
80
+ infoOnly: boolean;
81
+ verbose: boolean;
82
+ /** `--[no-]assume-unchanged`: true marks, false unmarks, undefined neither */
83
+ markValid?: boolean;
84
+ /** `--[no-]skip-worktree` */
85
+ markSkipWorktree?: boolean;
86
+ /** `--[no-]fsmonitor-valid` */
87
+ markFsmonitor?: boolean;
88
+ ignoreSkipWorktreeEntries: boolean;
89
+ chmod?: "+x" | "-x";
90
+ quiet: boolean;
91
+ unmerged: boolean;
92
+ ignoreMissing: boolean;
93
+ ignoreSubmodules: boolean;
94
+ }
95
+
96
+ /** A death (`die()`): git's message, without the `fatal: ` prefix. */
97
+ class Death extends Error {}
98
+
99
+ const S_IFMT = 0o170000;
100
+ const S_IFREG = 0o100000;
101
+
102
+ /** git's index order: the names' bytes, then the stage. */
103
+ function compareNames(a: string, b: string): number {
104
+ const n = Math.min(a.length, b.length);
105
+ for (let i = 0; i < n; i++) {
106
+ const x = a.charCodeAt(i);
107
+ const y = b.charCodeAt(i);
108
+ if (x === y) continue;
109
+ if (x < 0xd800 && y < 0xd800) return x - y;
110
+ const ea = encodeGitPath(a);
111
+ const eb = encodeGitPath(b);
112
+ const m = Math.min(ea.length, eb.length);
113
+ for (let j = 0; j < m; j++) {
114
+ if (ea[j] !== eb[j]) return (ea[j] as number) - (eb[j] as number);
115
+ }
116
+ return ea.length - eb.length;
117
+ }
118
+ return a.length - b.length;
119
+ }
120
+
121
+ /**
122
+ * Edits the index as `git update-index` does (builtin/update-index.c).
123
+ *
124
+ * Options and paths apply in the order they are given, as git parses its command line: a
125
+ * setter changes how the paths after it are handled ({@link setAdd} before {@link addPath}),
126
+ * {@link refresh} and {@link addCacheInfo} act where they stand, and {@link setIndexInfo} or
127
+ * {@link setStdin} input is read after everything else. Each path is `update_one`:
128
+ *
129
+ * - with {@link setAssumeUnchanged} or {@link setSkipWorktree}, its stage-0 entry is flagged
130
+ * or unflagged (`Unable to mark file <path>` when it has none);
131
+ * - with {@link setForceRemove}, every stage of it is removed;
132
+ * - otherwise the file is hashed into the index (`--add` needed for a new path), a missing
133
+ * file removed only with {@link setRemove}, a directory taken as a submodule's commit.
134
+ *
135
+ * git's deaths are thrown as {@link UpdateIndexFailedError} (exit status 128) before the
136
+ * index is written, carrying what was printed until then. A refresh that finds entries to
137
+ * update or merge prints them and ends with exit status 1, the index written all the same.
138
+ */
139
+ export class UpdateIndexCommand extends GitCommand<UpdateIndexResult> {
140
+ private readonly steps: Step[] = [];
141
+ private indexInfo?: { text: Uint8Array | string };
142
+ private stdinPaths?: Uint8Array | string;
143
+ private nulTerminated = false;
144
+ private indexVersion?: number;
145
+ private showIndexVersion = false;
146
+ private forceWrite = false;
147
+ private fsmonitor?: boolean;
148
+
149
+ private set(apply: (state: State) => void): this {
150
+ this.checkCallable();
151
+ this.steps.push({ kind: "set", apply });
152
+ return this;
153
+ }
154
+
155
+ /** `--add`: paths not in the index yet are added (from here on). */
156
+ setAdd(add = true): this {
157
+ return this.set((s) => {
158
+ s.add = add;
159
+ });
160
+ }
161
+
162
+ /** `--remove`: paths missing from the worktree are removed from the index. */
163
+ setRemove(remove = true): this {
164
+ return this.set((s) => {
165
+ s.remove = remove;
166
+ });
167
+ }
168
+
169
+ /** `--replace`: a file may replace a directory of its name in the index, and the reverse. */
170
+ setReplace(replace = true): this {
171
+ return this.set((s) => {
172
+ s.replace = replace;
173
+ });
174
+ }
175
+
176
+ /** `--force-remove`: paths are removed from the index whether or not their file exists. */
177
+ setForceRemove(forceRemove = true): this {
178
+ return this.set((s) => {
179
+ s.forceRemove = forceRemove;
180
+ });
181
+ }
182
+
183
+ /** `--info-only`: files are hashed into the index without storing their blobs. */
184
+ setInfoOnly(infoOnly = true): this {
185
+ return this.set((s) => {
186
+ s.infoOnly = infoOnly;
187
+ });
188
+ }
189
+
190
+ /** `--verbose`: `add '<path>'`, `remove '<path>'`, `chmod +x '<path>'` reported. */
191
+ setVerbose(verbose = true): this {
192
+ return this.set((s) => {
193
+ s.verbose = verbose;
194
+ });
195
+ }
196
+
197
+ /** `--chmod=(+|-)x`: the executable bit of the paths after it set or cleared in the index. */
198
+ setChmod(flip: "+x" | "-x"): this {
199
+ return this.set((s) => {
200
+ s.chmod = flip;
201
+ });
202
+ }
203
+
204
+ /** `--assume-unchanged` (true) / `--no-assume-unchanged` (false) for the paths after it. */
205
+ setAssumeUnchanged(mark: boolean): this {
206
+ return this.set((s) => {
207
+ s.markValid = mark;
208
+ });
209
+ }
210
+
211
+ /** `--skip-worktree` (true) / `--no-skip-worktree` (false) for the paths after it. */
212
+ setSkipWorktree(mark: boolean): this {
213
+ return this.set((s) => {
214
+ s.markSkipWorktree = mark;
215
+ });
216
+ }
217
+
218
+ /**
219
+ * `--fsmonitor-valid` (true) / `--no-fsmonitor-valid` (false) for the paths after it: the
220
+ * entry's fsmonitor valid bit (`CE_FSMONITOR_VALID`) set or cleared.
221
+ */
222
+ setFsmonitorValid(mark: boolean): this {
223
+ return this.set((s) => {
224
+ s.markFsmonitor = mark;
225
+ });
226
+ }
227
+
228
+ /**
229
+ * `--fsmonitor` (true) / `--no-fsmonitor` (false), applied after the paths, as git does:
230
+ * the index's `FSMN` extension added (`add_fsmonitor`; a warning when `core.fsmonitor` is
231
+ * unset; git's death in a bare repository with `core.fsmonitor` set) or removed (a warning
232
+ * when `core.fsmonitor` is set).
233
+ */
234
+ setFsmonitor(enable: boolean): this {
235
+ this.checkCallable();
236
+ this.fsmonitor = enable;
237
+ return this;
238
+ }
239
+
240
+ /** `--ignore-skip-worktree-entries`: `--remove` leaves skip-worktree entries alone. */
241
+ setIgnoreSkipWorktreeEntries(ignore = true): this {
242
+ return this.set((s) => {
243
+ s.ignoreSkipWorktreeEntries = ignore;
244
+ });
245
+ }
246
+
247
+ /** `-q`: a refresh after it prints nothing about entries needing an update. */
248
+ setQuiet(quiet = true): this {
249
+ return this.set((s) => {
250
+ s.quiet = quiet;
251
+ });
252
+ }
253
+
254
+ /** `--unmerged`: a refresh after it passes over unmerged entries quietly. */
255
+ setUnmerged(unmerged = true): this {
256
+ return this.set((s) => {
257
+ s.unmerged = unmerged;
258
+ });
259
+ }
260
+
261
+ /** `--ignore-missing`: a refresh after it passes over missing files. */
262
+ setIgnoreMissing(ignore = true): this {
263
+ return this.set((s) => {
264
+ s.ignoreMissing = ignore;
265
+ });
266
+ }
267
+
268
+ /** `--ignore-submodules`: a refresh after it passes over submodules. */
269
+ setIgnoreSubmodules(ignore = true): this {
270
+ return this.set((s) => {
271
+ s.ignoreSubmodules = ignore;
272
+ });
273
+ }
274
+
275
+ /** A path to update (git's `<file>` argument), relative to the worktree top. */
276
+ addPath(path: string): this {
277
+ this.checkCallable();
278
+ this.steps.push({ kind: "path", path });
279
+ return this;
280
+ }
281
+
282
+ /** `--cacheinfo <mode>,<object>,<path>`: an entry put in the index as given. */
283
+ addCacheInfo(mode: number, objectId: string, path: string): this {
284
+ this.checkCallable();
285
+ this.steps.push({ kind: "cacheinfo", mode, id: objectId, path });
286
+ return this;
287
+ }
288
+
289
+ /** `--refresh`: the stat data of unchanged files refreshed, the changed ones reported. */
290
+ refresh(): this {
291
+ this.checkCallable();
292
+ this.steps.push({ kind: "refresh", really: false });
293
+ return this;
294
+ }
295
+
296
+ /** `--really-refresh`: as {@link refresh}, assume-unchanged entries checked too. */
297
+ reallyRefresh(): this {
298
+ this.checkCallable();
299
+ this.steps.push({ kind: "refresh", really: true });
300
+ return this;
301
+ }
302
+
303
+ /**
304
+ * `--index-info`: entries read from `input` (`<mode> <id>\t<path>`, `<mode> <type>
305
+ * <id>\t<path>` or `<mode> <id> <stage>\t<path>`; mode 0 removes the path), after
306
+ * everything else.
307
+ */
308
+ setIndexInfo(input: string | Uint8Array): this {
309
+ this.checkCallable();
310
+ this.indexInfo = { text: input };
311
+ return this;
312
+ }
313
+
314
+ /** `--stdin`: paths read from `input`, one per line, after everything else. */
315
+ setStdin(input: string | Uint8Array): this {
316
+ this.checkCallable();
317
+ this.stdinPaths = input;
318
+ return this;
319
+ }
320
+
321
+ /** `-z`: {@link setIndexInfo} and {@link setStdin} input is NUL-separated. */
322
+ setNulTerminated(nul = true): this {
323
+ this.checkCallable();
324
+ this.nulTerminated = nul;
325
+ return this;
326
+ }
327
+
328
+ /** `--index-version <n>`: the index written in format 2, 3 or 4. */
329
+ setIndexVersion(version: number): this {
330
+ this.checkCallable();
331
+ this.indexVersion = version;
332
+ return this;
333
+ }
334
+
335
+ /** `--show-index-version`: the index's format version printed. */
336
+ setShowIndexVersion(show = true): this {
337
+ this.checkCallable();
338
+ this.showIndexVersion = show;
339
+ return this;
340
+ }
341
+
342
+ /** `--force-write-index`: the index written even when nothing changed. */
343
+ setForceWriteIndex(force = true): this {
344
+ this.checkCallable();
345
+ this.forceWrite = force;
346
+ return this;
347
+ }
348
+
349
+ async call(): Promise<UpdateIndexResult> {
350
+ this.checkCallable();
351
+ this.setCallable(false);
352
+ // fsm_settings__get_reason: a bare repository is incompatible with a configured monitor
353
+ // (git dies after reading the index, which a bare working copy here does not give)
354
+ if (this.fsmonitor && !this.hasWorktree()) {
355
+ const mode = fsmonitorModeOf(
356
+ RemoteConfigStore.from(this.workingCopy).value("core.fsmonitor"),
357
+ );
358
+ if (mode.kind !== "disabled") {
359
+ throw new UpdateIndexFailedError(
360
+ `fatal: bare repository '${await this.currentDirectory()}' is incompatible with fsmonitor`,
361
+ );
362
+ }
363
+ }
364
+ await this.readCurrentIndex(true, false);
365
+ // tweak_fsmonitor on the index read: the monitor asked, the extension added or removed
366
+ const hadFsmonitor = !!this.staging.getFsmonitor?.();
367
+ const fsm = await this.fsmonitorRefresh(this.staging);
368
+ const run = new UpdateIndexRun(this.context(fsm?.state));
369
+ for (const warning of fsm?.warnings ?? []) run.stderr.push(`warning: ${warning}`);
370
+ try {
371
+ await this.inOneOperation(async () => {
372
+ for (const step of this.steps) await run.step(step);
373
+ if (this.indexInfo) await run.readIndexInfo(this.indexInfo.text, this.nulTerminated);
374
+ this.applyIndexVersion(run);
375
+ if (this.stdinPaths !== undefined) {
376
+ const badlyQuoted = (): never => {
377
+ throw new Death("line is badly quoted");
378
+ };
379
+ for (const path of inputPaths(this.stdinPaths, this.nulTerminated, badlyQuoted)) {
380
+ await run.updateOne(path);
381
+ }
382
+ }
383
+ await this.applyFsmonitor(run);
384
+ });
385
+ } catch (error) {
386
+ if (error instanceof Death) {
387
+ throw new UpdateIndexFailedError(
388
+ [...run.stderr, `fatal: ${error.message}`].join("\n"),
389
+ run.stdout.join(""),
390
+ );
391
+ }
392
+ throw error;
393
+ }
394
+ // FSMONITOR_CHANGED: the extension added or removed, bits set
395
+ const fsmonitorNow = this.staging.getFsmonitor?.();
396
+ const fsmonitorChanged = !!fsmonitorNow?.changed || (hadFsmonitor && !fsmonitorNow);
397
+ if (run.changed || this.forceWrite || fsmonitorChanged) {
398
+ try {
399
+ await run.write();
400
+ } catch (error) {
401
+ if (error instanceof Death) {
402
+ throw new UpdateIndexFailedError(
403
+ [...run.stderr, `fatal: ${error.message}`].join("\n"),
404
+ run.stdout.join(""),
405
+ );
406
+ }
407
+ throw error;
408
+ }
409
+ }
410
+ return {
411
+ output: run.stdout.join(""),
412
+ errors: run.stderr.map((l) => `${l}\n`).join(""),
413
+ exitCode: run.hasErrors ? 1 : 0,
414
+ };
415
+ }
416
+
417
+ /** `--[no-]fsmonitor`: `add_fsmonitor` / `remove_fsmonitor` and their warnings. */
418
+ private async applyFsmonitor(run: UpdateIndexRun): Promise<void> {
419
+ if (this.fsmonitor === undefined) return;
420
+ const mode = fsmonitorModeOf(RemoteConfigStore.from(this.workingCopy).value("core.fsmonitor"));
421
+ const staging = this.staging;
422
+ if (this.fsmonitor) {
423
+ if (mode.kind === "disabled") {
424
+ run.stderr.push(
425
+ "warning: core.fsmonitor is unset; set it if you really want to enable fsmonitor",
426
+ );
427
+ }
428
+ if (!staging.getFsmonitor?.() && staging.setFsmonitor) {
429
+ // add_fsmonitor: a nanosecond token, every entry dirty; written although the
430
+ // monitor is off (the next read with it off removes it)
431
+ const state = new FsmonitorState(String(BigInt(Date.now()) * 1_000_000n));
432
+ state.changed = true;
433
+ state.writtenWhileDisabled = mode.kind === "disabled";
434
+ staging.setFsmonitor(state);
435
+ }
436
+ run.report("fsmonitor enabled");
437
+ } else {
438
+ if (mode.kind !== "disabled" && this.hasWorktree()) {
439
+ run.stderr.push(
440
+ "warning: core.fsmonitor is set; remove it if you really want to disable fsmonitor",
441
+ );
442
+ }
443
+ staging.setFsmonitor?.(undefined);
444
+ run.report("fsmonitor disabled");
445
+ }
446
+ }
447
+
448
+ /** git's `xgetcwd()` for a bare repository: the git directory's host path. */
449
+ private async currentDirectory(): Promise<string> {
450
+ const layout = await hookHostOf(this.workingCopy).layout();
451
+ if (!layout) return ".";
452
+ const root = (layout.files as { rootDirectory?: string }).rootDirectory;
453
+ if (!root) return layout.gitDir;
454
+ const base = root.replace(/\/+$/, "");
455
+ const rest = layout.gitDir.replace(/^\.?\/*|\/+$/g, "");
456
+ const path = rest ? `${base}/${rest}` : base || "/";
457
+ const environment = hostEnvironmentOf(this.workingCopy);
458
+ return (await environment?.realPath?.(path).catch(() => undefined)) ?? path;
459
+ }
460
+
461
+ private applyIndexVersion(run: UpdateIndexRun): void {
462
+ const staging = this.staging as unknown as {
463
+ _getVersion?(): number;
464
+ _setVersion?(version: number): void;
465
+ };
466
+ const current = staging._getVersion?.() ?? 2;
467
+ if (this.showIndexVersion) run.stdout.push(`${current}\n`);
468
+ const wanted = this.indexVersion;
469
+ if (wanted === undefined || wanted === 0) return;
470
+ if (wanted < 2 || wanted > 4) throw new Death(`index-version ${wanted} not in range: 2..4`);
471
+ if (current !== wanted) run.changed = true;
472
+ run.report(`index-version: was ${current}, set to ${wanted}`);
473
+ run.version = wanted;
474
+ if (staging._setVersion) run.setVersion = (v) => staging._setVersion?.(v);
475
+ }
476
+
477
+ private context(fsmonitor: FsmonitorState | undefined): RunContext {
478
+ const worktree = this.worktreeAccess;
479
+ return {
480
+ fsmonitor,
481
+ staging: this.staging,
482
+ worktree,
483
+ blobs: this.blobs,
484
+ trust: worktree
485
+ ? worktreeModeTrust(this.workingCopy, worktree)
486
+ : { executable: true, symlinks: true },
487
+ pathRules: worktreePathRules(this.workingCopy),
488
+ nullId: this.objectFormat.nullId,
489
+ ignoreStat: configBool(this.workingCopy, "core.ignoreStat", false),
490
+ hexLength: this.objectFormat.hexLength,
491
+ };
492
+ }
493
+ }
494
+
495
+ interface RunContext {
496
+ /** The index's fsmonitor state, the monitor asked (undefined while it is off) */
497
+ fsmonitor: FsmonitorState | undefined;
498
+ staging: UpdateIndexCommand["staging"];
499
+ worktree: Worktree | undefined;
500
+ blobs: UpdateIndexCommand["blobs"];
501
+ trust: WorktreeModeTrust;
502
+ pathRules: ReturnType<typeof worktreePathRules>;
503
+ nullId: string;
504
+ /** `core.ignoreStat` (git's `assume_unchanged`) */
505
+ ignoreStat: boolean;
506
+ hexLength: number;
507
+ }
508
+
509
+ /** One run of `update-index` over the index read at its start (git's `the_index`). */
510
+ class UpdateIndexRun {
511
+ readonly stdout: string[] = [];
512
+ readonly stderr: string[] = [];
513
+ changed = false;
514
+ hasErrors = false;
515
+ version?: number;
516
+ setVersion?: (version: number) => void;
517
+ private readonly state: State = {
518
+ add: false,
519
+ remove: false,
520
+ replace: false,
521
+ forceRemove: false,
522
+ infoOnly: false,
523
+ verbose: false,
524
+ ignoreSkipWorktreeEntries: false,
525
+ quiet: false,
526
+ unmerged: false,
527
+ ignoreMissing: false,
528
+ ignoreSubmodules: false,
529
+ };
530
+ private entries: Entry[] = [];
531
+ private loaded = false;
532
+ private readonly invalidated = new Set<string>();
533
+ private readonly resolveUndo = new Map<string, ResolveUndoRecord>();
534
+ private indexTime = 0;
535
+
536
+ constructor(private readonly ctx: RunContext) {}
537
+
538
+ private async load(): Promise<void> {
539
+ if (this.loaded) return;
540
+ this.loaded = true;
541
+ const staging = this.ctx.staging;
542
+ const list = staging.entryList?.();
543
+ if (list) this.entries = [...list];
544
+ else for await (const e of staging.entries()) this.entries.push(e);
545
+ this.indexTime = staging.getUpdateTime();
546
+ }
547
+
548
+ report(line: string): void {
549
+ if (this.state.verbose) this.stdout.push(`${line}\n`);
550
+ }
551
+
552
+ async step(step: Step): Promise<void> {
553
+ await this.load();
554
+ switch (step.kind) {
555
+ case "set":
556
+ step.apply(this.state);
557
+ return;
558
+ case "path":
559
+ await this.updateOne(step.path);
560
+ return;
561
+ case "cacheinfo":
562
+ if (!this.addCacheInfo(step.mode, step.id, step.path, 0)) {
563
+ throw new Death(`git update-index: --cacheinfo cannot add ${step.path}`);
564
+ }
565
+ return;
566
+ case "refresh":
567
+ await this.refresh(step.really);
568
+ return;
569
+ }
570
+ }
571
+
572
+ // ------------------------------------------------------------------------------------------
573
+ // The index in memory (read-cache.c)
574
+
575
+ /** `index_name_stage_pos`: the entry's position, or -(insert position)-1. */
576
+ private pos(name: string, stage: number): number {
577
+ let lo = 0;
578
+ let hi = this.entries.length;
579
+ while (lo < hi) {
580
+ const mid = (lo + hi) >>> 1;
581
+ const e = this.entries[mid] as Entry;
582
+ const c = compareNames(name, e.path) || stage - e.stage;
583
+ if (c === 0) return mid;
584
+ if (c < 0) hi = mid;
585
+ else lo = mid + 1;
586
+ }
587
+ return -lo - 1;
588
+ }
589
+
590
+ /** `index_name_pos`: the stage-0 entry's position, or -(insert position)-1. */
591
+ private namePos(name: string): number {
592
+ return this.pos(name, 0);
593
+ }
594
+
595
+ private invalidate(path: string): void {
596
+ this.invalidated.add(path);
597
+ }
598
+
599
+ /** `remove_index_entry_at`: a conflict stage removed is kept as resolve-undo. */
600
+ private removeAt(pos: number): void {
601
+ const ce = this.entries[pos] as Entry;
602
+ if (ce.stage > 0) {
603
+ let record = this.resolveUndo.get(ce.path);
604
+ if (!record) {
605
+ record = { path: ce.path, modes: [0, 0, 0], objectIds: [undefined, undefined, undefined] };
606
+ this.resolveUndo.set(ce.path, record);
607
+ }
608
+ record.modes[ce.stage - 1] = ce.mode;
609
+ record.objectIds[ce.stage - 1] = ce.objectId;
610
+ }
611
+ this.entries.splice(pos, 1);
612
+ this.changed = true;
613
+ }
614
+
615
+ /** `remove_file_from_index`: every stage of `path` removed. */
616
+ private removeFile(path: string): void {
617
+ let pos = this.namePos(path);
618
+ if (pos < 0) pos = -pos - 1;
619
+ this.invalidate(path);
620
+ while (pos < this.entries.length && (this.entries[pos] as Entry).path === path) {
621
+ this.removeAt(pos);
622
+ }
623
+ }
624
+
625
+ /** `add_index_entry` with OK_TO_ADD / OK_TO_REPLACE as the flags say; false: refused. */
626
+ private addEntry(ce: Entry): boolean {
627
+ let okToAdd = this.state.add;
628
+ const okToReplace = this.state.replace;
629
+ let pos = this.pos(ce.path, ce.stage);
630
+ this.invalidate(ce.path);
631
+ if (pos >= 0) {
632
+ this.entries[pos] = ce;
633
+ this.changed = true;
634
+ return true;
635
+ }
636
+ pos = -pos - 1;
637
+ if (ce.stage === 0) {
638
+ while (pos < this.entries.length && (this.entries[pos] as Entry).path === ce.path) {
639
+ okToAdd = true;
640
+ this.removeAt(pos);
641
+ }
642
+ }
643
+ if (!okToAdd) return false;
644
+ if (!isValidWorktreePath(ce.path, ce.mode, this.ctx.pathRules)) {
645
+ this.stderr.push(`error: invalid path '${ce.path}'`);
646
+ return false;
647
+ }
648
+ if (this.fileDirectoryConflict(ce, pos, okToReplace)) {
649
+ if (!okToReplace) {
650
+ this.stderr.push(`error: '${ce.path}' appears as both a file and as a directory`);
651
+ return false;
652
+ }
653
+ pos = -this.pos(ce.path, ce.stage) - 1;
654
+ }
655
+ this.entries.splice(pos, 0, ce);
656
+ this.changed = true;
657
+ return true;
658
+ }
659
+
660
+ /** `check_file_directory_conflict`: `has_file_name`, then `has_dir_name`. */
661
+ private fileDirectoryConflict(ce: Entry, at: number, okToReplace: boolean): boolean {
662
+ let conflict = false;
663
+ // has_file_name: entries below the new path as a directory
664
+ let pos = at;
665
+ const name = ce.path;
666
+ while (pos < this.entries.length) {
667
+ const p = this.entries[pos++] as Entry;
668
+ if (name.length >= p.path.length || !p.path.startsWith(name)) break;
669
+ if (p.stage !== ce.stage) continue;
670
+ if (p.path[name.length] !== "/") continue;
671
+ conflict = true;
672
+ if (!okToReplace) return true;
673
+ this.removeAt(--pos);
674
+ }
675
+ // has_dir_name: a file where one of its leading directories goes
676
+ for (let slash = name.lastIndexOf("/"); slash > 0; slash = name.lastIndexOf("/", slash - 1)) {
677
+ const dir = name.slice(0, slash);
678
+ const found = this.pos(dir, ce.stage);
679
+ if (found >= 0) {
680
+ conflict = true;
681
+ if (!okToReplace) return true;
682
+ this.removeAt(found);
683
+ continue;
684
+ }
685
+ // a directory of that name already in the index: the levels above are fine too
686
+ let p = -found - 1;
687
+ let exists = false;
688
+ while (p < this.entries.length) {
689
+ const e = this.entries[p] as Entry;
690
+ if (e.path.length <= dir.length || e.path[dir.length] !== "/" || !e.path.startsWith(dir)) {
691
+ break;
692
+ }
693
+ if (e.stage === ce.stage) {
694
+ exists = true;
695
+ break;
696
+ }
697
+ p++;
698
+ }
699
+ if (exists) break;
700
+ }
701
+ return conflict;
702
+ }
703
+
704
+ // ------------------------------------------------------------------------------------------
705
+ // update_one and its helpers
706
+
707
+ /** git's `update_one`. */
708
+ async updateOne(path: string): Promise<void> {
709
+ await this.load();
710
+ const s = this.state;
711
+ const markOnly =
712
+ s.markValid !== undefined ||
713
+ s.markSkipWorktree !== undefined ||
714
+ s.markFsmonitor !== undefined;
715
+ let current: WorktreeEntry | undefined;
716
+ let missing = false;
717
+ let mode = 0;
718
+ if (!markOnly && !s.forceRemove) {
719
+ current = await this.ctx.worktree?.getEntry(path).catch(() => undefined);
720
+ missing = !current;
721
+ if (current) mode = current.isDirectory ? 0o040000 : current.mode;
722
+ }
723
+ if (!isValidWorktreePath(path, mode, this.ctx.pathRules)) {
724
+ this.stderr.push(`Ignoring path ${path}`);
725
+ return;
726
+ }
727
+ if (s.markValid !== undefined) {
728
+ if (!this.markFlags(path, "assumeValid", s.markValid)) {
729
+ throw new Death(`Unable to mark file ${path}`);
730
+ }
731
+ return this.chmodAfter(path);
732
+ }
733
+ if (s.markSkipWorktree !== undefined) {
734
+ if (!this.markFlags(path, "skipWorktree", s.markSkipWorktree)) {
735
+ throw new Death(`Unable to mark file ${path}`);
736
+ }
737
+ return this.chmodAfter(path);
738
+ }
739
+ if (s.markFsmonitor !== undefined) {
740
+ if (!this.markFsmonitor(path, s.markFsmonitor)) {
741
+ throw new Death(`Unable to mark file ${path}`);
742
+ }
743
+ return this.chmodAfter(path);
744
+ }
745
+ if (s.forceRemove) {
746
+ this.removeFile(path);
747
+ this.report(`remove '${path}'`);
748
+ return this.chmodAfter(path);
749
+ }
750
+ if (!(await this.processPath(path, current, missing))) {
751
+ throw new Death(`Unable to process path ${path}`);
752
+ }
753
+ this.report(`add '${path}'`);
754
+ return this.chmodAfter(path);
755
+ }
756
+
757
+ /** The `--chmod` that follows every path (`chmod_path`). */
758
+ private chmodAfter(path: string): void {
759
+ const flip = this.state.chmod;
760
+ if (!flip) return;
761
+ const pos = this.namePos(path);
762
+ const ce = pos >= 0 ? (this.entries[pos] as Entry) : undefined;
763
+ if (!ce || (ce.mode & S_IFMT) !== S_IFREG) {
764
+ throw new Death(`git update-index: cannot chmod ${flip} '${path}'`);
765
+ }
766
+ // chmod_index_entry
767
+ const mode = flip === "+x" ? FileMode.EXECUTABLE_FILE : FileMode.REGULAR_FILE;
768
+ this.entries[pos] = { ...ce, mode };
769
+ this.invalidate(path);
770
+ this.changed = true;
771
+ this.report(`chmod ${flip} '${path}'`);
772
+ }
773
+
774
+ /** `mark_ce_flags`: false when the path has no stage-0 entry. */
775
+ private markFlags(path: string, flag: "assumeValid" | "skipWorktree", mark: boolean): boolean {
776
+ const pos = this.namePos(path);
777
+ if (pos < 0) return false;
778
+ const ce = this.entries[pos] as Entry;
779
+ this.entries[pos] = { ...ce, [flag]: mark };
780
+ this.invalidate(path);
781
+ this.changed = true;
782
+ return true;
783
+ }
784
+
785
+ /** `mark_ce_flags` with `CE_FSMONITOR_VALID`: false when the path has no stage-0 entry. */
786
+ private markFsmonitor(path: string, mark: boolean): boolean {
787
+ const pos = this.namePos(path);
788
+ if (pos < 0) return false;
789
+ const ce = this.entries[pos] as Entry;
790
+ const state = this.ctx.fsmonitor;
791
+ if (state) {
792
+ state.markInvalid(ce);
793
+ if (mark) state.markValid(ce, { gitlinks: true });
794
+ }
795
+ this.invalidate(path);
796
+ this.changed = true;
797
+ return true;
798
+ }
799
+
800
+ /** `remove_one_path`. */
801
+ private removeOnePath(path: string): boolean {
802
+ if (!this.state.remove) {
803
+ this.stderr.push(`error: ${path}: does not exist and --remove not passed`);
804
+ return false;
805
+ }
806
+ this.removeFile(path);
807
+ return true;
808
+ }
809
+
810
+ /** `process_path`: false where git's returns an error. */
811
+ private async processPath(
812
+ path: string,
813
+ current: WorktreeEntry | undefined,
814
+ missing: boolean,
815
+ ): Promise<boolean> {
816
+ if (await this.beyondSymlink(path)) {
817
+ this.stderr.push(`error: '${path}' is beyond a symbolic link`);
818
+ return false;
819
+ }
820
+ const pos = this.namePos(path);
821
+ const ce = pos >= 0 ? (this.entries[pos] as Entry) : undefined;
822
+ if (ce?.skipWorktree) {
823
+ // the worktree's version is assumed good: only a removal applies
824
+ if (!this.state.ignoreSkipWorktreeEntries && this.state.remove) this.removeFile(path);
825
+ return true;
826
+ }
827
+ if (missing || !current) return this.removeOnePath(path);
828
+ if (current.isDirectory) return this.processDirectory(path, current);
829
+ return this.addOnePath(ce, path, current);
830
+ }
831
+
832
+ /** `has_symlink_leading_path`. */
833
+ private async beyondSymlink(path: string): Promise<boolean> {
834
+ const worktree = this.ctx.worktree;
835
+ if (!worktree) return false;
836
+ for (let at = path.indexOf("/"); at > 0; at = path.indexOf("/", at + 1)) {
837
+ const dir = await worktree.getEntry(path.slice(0, at)).catch(() => undefined);
838
+ if (!dir) return false;
839
+ if (!dir.isDirectory && (dir.mode & S_IFMT) === FileMode.SYMLINK) return true;
840
+ if (!dir.isDirectory) return false;
841
+ }
842
+ return false;
843
+ }
844
+
845
+ /** `process_directory`. */
846
+ private async processDirectory(path: string, current: WorktreeEntry): Promise<boolean> {
847
+ const worktree = this.ctx.worktree as Worktree;
848
+ const pos = this.namePos(path);
849
+ if (pos >= 0) {
850
+ const ce = this.entries[pos] as Entry;
851
+ if (ce.mode === FileMode.GITLINK) {
852
+ const head = await worktree.readGitlinkHead?.(path).catch(() => undefined);
853
+ if (!head) return true;
854
+ return this.addGitlink(ce, path, current, head);
855
+ }
856
+ return this.removeOnePath(path);
857
+ }
858
+ // a subdirectory of entries: an error
859
+ for (let p = -pos - 1; p < this.entries.length; p++) {
860
+ const e = this.entries[p] as Entry;
861
+ if (!e.path.startsWith(path)) break;
862
+ const c = e.path.charCodeAt(path.length);
863
+ if (c > 0x2f) break;
864
+ if (c < 0x2f) continue;
865
+ this.stderr.push(`error: ${path}: is a directory - add individual files instead`);
866
+ return false;
867
+ }
868
+ const head = await worktree.readGitlinkHead?.(path).catch(() => undefined);
869
+ if (head) return this.addGitlink(undefined, path, current, head);
870
+ this.stderr.push(`error: ${path}: is a directory - add files inside instead`);
871
+ return false;
872
+ }
873
+
874
+ private addGitlink(
875
+ old: Entry | undefined,
876
+ path: string,
877
+ current: WorktreeEntry,
878
+ head: ObjectId,
879
+ ): boolean {
880
+ // ie_match_stat of a gitlink: only the commit checked out counts
881
+ if (old && old.stage === 0 && old.objectId === head) return true;
882
+ const ce: Entry = {
883
+ path,
884
+ mode: FileMode.GITLINK,
885
+ objectId: head,
886
+ stage: 0,
887
+ ...entryStatOf(current),
888
+ };
889
+ if (!this.addEntry(ce)) {
890
+ this.stderr.push(`error: ${path}: cannot add to the index - missing --add option?`);
891
+ return false;
892
+ }
893
+ return true;
894
+ }
895
+
896
+ /** Whether `old` is up to date with the file (`ie_match_stat(old, st, 0)` is 0). */
897
+ private async upToDate(old: Entry, current: WorktreeEntry): Promise<boolean> {
898
+ if (old.assumeValid) return true;
899
+ if (old.intentToAdd) return false;
900
+ const trust = this.ctx.trust;
901
+ if (modeFromWorktree(current.mode, old.mode, trust) !== old.mode) return false;
902
+ if (!basicStatMatches(old, current, trust)) return false;
903
+ const racy =
904
+ this.indexTime === 0 || wholeSeconds(old.mtime, old.mtimeNs) >= wholeSeconds(this.indexTime);
905
+ if (!racy) return true;
906
+ const worktree = this.ctx.worktree as Worktree;
907
+ return (await worktree.computeHash(old.path).catch(() => undefined)) === old.objectId;
908
+ }
909
+
910
+ /** `add_one_path`. */
911
+ private async addOnePath(
912
+ old: Entry | undefined,
913
+ path: string,
914
+ current: WorktreeEntry,
915
+ ): Promise<boolean> {
916
+ if (old && old.stage === 0 && (await this.upToDate(old, current))) return true;
917
+ const worktree = this.ctx.worktree as Worktree;
918
+ let id: ObjectId;
919
+ let stat = current;
920
+ try {
921
+ if (this.state.infoOnly) {
922
+ id = await worktree.computeHash(path);
923
+ } else {
924
+ const stored = await storeWorktreeFile(this.ctx.blobs, worktree, path, current);
925
+ id = stored.id;
926
+ stat = stored.entry;
927
+ }
928
+ } catch (error) {
929
+ this.stderr.push(`error: ${(error as Error).message}`);
930
+ return false;
931
+ }
932
+ const ce: Entry = {
933
+ path,
934
+ mode: modeFromWorktree(stat.mode, old?.mode, this.ctx.trust) as FileModeValue,
935
+ objectId: id,
936
+ stage: 0,
937
+ ...entryStatOf(stat),
938
+ };
939
+ if (!this.addEntry(ce)) {
940
+ this.stderr.push(`error: ${path}: cannot add to the index - missing --add option?`);
941
+ return false;
942
+ }
943
+ return true;
944
+ }
945
+
946
+ /** `add_cacheinfo`: false where git returns an error. */
947
+ private addCacheInfo(mode: number, id: string, path: string, stage: number): boolean {
948
+ if (!isValidWorktreePath(path, mode, this.ctx.pathRules)) {
949
+ this.stderr.push(`error: Invalid path '${path}'`);
950
+ return false;
951
+ }
952
+ const ce: Entry = {
953
+ path,
954
+ mode: createCeMode(mode) as FileModeValue,
955
+ objectId: id.toLowerCase(),
956
+ stage: stage as Entry["stage"],
957
+ size: 0,
958
+ mtime: 0,
959
+ // add_cacheinfo's CE_VALID is core.ignoreStat's (assume_unchanged), not the option
960
+ ...(this.ctx.ignoreStat ? { assumeValid: true } : {}),
961
+ };
962
+ if (!this.addEntry(ce)) {
963
+ this.stderr.push(`error: ${path}: cannot add to the index - missing --add option?`);
964
+ return false;
965
+ }
966
+ this.report(`add '${path}'`);
967
+ return true;
968
+ }
969
+
970
+ // ------------------------------------------------------------------------------------------
971
+ // --index-info
972
+
973
+ /** `read_index_info`. */
974
+ async readIndexInfo(input: string | Uint8Array, nul: boolean): Promise<void> {
975
+ await this.load();
976
+ const s = this.state;
977
+ s.add = true;
978
+ s.replace = true;
979
+ s.remove = true;
980
+ const hex = this.ctx.hexLength;
981
+ for (const line of inputLines(input, nul)) {
982
+ const bad = (): never => {
983
+ throw new Death(`malformed index info ${line}`);
984
+ };
985
+ const m = /^([0-7]+) /.exec(line);
986
+ if (!m) bad();
987
+ const mode = Number.parseInt((m as RegExpExecArray)[1] as string, 8);
988
+ if (mode > 0xffffffff) bad();
989
+ let tab = line.indexOf("\t");
990
+ if (tab < 0 || tab - (m as RegExpExecArray)[0].length + 1 < hex + 1) bad();
991
+ let stage = 0;
992
+ const pathAt = tab + 1;
993
+ if (
994
+ line[tab - 2] === " " &&
995
+ line[tab - 1] !== undefined &&
996
+ /[0-3]/.test(line[tab - 1] as string)
997
+ ) {
998
+ stage = Number(line[tab - 1]);
999
+ tab -= 2;
1000
+ }
1001
+ const id = line.slice(tab - hex, tab);
1002
+ if (!/^[0-9a-fA-F]+$/.test(id) || id.length !== hex || line[tab - hex - 1] !== " ") bad();
1003
+ let path = line.slice(pathAt);
1004
+ if (!nul && path.startsWith('"')) {
1005
+ const unquoted = unquoteLine(path);
1006
+ if (unquoted === undefined) throw new Death("git update-index: bad quoting of path name");
1007
+ path = unquoted;
1008
+ }
1009
+ if (!isValidWorktreePath(path, mode, this.ctx.pathRules)) {
1010
+ this.stderr.push(`Ignoring path ${path}`);
1011
+ continue;
1012
+ }
1013
+ if (mode === 0) {
1014
+ this.removeFile(path);
1015
+ } else if (!this.addCacheInfo(mode, id, path, stage)) {
1016
+ throw new Death(`git update-index: unable to update ${path}`);
1017
+ }
1018
+ }
1019
+ }
1020
+
1021
+ // ------------------------------------------------------------------------------------------
1022
+ // --refresh / --really-refresh
1023
+
1024
+ /** `refresh_index` over the entries (read-cache.c), then `has_racy_timestamp`. */
1025
+ private async refresh(really: boolean): Promise<void> {
1026
+ const s = this.state;
1027
+ const worktree = this.ctx.worktree;
1028
+ if (!worktree) return;
1029
+ const trust = this.ctx.trust;
1030
+ const fsmonitor = this.ctx.fsmonitor;
1031
+ for (let i = 0; i < this.entries.length; i++) {
1032
+ const ce = this.entries[i] as Entry;
1033
+ if (s.ignoreSubmodules && ce.mode === FileMode.GITLINK) continue;
1034
+ if (ce.stage !== 0) {
1035
+ while (i < this.entries.length && (this.entries[i] as Entry).path === ce.path) i++;
1036
+ i--;
1037
+ if (s.unmerged) continue;
1038
+ this.stdout.push(`${ce.path}: needs merge\n`);
1039
+ this.hasErrors = true;
1040
+ continue;
1041
+ }
1042
+ // refresh_cache_ent: what the user promised not to have changed
1043
+ if (ce.skipWorktree) continue;
1044
+ if (!really && ce.assumeValid) continue;
1045
+ // CE_FSMONITOR_VALID: the monitor reported nothing for it, taken as up to date unseen
1046
+ if (fsmonitor?.isValid(ce)) continue;
1047
+ const current = await worktree.getEntry(ce.path).catch(() => undefined);
1048
+ if (!current && s.ignoreMissing) continue;
1049
+ let changed: boolean;
1050
+ let fresh: Entry | undefined;
1051
+ if (ce.intentToAdd) {
1052
+ changed = true;
1053
+ } else {
1054
+ const compared = await compareWithWorktree(
1055
+ worktree,
1056
+ ce,
1057
+ { trust, indexTime: this.indexTime },
1058
+ current ?? null,
1059
+ );
1060
+ changed = compared.kind !== undefined;
1061
+ const file = compared.worktreeEntry;
1062
+ // proved clean by reading it: its fresh stat recorded (refresh_cache_ent's copy)
1063
+ if (!changed && compared.hashedId === ce.objectId && file && !file.isDirectory) {
1064
+ fresh = { ...ce, ...entryStatOf(file) };
1065
+ }
1066
+ }
1067
+ if (changed) {
1068
+ if (really && ce.assumeValid && current) {
1069
+ // the promise broken: the flag goes
1070
+ this.entries[i] = { ...ce, assumeValid: false };
1071
+ this.changed = true;
1072
+ }
1073
+ if (s.quiet) continue;
1074
+ this.stdout.push(`${ce.path}: needs update\n`);
1075
+ this.hasErrors = true;
1076
+ continue;
1077
+ }
1078
+ if (fresh && !sameStat(fresh, ce)) {
1079
+ // replaced (its stat stored): no longer fsmonitor-valid (replace_index_entry)
1080
+ this.entries[i] = fresh;
1081
+ this.changed = true;
1082
+ } else {
1083
+ // up to date as it is: mark_fsmonitor_valid (gitlinks never)
1084
+ fsmonitor?.markValid(ce);
1085
+ }
1086
+ }
1087
+ // has_racy_timestamp: written anyway, so the racy entries stop being racy
1088
+ for (const ce of this.entries) {
1089
+ if (ce.stage !== 0) continue;
1090
+ if (
1091
+ this.indexTime === 0 ||
1092
+ wholeSeconds(ce.mtime, ce.mtimeNs) >= wholeSeconds(this.indexTime)
1093
+ ) {
1094
+ if (ce.mtime !== 0) {
1095
+ this.changed = true;
1096
+ break;
1097
+ }
1098
+ }
1099
+ }
1100
+ }
1101
+
1102
+ // ------------------------------------------------------------------------------------------
1103
+ // Writing
1104
+
1105
+ /** `write_locked_index`: the entries, invalidated cache-tree paths and resolve-undo. */
1106
+ async write(): Promise<void> {
1107
+ await this.load();
1108
+ for (const ce of this.entries) {
1109
+ if (ce.objectId === this.ctx.nullId) {
1110
+ this.stderr.push(`error: cache entry has null sha1: ${ce.path}`);
1111
+ throw new Death("Unable to write new index file");
1112
+ }
1113
+ }
1114
+ const staging = this.ctx.staging;
1115
+ const tree = staging.getCacheTree?.();
1116
+ const builder = staging.createBuilder();
1117
+ for (const ce of this.entries) builder.add(ce);
1118
+ await builder.finish({ upToDate: false });
1119
+ if (staging.setCacheTree) {
1120
+ if (tree) for (const path of this.invalidated) invalidateCacheTreePath(tree, path);
1121
+ staging.setCacheTree(tree);
1122
+ }
1123
+ if (this.resolveUndo.size > 0) staging.recordResolveUndo?.([...this.resolveUndo.values()]);
1124
+ if (this.version !== undefined) this.setVersion?.(this.version);
1125
+ await staging.write();
1126
+ }
1127
+ }
1128
+
1129
+ function sameStat(a: Entry, b: Entry): boolean {
1130
+ return (
1131
+ a.size === b.size &&
1132
+ a.mtime === b.mtime &&
1133
+ a.mtimeNs === b.mtimeNs &&
1134
+ a.ctime === b.ctime &&
1135
+ a.ctimeNs === b.ctimeNs &&
1136
+ a.dev === b.dev &&
1137
+ a.ino === b.ino &&
1138
+ a.uid === b.uid &&
1139
+ a.gid === b.gid
1140
+ );
1141
+ }
1142
+
1143
+ /** git's `create_ce_mode`. */
1144
+ function createCeMode(mode: number): number {
1145
+ if ((mode & S_IFMT) === FileMode.SYMLINK) return FileMode.SYMLINK;
1146
+ if ((mode & S_IFMT) === 0o040000 || (mode & S_IFMT) === FileMode.GITLINK) return FileMode.GITLINK;
1147
+ return S_IFREG | ((mode & 0o100) !== 0 ? 0o755 : 0o644);
1148
+ }