@openchamber/web 1.24.0 → 1.24.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.
- package/bin/cli.test.js +29 -6
- package/bin/lib/cli-http.js +5 -1
- package/bin/lib/commands-status.js +5 -0
- package/dist/assets/{CodeMirrorCommentWidgets-C9kV-n7r.js → CodeMirrorCommentWidgets-B_vBPQYm.js} +1 -1
- package/dist/assets/DiffView-Ce0oBXXQ.js +4 -0
- package/dist/assets/{FilesView-vjJx7VaM.js → FilesView-DtXueAWP.js} +6 -6
- package/dist/assets/GitView-k0hUF8KB.js +6 -0
- package/dist/assets/GuestAttachDialog-DIf2U85Z.js +1 -0
- package/dist/assets/{JsonTreeView-D_4G5X6-.js → JsonTreeView-4AnJ04Pw.js} +1 -1
- package/dist/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- package/dist/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
- package/dist/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
- package/dist/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
- package/dist/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
- package/dist/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- package/dist/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
- package/dist/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- package/dist/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
- package/dist/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
- package/dist/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
- package/dist/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- package/dist/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
- package/dist/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- package/dist/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
- package/dist/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- package/dist/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
- package/dist/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
- package/dist/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- package/dist/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
- package/dist/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
- package/dist/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
- package/dist/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
- package/dist/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- package/dist/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- package/dist/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
- package/dist/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
- package/dist/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
- package/dist/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
- package/dist/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
- package/dist/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
- package/dist/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
- package/dist/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
- package/dist/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
- package/dist/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
- package/dist/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
- package/dist/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
- package/dist/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
- package/dist/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
- package/dist/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
- package/dist/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
- package/dist/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
- package/dist/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
- package/dist/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
- package/dist/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
- package/dist/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
- package/dist/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
- package/dist/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
- package/dist/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
- package/dist/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
- package/dist/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
- package/dist/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
- package/dist/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
- package/dist/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
- package/dist/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
- package/dist/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
- package/dist/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
- package/dist/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
- package/dist/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
- package/dist/assets/{LinearIssuesView-1uKhePfH.js → LinearIssuesView-z_9p2GuO.js} +1 -1
- package/dist/assets/{MarkdownImageGallery-Ix7N_2wp.js → MarkdownImageGallery-BC-BNN-s.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-Deel_y5S.js → MarkdownRendererImpl-DyaBTUbH.js} +6 -6
- package/dist/assets/{OnboardingScreen-ToIakxb_.js → OnboardingScreen-DKU_yTb6.js} +1 -1
- package/dist/assets/{PatchDiff-BjMgezr1.js → PatchDiff-DpGmHRnV.js} +1 -1
- package/dist/assets/PierreDiffViewer-CgLl_tp7.js +210 -0
- package/dist/assets/{PlanView-BGAzxDwD.js → PlanView-CrfB4qqY.js} +4 -4
- package/dist/assets/PluginPane-B5cn-jPy.js +3 -0
- package/dist/assets/SettingsView-DMKKwezx.js +29 -0
- package/dist/assets/SettingsWindow-DwbnVzOC.js +1 -0
- package/dist/assets/{SubmoduleDiffSummary--YFqK6Ih.js → SubmoduleDiffSummary-hkGcvs0E.js} +1 -1
- package/dist/assets/{ToolOutputDialog-DRWBvdaJ.js → ToolOutputDialog-DuoIOc0j.js} +6 -6
- package/dist/assets/{ToolPartDiffPreview-BxZJCU28.js → ToolPartDiffPreview-t1Bvq_2Y.js} +2 -2
- package/dist/assets/{VirtualizedFileDiff-DCXjBGRf.js → VirtualizedFileDiff-BK4aU5qJ.js} +1 -1
- package/dist/assets/{WalkthroughView-CfIPvWWa.js → WalkthroughView-Bk6TPNFw.js} +2 -2
- package/dist/assets/{appThemeRegistry-DDROzcUO.js → appThemeRegistry-DnOVbJjF.js} +1 -1
- package/dist/assets/commitAndPush-DLWNZkkY.js +1 -0
- package/dist/assets/{computeVirtualFileMetrics-DHgQIkUq.js → computeVirtualFileMetrics-BVTujWSX.js} +1 -1
- package/dist/assets/{de-CX_f-T5U.js → de-zEHaAIi3.js} +4 -4
- package/dist/assets/{es-BERmWNn_.js → es-CBDgEzgk.js} +4 -4
- package/dist/assets/{fr-BjYYE_-z.js → fr-DjiTptT_.js} +4 -4
- package/dist/assets/index-AgOdanig.css +1 -0
- package/dist/assets/index-B-2_X4DD.js +40 -0
- package/dist/assets/{index-WjufPkIV.js → index-CkA4p2IK.js} +1 -1
- package/dist/assets/{isDiffPlainText-D9faP70y.js → isDiffPlainText-D3yX_vx4.js} +1 -1
- package/dist/assets/{isFilePlainText-6qOcz5Ky.js → isFilePlainText-CZR9TcHV.js} +1 -1
- package/dist/assets/ja-CerMgj3r.js +16 -0
- package/dist/assets/{ko-Dty1aUod.js → ko-DHYDAze5.js} +4 -4
- package/dist/assets/main-BDka4W43.js +896 -0
- package/dist/assets/main-Dl7Dyge_.js +2 -0
- package/dist/assets/markdownCore-DFmr0rUR.js +5 -0
- package/dist/assets/miniChat-CLKQPPpO.js +2 -0
- package/dist/assets/mobile--giD2Q1L.js +2 -0
- package/dist/assets/{patchFileDiff-BvU6KOQC.js → patchFileDiff-DRh-AQvd.js} +1 -1
- package/dist/assets/{pl-CX-_ROkr.js → pl-BTB_93bq.js} +6 -6
- package/dist/assets/{pt-BR-DhRR1arx.js → pt-BR-BwA3oyCK.js} +4 -4
- package/dist/assets/renderElectronMiniChatApp-DmB7zpVK.js +2 -0
- package/dist/assets/renderMobileApp-pMfOuQfl.js +25 -0
- package/dist/assets/runtimeEndpointReset-Gqhmkm3U.js +25 -0
- package/dist/assets/{scheduledTasksApi-DW3xqMQ8.js → scheduledTasksApi-CeRAIUmW.js} +1 -1
- package/dist/assets/{shikiHighlight-DsxD9QEa.js → shikiHighlight-BfjuB3CD.js} +1 -1
- package/dist/assets/{textMateThemeFromAppTheme-Da7ed8qM.js → textMateThemeFromAppTheme-BP60t9SX.js} +1 -1
- package/dist/assets/tr-CcPsJoNM.js +7 -0
- package/dist/assets/{uk-CD21CXFV.js → uk-B68WibXi.js} +4 -4
- package/dist/assets/{useAppFontEffects-hfv2s6mZ.js → useAppFontEffects-DcdrFv2Z.js} +147 -147
- package/dist/assets/{useInlineCommentController-BmtfVbo8.js → useInlineCommentController-Cq4SUjsA.js} +2 -2
- package/dist/assets/useRootScrollLock-CSdR6Wnm.js +2 -0
- package/dist/assets/{vendor-codemirror-language-data-BPMJpOpT.js → vendor-codemirror-language-data-BFm1Ju2w.js} +2 -2
- package/dist/assets/vendor-katex-Cp579UoJ.css +1 -0
- package/dist/assets/{vendor-tanstack-react-virtual-g05Cx3z9.js → vendor-tanstack-react-virtual-ClYN8CzB.js} +1 -1
- package/dist/assets/{vendor-tanstack-virtual-core-Dubg10g5.js → vendor-tanstack-virtual-core-BewVQryB.js} +1 -1
- package/dist/assets/{vendor-zod-fZppILAM.js → vendor-zod-CgAdXWZO.js} +4 -4
- package/dist/assets/{web-components-U-hWbgJo.js → web-components-2vo9YsZc.js} +1 -1
- package/dist/assets/zh-CN-DbFHYXwP.js +16 -0
- package/dist/assets/{zh-TW-CRp5dJU2.js → zh-TW-DmXAwdty.js} +4 -4
- package/dist/index.html +6 -4
- package/dist/mini-chat.html +6 -4
- package/dist/mobile.html +6 -4
- package/package.json +6 -5
- package/server/index.js +29 -7
- package/server/lib/agent-tool/DOCUMENTATION.md +17 -4
- package/server/lib/agent-tool/runtime.js +62 -15
- package/server/lib/agent-tool/runtime.test.js +88 -2
- package/server/lib/changelog/update-notes.js +2 -1
- package/server/lib/changelog/update-notes.test.js +19 -0
- package/server/lib/event-stream/DOCUMENTATION.md +23 -0
- package/server/lib/event-stream/delta-coalescer.js +0 -0
- package/server/lib/event-stream/delta-coalescer.test.js +292 -0
- package/server/lib/event-stream/global-hub.js +53 -23
- package/server/lib/event-stream/global-hub.test.js +160 -0
- package/server/lib/event-stream/global-ws-bridge.js +1 -0
- package/server/lib/event-stream/index.js +4 -0
- package/server/lib/fs/DOCUMENTATION.md +2 -1
- package/server/lib/fs/routes.js +56 -4
- package/server/lib/fs/routes.test.js +116 -0
- package/server/lib/git/DOCUMENTATION.md +18 -5
- package/server/lib/git/routes.js +1 -1
- package/server/lib/git/serial-refresh.js +93 -0
- package/server/lib/git/serial-refresh.test.js +112 -0
- package/server/lib/git/service.js +325 -70
- package/server/lib/git/service.test.js +291 -0
- package/server/lib/github/pr-status.js +5 -5
- package/server/lib/github/pr-status.test.js +1 -1
- package/server/lib/github/routes.js +4 -4
- package/server/lib/guests/DOCUMENTATION.md +5 -3
- package/server/lib/guests/background.test.js +83 -0
- package/server/lib/guests/catalog.js +20 -9
- package/server/lib/guests/catalog.test.js +5 -5
- package/server/lib/guests/routes.js +2 -2
- package/server/lib/message-queue/DOCUMENTATION.md +10 -1
- package/server/lib/message-queue/runtime.js +21 -1
- package/server/lib/message-queue/runtime.test.js +52 -5
- package/server/lib/notifications/routes.js +5 -0
- package/server/lib/openchamber-sessions/routes.js +18 -18
- package/server/lib/openchamber-sessions/routes.test.js +49 -0
- package/server/lib/opencode/DOCUMENTATION.md +1 -1
- package/server/lib/opencode/bootstrap-runtime.js +1 -0
- package/server/lib/opencode/feature-routes-runtime.js +5 -0
- package/server/lib/opencode/session-runtime.js +68 -0
- package/server/lib/opencode/session-runtime.test.js +43 -0
- package/server/lib/opencode/settings-helpers.js +3 -0
- package/server/lib/opencode/settings-registry.json +8 -0
- package/server/lib/permission-auto-accept/DOCUMENTATION.md +8 -0
- package/server/lib/permission-auto-accept/runtime.js +13 -0
- package/server/lib/permission-auto-accept/runtime.test.js +37 -1
- package/server/lib/projects/project-config.js +2 -2
- package/server/lib/realtime-proxy-terminal.test.js +150 -0
- package/server/lib/realtime-proxy.js +2 -0
- package/server/lib/routing/DOCUMENTATION.md +83 -0
- package/server/lib/routing/defaults.js +98 -0
- package/server/lib/routing/feature-flag.js +11 -0
- package/server/lib/routing/history.js +34 -0
- package/server/lib/routing/jev.js +98 -0
- package/server/lib/routing/routes.http.test.js +100 -0
- package/server/lib/routing/routes.js +81 -0
- package/server/lib/routing/runtime.js +217 -0
- package/server/lib/routing/runtime.test.js +188 -0
- package/server/lib/routing/store.js +249 -0
- package/server/lib/routing/store.test.js +96 -0
- package/server/lib/scheduled-tasks/runtime.js +2 -2
- package/server/lib/scheduled-tasks/runtime.test.js +14 -0
- package/server/lib/security/request-security.js +9 -5
- package/server/lib/security/request-security.test.js +37 -0
- package/server/lib/small-model/DOCUMENTATION.md +14 -2
- package/server/lib/small-model/call.js +37 -6
- package/server/lib/small-model/call.test.js +182 -0
- package/server/lib/terminal/DOCUMENTATION.md +21 -2
- package/server/lib/terminal/runtime.js +10 -3
- package/server/lib/terminal/runtime.test.js +22 -0
- package/server/lib/terminal/shutdown.js +106 -0
- package/server/lib/terminal/shutdown.test.js +84 -0
- package/server/lib/tts/service.test.js +78 -0
- package/server/lib/ui-auth/DOCUMENTATION.md +8 -0
- package/server/lib/ui-auth/session-cookie.js +51 -0
- package/server/lib/ui-auth/session-cookie.test.js +46 -0
- package/server/lib/ui-auth/ui-auth.js +13 -9
- package/server/lib/ui-auth/ui-auth.test.js +56 -0
- package/dist/assets/DiffView-B7YkbY-u.js +0 -4
- package/dist/assets/DirtyBranchSwitchDialog-CU0A93Zx.js +0 -1
- package/dist/assets/GitView-BLhlMYEY.js +0 -6
- package/dist/assets/GuestAttachDialog-B-fwE8r3.js +0 -3
- package/dist/assets/PierreDiffViewer-53Ghfnlr.js +0 -161
- package/dist/assets/SettingsView-n2X-jfBB.js +0 -29
- package/dist/assets/SettingsWindow-Bi8LE9XI.js +0 -1
- package/dist/assets/index-DpzTz2UH.css +0 -1
- package/dist/assets/index-Dy8xgawx.js +0 -40
- package/dist/assets/ja-DxqeAk9N.js +0 -16
- package/dist/assets/main-BOYSXfYn.js +0 -896
- package/dist/assets/main-Bjcre_GE.js +0 -2
- package/dist/assets/markdownCore-DPrwM1rU.js +0 -5
- package/dist/assets/miniChat-Dz_bPgMc.js +0 -2
- package/dist/assets/mobile-BbZPBJrK.js +0 -2
- package/dist/assets/renderElectronMiniChatApp-uNEUkeAI.js +0 -2
- package/dist/assets/renderMobileApp-BK1kFlcJ.js +0 -25
- package/dist/assets/runtimeEndpointReset-BULHvOwb.js +0 -25
- package/dist/assets/tr-cIQtYBpg.js +0 -7
- package/dist/assets/useRootScrollLock-Cwc4kSl2.js +0 -1
- package/dist/assets/zh-CN-BWvlPHY-.js +0 -16
- /package/dist/assets/{vendor-katex-k3Ppq1Ha.js → vendor-katex-CHD9BdDO.js} +0 -0
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import simpleGit from 'simple-git';
|
|
2
|
+
import { createSerialRefresh } from './serial-refresh.js';
|
|
2
3
|
import fs from 'fs';
|
|
3
4
|
import path from 'path';
|
|
4
5
|
import os from 'os';
|
|
5
|
-
import { execFile } from 'child_process';
|
|
6
|
+
import { execFile, spawn } from 'child_process';
|
|
6
7
|
import { promisify } from 'util';
|
|
7
8
|
import { createRequire } from 'module';
|
|
8
9
|
|
|
@@ -349,12 +350,22 @@ const buildGitEnv = async () => {
|
|
|
349
350
|
env.SSH_AUTH_SOCK = resolved;
|
|
350
351
|
}
|
|
351
352
|
}
|
|
353
|
+
// The server has no terminal a user could answer. Without this, Git asks
|
|
354
|
+
// for a username or password on its (hidden, on Windows) console and waits
|
|
355
|
+
// forever; credential helpers and GUI prompts still run before this point.
|
|
356
|
+
if (env.GIT_TERMINAL_PROMPT === undefined) {
|
|
357
|
+
env.GIT_TERMINAL_PROMPT = '0';
|
|
358
|
+
}
|
|
352
359
|
return env;
|
|
353
360
|
};
|
|
354
361
|
|
|
355
|
-
const createGit = async (directory, { allowUnsafeSshCommand = false, allowUnsafeCredentialHelper = false } = {}) => {
|
|
362
|
+
const createGit = async (directory, { allowUnsafeSshCommand = false, allowUnsafeCredentialHelper = false, stallTimeoutMs = 0 } = {}) => {
|
|
356
363
|
const env = await buildGitEnv();
|
|
357
364
|
const spawnOptions = { windowsHide: true };
|
|
365
|
+
// simple-git's block timeout kills the process once it has produced no
|
|
366
|
+
// output for this long. Opt-in per caller: a background read must never hold
|
|
367
|
+
// a limiter slot forever, while a silent long push or fetch must not be cut.
|
|
368
|
+
const timeout = stallTimeoutMs > 0 ? { block: stallTimeoutMs } : undefined;
|
|
358
369
|
const binary = getGitBinary();
|
|
359
370
|
const hasCustomBinary = typeof binary === 'string' && binary.trim() && binary !== 'git' && binary !== 'git.exe';
|
|
360
371
|
const unsafe = hasCustomBinary || allowUnsafeSshCommand || allowUnsafeCredentialHelper
|
|
@@ -379,6 +390,7 @@ const createGit = async (directory, { allowUnsafeSshCommand = false, allowUnsafe
|
|
|
379
390
|
spawnOptions,
|
|
380
391
|
binary,
|
|
381
392
|
unsafe,
|
|
393
|
+
...(timeout ? { timeout } : {}),
|
|
382
394
|
});
|
|
383
395
|
};
|
|
384
396
|
|
|
@@ -484,14 +496,14 @@ const resolveGitRepositoryRoot = async (directoryPath, git) => {
|
|
|
484
496
|
: path.resolve(directoryPath, normalizedTopLevel);
|
|
485
497
|
};
|
|
486
498
|
|
|
487
|
-
const createRepositoryGitContext = async (directory) => {
|
|
499
|
+
const createRepositoryGitContext = async (directory, gitOptions = {}) => {
|
|
488
500
|
const directoryPath = normalizeDirectoryPath(directory);
|
|
489
501
|
if (typeof directoryPath !== 'string' || !directoryPath.trim()) {
|
|
490
502
|
throw new Error('Git directory is required');
|
|
491
503
|
}
|
|
492
|
-
const directoryGit = await createGit(directoryPath);
|
|
504
|
+
const directoryGit = await createGit(directoryPath, gitOptions);
|
|
493
505
|
const repoRoot = await resolveGitRepositoryRoot(directoryPath, directoryGit);
|
|
494
|
-
const git = path.resolve(directoryPath) === repoRoot ? directoryGit : await createGit(repoRoot);
|
|
506
|
+
const git = path.resolve(directoryPath) === repoRoot ? directoryGit : await createGit(repoRoot, gitOptions);
|
|
495
507
|
return { directoryPath, directoryGit, repoRoot, git };
|
|
496
508
|
};
|
|
497
509
|
|
|
@@ -517,14 +529,16 @@ const GITLINK_MODE = '160000';
|
|
|
517
529
|
// tell these apart by `code`, and diff routes send the code to clients as is.
|
|
518
530
|
const GIT_PATH_NOT_FOUND = 'path_not_found';
|
|
519
531
|
const GIT_PATH_IS_NESTED_REPOSITORY = 'nested_repository';
|
|
532
|
+
const GIT_PATH_IS_UNTRACKED_DIRECTORY = 'untracked_directory';
|
|
520
533
|
|
|
521
|
-
const
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
return Object.assign(new Error(message), { code });
|
|
534
|
+
const GIT_PATH_ERROR_MESSAGES = {
|
|
535
|
+
[GIT_PATH_IS_NESTED_REPOSITORY]: (filePath) => `Path is a separate Git repository: ${filePath}`,
|
|
536
|
+
[GIT_PATH_IS_UNTRACKED_DIRECTORY]: (filePath) => `Path is a directory of untracked files: ${filePath}`,
|
|
537
|
+
[GIT_PATH_NOT_FOUND]: (filePath) => `Path not found in working tree, index, or HEAD: ${filePath}`,
|
|
526
538
|
};
|
|
527
539
|
|
|
540
|
+
const createGitPathError = (code, filePath) => Object.assign(new Error(GIT_PATH_ERROR_MESSAGES[code](filePath)), { code });
|
|
541
|
+
|
|
528
542
|
// Mode of the exact entry at `repoPath`, or null. `cat-file -e` cannot answer
|
|
529
543
|
// this: a gitlink's commit lives in the submodule's object store, so git exits 1
|
|
530
544
|
// without stderr, which simple-git reports as success.
|
|
@@ -547,6 +561,7 @@ const resolveGitFileContext = async (directoryPath, git, filePath, repoRootOverr
|
|
|
547
561
|
path.resolve(directoryPath, filePath),
|
|
548
562
|
]));
|
|
549
563
|
let nestedRepository = false;
|
|
564
|
+
let untrackedDirectory = false;
|
|
550
565
|
|
|
551
566
|
for (const absolutePath of candidates) {
|
|
552
567
|
if (!isInsideOrSameDirectory(repoRoot, absolutePath)) {
|
|
@@ -570,12 +585,20 @@ const resolveGitFileContext = async (directoryPath, git, filePath, repoRootOverr
|
|
|
570
585
|
};
|
|
571
586
|
}
|
|
572
587
|
|
|
573
|
-
if (worktreeEntry?.isDirectory()
|
|
574
|
-
|
|
588
|
+
if (worktreeEntry?.isDirectory()) {
|
|
589
|
+
if (await fsp.lstat(path.join(absolutePath, '.git')).then(() => true, () => false)) {
|
|
590
|
+
nestedRepository = true;
|
|
591
|
+
} else {
|
|
592
|
+
// Status lists a directory whose untracked files were not expanded
|
|
593
|
+
// (see readStatus) as `dir/`; there is no single patch for it.
|
|
594
|
+
untrackedDirectory = true;
|
|
595
|
+
}
|
|
575
596
|
}
|
|
576
597
|
}
|
|
577
598
|
|
|
578
|
-
|
|
599
|
+
if (nestedRepository) throw createGitPathError(GIT_PATH_IS_NESTED_REPOSITORY, filePath);
|
|
600
|
+
if (untrackedDirectory) throw createGitPathError(GIT_PATH_IS_UNTRACKED_DIRECTORY, filePath);
|
|
601
|
+
throw createGitPathError(GIT_PATH_NOT_FOUND, filePath);
|
|
579
602
|
};
|
|
580
603
|
|
|
581
604
|
/**
|
|
@@ -996,13 +1019,16 @@ const isMissingDirectoryError = (error) => {
|
|
|
996
1019
|
return /directory that does not exist|does not exist|no such file or directory/i.test(text);
|
|
997
1020
|
};
|
|
998
1021
|
|
|
999
|
-
const runGitCommand = async (cwd, args) => {
|
|
1022
|
+
const runGitCommand = async (cwd, args, { timeoutMs = 0 } = {}) => {
|
|
1000
1023
|
try {
|
|
1001
1024
|
const { stdout, stderr } = await execFileAsync(getGitBinary(), args, {
|
|
1002
1025
|
cwd,
|
|
1003
1026
|
env: await buildGitEnv(),
|
|
1004
1027
|
windowsHide: true,
|
|
1005
1028
|
maxBuffer: 20 * 1024 * 1024,
|
|
1029
|
+
// Only short probes pass a timeout; commands that legitimately run long
|
|
1030
|
+
// (a fetch into a temporary clone) keep the default of none.
|
|
1031
|
+
...(timeoutMs > 0 ? { timeout: timeoutMs, killSignal: 'SIGKILL' } : {}),
|
|
1006
1032
|
});
|
|
1007
1033
|
return {
|
|
1008
1034
|
success: true,
|
|
@@ -2129,14 +2155,45 @@ const applyUpstreamConfiguration = async (args) => {
|
|
|
2129
2155
|
);
|
|
2130
2156
|
};
|
|
2131
2157
|
|
|
2158
|
+
/**
|
|
2159
|
+
* A repository whose root is the user's home directory or a filesystem root
|
|
2160
|
+
* (`C:\`, `/`) covers the whole disk. Every status read walks Program Files
|
|
2161
|
+
* or the entire home tree, which is minutes of Git work per refresh and, on
|
|
2162
|
+
* Windows, the process pile-ups users report. Such a repository is nearly
|
|
2163
|
+
* always an accidental `git init` in the wrong place, so OpenChamber treats
|
|
2164
|
+
* it as no repository at all. Returns the reason or null for a normal root.
|
|
2165
|
+
*/
|
|
2166
|
+
export const unsupportedRepositoryRootReason = (repoRoot, home = os.homedir()) => {
|
|
2167
|
+
if (typeof repoRoot !== 'string' || !repoRoot.trim()) return null;
|
|
2168
|
+
const resolved = path.resolve(repoRoot.trim());
|
|
2169
|
+
if (path.resolve(path.parse(resolved).root) === resolved) return 'filesystem-root';
|
|
2170
|
+
if (typeof home === 'string' && home.trim() && path.resolve(home.trim()) === resolved) return 'home';
|
|
2171
|
+
return null;
|
|
2172
|
+
};
|
|
2173
|
+
|
|
2174
|
+
const warnedUnsupportedRoots = new Set();
|
|
2175
|
+
|
|
2132
2176
|
export async function isGitRepository(directory) {
|
|
2133
2177
|
const directoryPath = normalizeDirectoryPath(directory);
|
|
2134
2178
|
if (!directoryPath || !fs.existsSync(directoryPath)) {
|
|
2135
2179
|
return false;
|
|
2136
2180
|
}
|
|
2137
2181
|
|
|
2138
|
-
const result = await runGitCommand(directoryPath, ['rev-parse', '--git-dir']);
|
|
2139
|
-
|
|
2182
|
+
const result = await runGitCommand(directoryPath, ['rev-parse', '--git-dir'], { timeoutMs: GIT_PROBE_TIMEOUT_MS });
|
|
2183
|
+
if (!result.success) return false;
|
|
2184
|
+
|
|
2185
|
+
// `--show-toplevel` has no answer inside a bare repository or a .git
|
|
2186
|
+
// directory; those keep the previous answer rather than being rejected.
|
|
2187
|
+
const topLevel = await runGitCommand(directoryPath, ['rev-parse', '--show-toplevel'], { timeoutMs: GIT_PROBE_TIMEOUT_MS });
|
|
2188
|
+
if (!topLevel.success) return true;
|
|
2189
|
+
const repoRoot = topLevel.stdout.trim();
|
|
2190
|
+
const reason = unsupportedRepositoryRootReason(repoRoot);
|
|
2191
|
+
if (!reason) return true;
|
|
2192
|
+
if (!warnedUnsupportedRoots.has(repoRoot)) {
|
|
2193
|
+
warnedUnsupportedRoots.add(repoRoot);
|
|
2194
|
+
console.warn(`[git] Ignoring repository rooted at ${repoRoot} (${reason}): Git features are disabled for ${directoryPath}`);
|
|
2195
|
+
}
|
|
2196
|
+
return false;
|
|
2140
2197
|
}
|
|
2141
2198
|
|
|
2142
2199
|
export async function getGlobalIdentity() {
|
|
@@ -2258,13 +2315,193 @@ export async function setLocalIdentity(directory, profile) {
|
|
|
2258
2315
|
}
|
|
2259
2316
|
}
|
|
2260
2317
|
|
|
2318
|
+
// Beyond this many untracked files, a directory stays one `dir/` entry in
|
|
2319
|
+
// status. Every file would otherwise become a row, a diff request, and a stat
|
|
2320
|
+
// on the server, and the only directories that large are ones that belong in
|
|
2321
|
+
// .gitignore.
|
|
2322
|
+
const UNTRACKED_DIRECTORY_EXPANSION_LIMIT = 1000;
|
|
2323
|
+
|
|
2324
|
+
// A status read holds one of MAX_CONCURRENT_STATUS_READS slots until it
|
|
2325
|
+
// finishes. Git never gets a terminal here, but a process can still hang on
|
|
2326
|
+
// Windows (a locked index, a stuck filesystem monitor, an unreachable network
|
|
2327
|
+
// drive), and a hung process would hold its slot forever: four of them and no
|
|
2328
|
+
// status read runs again until someone kills them by hand. Every process the
|
|
2329
|
+
// read spawns is therefore killed when it stops producing output for this long,
|
|
2330
|
+
// and the read fails instead of wedging the limiter. Two minutes is far above
|
|
2331
|
+
// what a healthy read spends silent, even on a very large tree.
|
|
2332
|
+
const GIT_STATUS_STALL_TIMEOUT_MS = 120_000;
|
|
2333
|
+
const GIT_UNTRACKED_LISTING_STALL_TIMEOUT_MS = 60_000;
|
|
2334
|
+
const GIT_PROBE_TIMEOUT_MS = 30_000;
|
|
2335
|
+
|
|
2336
|
+
// Untracked files under `dirPath` (repository-relative, trailing slash), read
|
|
2337
|
+
// Git for Windows runs commands through a launcher: the `git.exe` we spawn is a
|
|
2338
|
+
// wrapper whose child is the real `git`. Killing only the wrapper leaves that
|
|
2339
|
+
// child alive, still walking the tree on its own (a repository rooted at a
|
|
2340
|
+
// drive root sends it through Program Files), and it shows up in Task Manager
|
|
2341
|
+
// as a stuck pair until someone ends it by hand. Windows has no process groups
|
|
2342
|
+
// to signal, so the tree is ended through taskkill.
|
|
2343
|
+
const killProcessTree = (child) => {
|
|
2344
|
+
if (!child.pid) return;
|
|
2345
|
+
if (process.platform === 'win32') {
|
|
2346
|
+
try {
|
|
2347
|
+
spawn('taskkill', ['/pid', String(child.pid), '/T', '/F'], { windowsHide: true, stdio: 'ignore' }).on('error', () => {});
|
|
2348
|
+
} catch {
|
|
2349
|
+
child.kill('SIGKILL');
|
|
2350
|
+
}
|
|
2351
|
+
return;
|
|
2352
|
+
}
|
|
2353
|
+
child.kill('SIGKILL');
|
|
2354
|
+
};
|
|
2355
|
+
|
|
2356
|
+
// from a streamed `ls-files` that is stopped once the bound is exceeded so a
|
|
2357
|
+
// huge directory is never listed in full. `paths` is complete when
|
|
2358
|
+
// `truncated` is false.
|
|
2359
|
+
const listUntrackedFilesBounded = async (repoRoot, dirPath, limit) => {
|
|
2360
|
+
const env = await buildGitEnv();
|
|
2361
|
+
return new Promise((resolve, reject) => {
|
|
2362
|
+
const child = spawn(getGitBinary(), ['ls-files', '--others', '--exclude-standard', '-z', '--', dirPath], {
|
|
2363
|
+
cwd: repoRoot,
|
|
2364
|
+
env,
|
|
2365
|
+
windowsHide: true,
|
|
2366
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
2367
|
+
});
|
|
2368
|
+
const paths = [];
|
|
2369
|
+
let pending = '';
|
|
2370
|
+
let truncated = false;
|
|
2371
|
+
let settled = false;
|
|
2372
|
+
let stallTimer = null;
|
|
2373
|
+
const finish = (error) => {
|
|
2374
|
+
if (settled) return;
|
|
2375
|
+
settled = true;
|
|
2376
|
+
if (stallTimer) clearTimeout(stallTimer);
|
|
2377
|
+
if (error) {
|
|
2378
|
+
reject(error);
|
|
2379
|
+
return;
|
|
2380
|
+
}
|
|
2381
|
+
resolve({ paths, truncated });
|
|
2382
|
+
};
|
|
2383
|
+
// A listing that goes silent is killed rather than left holding the
|
|
2384
|
+
// status read (and its limiter slot) open.
|
|
2385
|
+
const armStallTimer = () => {
|
|
2386
|
+
if (stallTimer) clearTimeout(stallTimer);
|
|
2387
|
+
stallTimer = setTimeout(() => {
|
|
2388
|
+
killProcessTree(child);
|
|
2389
|
+
finish(new Error(`git ls-files produced no output for ${GIT_UNTRACKED_LISTING_STALL_TIMEOUT_MS}ms in ${dirPath}`));
|
|
2390
|
+
}, GIT_UNTRACKED_LISTING_STALL_TIMEOUT_MS);
|
|
2391
|
+
};
|
|
2392
|
+
armStallTimer();
|
|
2393
|
+
child.stdout.on('data', (chunk) => {
|
|
2394
|
+
armStallTimer();
|
|
2395
|
+
if (truncated) return;
|
|
2396
|
+
pending += chunk.toString('utf8');
|
|
2397
|
+
const records = pending.split('\0');
|
|
2398
|
+
pending = records.pop() ?? '';
|
|
2399
|
+
for (const record of records) {
|
|
2400
|
+
if (!record) continue;
|
|
2401
|
+
paths.push(record);
|
|
2402
|
+
if (paths.length > limit) {
|
|
2403
|
+
truncated = true;
|
|
2404
|
+
killProcessTree(child);
|
|
2405
|
+
finish();
|
|
2406
|
+
return;
|
|
2407
|
+
}
|
|
2408
|
+
}
|
|
2409
|
+
});
|
|
2410
|
+
child.on('error', (error) => finish(error));
|
|
2411
|
+
child.on('close', (code) => {
|
|
2412
|
+
if (truncated) {
|
|
2413
|
+
finish();
|
|
2414
|
+
return;
|
|
2415
|
+
}
|
|
2416
|
+
if (code !== 0) {
|
|
2417
|
+
finish(new Error(`git ls-files exited with code ${code} for ${dirPath}`));
|
|
2418
|
+
return;
|
|
2419
|
+
}
|
|
2420
|
+
if (pending) paths.push(pending);
|
|
2421
|
+
finish();
|
|
2422
|
+
});
|
|
2423
|
+
});
|
|
2424
|
+
};
|
|
2425
|
+
|
|
2426
|
+
// Replaces each untracked `dir/` entry from `-unormal` with one entry per file
|
|
2427
|
+
// inside it, the listing `-uall` would have produced, unless the directory
|
|
2428
|
+
// holds more than the bound; then the `dir/` entry stays. A nested repository
|
|
2429
|
+
// lists as itself and stays a `dir/` entry too, which is what the diff routes
|
|
2430
|
+
// expect. A listing failure keeps the `dir/` entry rather than dropping the
|
|
2431
|
+
// change from the status.
|
|
2432
|
+
const expandUntrackedDirectories = async (repoRoot, files) => {
|
|
2433
|
+
const expanded = [];
|
|
2434
|
+
for (const file of files) {
|
|
2435
|
+
const isUntrackedDirectory = file.path.endsWith('/')
|
|
2436
|
+
&& (file.working_dir || '').trim() === '?'
|
|
2437
|
+
&& (file.index || '').trim() === '?';
|
|
2438
|
+
if (!isUntrackedDirectory) {
|
|
2439
|
+
expanded.push(file);
|
|
2440
|
+
continue;
|
|
2441
|
+
}
|
|
2442
|
+
const listing = await listUntrackedFilesBounded(repoRoot, file.path, UNTRACKED_DIRECTORY_EXPANSION_LIMIT)
|
|
2443
|
+
.catch((error) => {
|
|
2444
|
+
console.warn(`[GitService] Could not expand untracked directory ${file.path}:`, error?.message || error);
|
|
2445
|
+
return null;
|
|
2446
|
+
});
|
|
2447
|
+
if (!listing || listing.truncated || listing.paths.some((entry) => entry === file.path)) {
|
|
2448
|
+
expanded.push(file);
|
|
2449
|
+
continue;
|
|
2450
|
+
}
|
|
2451
|
+
for (const entryPath of listing.paths) {
|
|
2452
|
+
expanded.push({ ...file, path: entryPath });
|
|
2453
|
+
}
|
|
2454
|
+
}
|
|
2455
|
+
return expanded;
|
|
2456
|
+
};
|
|
2457
|
+
|
|
2458
|
+
// A status read walks the working tree and runs a dozen Git processes; on a
|
|
2459
|
+
// large repository it takes seconds. Clients ask for it after every completed
|
|
2460
|
+
// agent tool call, from several surfaces, and from PR polling, so without a
|
|
2461
|
+
// bound one slow repository ends up with many identical `git status` processes
|
|
2462
|
+
// side by side. Runs are serialized per directory and capped across
|
|
2463
|
+
// directories; a caller that asks during a run gets a run started after it
|
|
2464
|
+
// asked, so results are never older than the request.
|
|
2465
|
+
const MAX_CONCURRENT_STATUS_READS = 4;
|
|
2466
|
+
const statusRefresh = createSerialRefresh({ maxConcurrent: MAX_CONCURRENT_STATUS_READS });
|
|
2467
|
+
|
|
2261
2468
|
export async function getStatus(directory, options = {}) {
|
|
2262
|
-
const lightMode = options.mode === 'light';
|
|
2263
2469
|
const normalizedDirectory = normalizeDirectoryPath(directory);
|
|
2264
2470
|
if (typeof normalizedDirectory !== 'string' || !normalizedDirectory.trim()) {
|
|
2265
2471
|
throw new Error('directory is required');
|
|
2266
2472
|
}
|
|
2473
|
+
const lightMode = options.mode === 'light';
|
|
2474
|
+
// A full read satisfies light callers too, so one run serves whichever
|
|
2475
|
+
// callers it answers, at the widest mode any of them asked for.
|
|
2476
|
+
return statusRefresh.run(
|
|
2477
|
+
normalizedDirectory,
|
|
2478
|
+
{ lightMode },
|
|
2479
|
+
(requests) => readStatus(normalizedDirectory, requests.every((request) => request.lightMode)),
|
|
2480
|
+
);
|
|
2481
|
+
}
|
|
2482
|
+
|
|
2483
|
+
/**
|
|
2484
|
+
* Upstream of the checked-out branch as `remote/branch`, or `null` when HEAD
|
|
2485
|
+
* is detached, unborn, or the branch has no upstream configured. Reads refs
|
|
2486
|
+
* and config only, never the working tree: callers that only need the
|
|
2487
|
+
* tracking name must not pay for a status read.
|
|
2488
|
+
*/
|
|
2489
|
+
export async function getTrackingBranch(directory) {
|
|
2490
|
+
const normalizedDirectory = normalizeDirectoryPath(directory);
|
|
2491
|
+
if (!normalizedDirectory) {
|
|
2492
|
+
return null;
|
|
2493
|
+
}
|
|
2494
|
+
const head = await runGitCommand(normalizedDirectory, ['symbolic-ref', '--quiet', 'HEAD']);
|
|
2495
|
+
const headRef = head.success ? head.stdout.trim() : '';
|
|
2496
|
+
if (!headRef.startsWith('refs/heads/')) {
|
|
2497
|
+
return null;
|
|
2498
|
+
}
|
|
2499
|
+
const upstream = await runGitCommand(normalizedDirectory, ['for-each-ref', '--format=%(upstream:short)', headRef]);
|
|
2500
|
+
const tracking = upstream.success ? upstream.stdout.trim() : '';
|
|
2501
|
+
return tracking || null;
|
|
2502
|
+
}
|
|
2267
2503
|
|
|
2504
|
+
async function readStatus(normalizedDirectory, lightMode) {
|
|
2268
2505
|
try {
|
|
2269
2506
|
// Prefer an explicit non-repo check before simple-git status so a missing
|
|
2270
2507
|
// repository never depends on process.cwd() or an opaque GitError shape.
|
|
@@ -2272,12 +2509,22 @@ export async function getStatus(directory, options = {}) {
|
|
|
2272
2509
|
throw new Error('fatal: not a git repository (or any of the parent directories): .git');
|
|
2273
2510
|
}
|
|
2274
2511
|
|
|
2275
|
-
const { directoryPath, repoRoot, git } = await createRepositoryGitContext(normalizedDirectory
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
const status = await git.status(['-uall']);
|
|
2512
|
+
const { directoryPath, repoRoot, git } = await createRepositoryGitContext(normalizedDirectory, {
|
|
2513
|
+
stallTimeoutMs: GIT_STATUS_STALL_TIMEOUT_MS,
|
|
2514
|
+
});
|
|
2279
2515
|
|
|
2280
|
-
//
|
|
2516
|
+
// `-unormal` lists a directory with no tracked files as one `dir/` entry
|
|
2517
|
+
// and stops walking it at its first file. `-uall` would walk every file
|
|
2518
|
+
// in it: on a forgotten build or dependency directory that is a scan of
|
|
2519
|
+
// tens of thousands of files and hundreds of megabytes per status read.
|
|
2520
|
+
// Directories are expanded to their files afterwards, up to a bound.
|
|
2521
|
+
const status = await git.status(['-unormal']);
|
|
2522
|
+
status.files = await expandUntrackedDirectories(repoRoot, status.files);
|
|
2523
|
+
|
|
2524
|
+
// Light mode: skip numstat + new-file line counting for faster response.
|
|
2525
|
+
// Staged (`--cached`: HEAD -> index) and working (`--numstat`: index -> worktree)
|
|
2526
|
+
// stay in separate maps. A partially staged file has an entry in both, and the
|
|
2527
|
+
// UI shows each row's own scope instead of a combined total.
|
|
2281
2528
|
const [stagedStatsRaw, workingStatsRaw] = lightMode
|
|
2282
2529
|
? ['', '']
|
|
2283
2530
|
: await Promise.all([
|
|
@@ -2285,9 +2532,10 @@ export async function getStatus(directory, options = {}) {
|
|
|
2285
2532
|
git.raw(['diff', '--numstat']).catch(() => ''),
|
|
2286
2533
|
]);
|
|
2287
2534
|
|
|
2288
|
-
const
|
|
2535
|
+
const stagedDiffStats = {};
|
|
2536
|
+
const workingDiffStats = {};
|
|
2289
2537
|
|
|
2290
|
-
const accumulateStats = (raw) => {
|
|
2538
|
+
const accumulateStats = (raw, target) => {
|
|
2291
2539
|
if (!raw) return;
|
|
2292
2540
|
raw
|
|
2293
2541
|
.split('\n')
|
|
@@ -2306,18 +2554,18 @@ export async function getStatus(directory, options = {}) {
|
|
|
2306
2554
|
const insertions = insertionsRaw === '-' ? 0 : parseInt(insertionsRaw, 10) || 0;
|
|
2307
2555
|
const deletions = deletionsRaw === '-' ? 0 : parseInt(deletionsRaw, 10) || 0;
|
|
2308
2556
|
|
|
2309
|
-
const existing =
|
|
2310
|
-
|
|
2557
|
+
const existing = target[path] || { insertions: 0, deletions: 0 };
|
|
2558
|
+
target[path] = {
|
|
2311
2559
|
insertions: existing.insertions + insertions,
|
|
2312
2560
|
deletions: existing.deletions + deletions,
|
|
2313
|
-
}
|
|
2561
|
+
};
|
|
2314
2562
|
});
|
|
2315
2563
|
};
|
|
2316
2564
|
|
|
2317
|
-
accumulateStats(stagedStatsRaw);
|
|
2318
|
-
accumulateStats(workingStatsRaw);
|
|
2565
|
+
accumulateStats(stagedStatsRaw, stagedDiffStats);
|
|
2566
|
+
accumulateStats(workingStatsRaw, workingDiffStats);
|
|
2319
2567
|
|
|
2320
|
-
const diffStats =
|
|
2568
|
+
const diffStats = { staged: stagedDiffStats, working: workingDiffStats };
|
|
2321
2569
|
|
|
2322
2570
|
const MAX_NEW_FILE_STATS = 200;
|
|
2323
2571
|
const MAX_NEW_FILE_STAT_SIZE = 1024 * 1024;
|
|
@@ -2337,7 +2585,10 @@ export async function getStatus(directory, options = {}) {
|
|
|
2337
2585
|
continue;
|
|
2338
2586
|
}
|
|
2339
2587
|
|
|
2340
|
-
|
|
2588
|
+
// Untracked and working-tree-added files belong to the working scope;
|
|
2589
|
+
// a file whose 'A' code is on the index belongs to the staged scope.
|
|
2590
|
+
const target = working === '?' || working === 'A' ? workingDiffStats : stagedDiffStats;
|
|
2591
|
+
const existing = target[file.path];
|
|
2341
2592
|
if (existing && existing.insertions > 0) {
|
|
2342
2593
|
continue;
|
|
2343
2594
|
}
|
|
@@ -2353,6 +2604,7 @@ export async function getStatus(directory, options = {}) {
|
|
|
2353
2604
|
const buffer = await fsp.readFile(absolutePath);
|
|
2354
2605
|
if (buffer.indexOf(0) !== -1) {
|
|
2355
2606
|
newFileStats.push({
|
|
2607
|
+
target,
|
|
2356
2608
|
path: file.path,
|
|
2357
2609
|
insertions: existing?.insertions ?? 0,
|
|
2358
2610
|
deletions: existing?.deletions ?? 0,
|
|
@@ -2363,6 +2615,7 @@ export async function getStatus(directory, options = {}) {
|
|
|
2363
2615
|
const normalized = buffer.toString('utf8').replace(/\r\n/g, '\n');
|
|
2364
2616
|
if (!normalized.length) {
|
|
2365
2617
|
newFileStats.push({
|
|
2618
|
+
target,
|
|
2366
2619
|
path: file.path,
|
|
2367
2620
|
insertions: 0,
|
|
2368
2621
|
deletions: 0,
|
|
@@ -2377,6 +2630,7 @@ export async function getStatus(directory, options = {}) {
|
|
|
2377
2630
|
|
|
2378
2631
|
const lineCount = segments.length;
|
|
2379
2632
|
newFileStats.push({
|
|
2633
|
+
target,
|
|
2380
2634
|
path: file.path,
|
|
2381
2635
|
insertions: lineCount,
|
|
2382
2636
|
deletions: 0,
|
|
@@ -2390,7 +2644,7 @@ export async function getStatus(directory, options = {}) {
|
|
|
2390
2644
|
}
|
|
2391
2645
|
|
|
2392
2646
|
for (const entry of newFileStats) {
|
|
2393
|
-
|
|
2647
|
+
entry.target[entry.path] = {
|
|
2394
2648
|
insertions: entry.insertions,
|
|
2395
2649
|
deletions: entry.deletions,
|
|
2396
2650
|
};
|
|
@@ -3450,26 +3704,45 @@ export async function push(directory, options = {}) {
|
|
|
3450
3704
|
);
|
|
3451
3705
|
};
|
|
3452
3706
|
|
|
3453
|
-
const
|
|
3707
|
+
const remote = String(options.remote || '').trim();
|
|
3708
|
+
const status = await git.status();
|
|
3709
|
+
const config = await git.listConfig();
|
|
3710
|
+
const remotes = await git.getRemotes(true);
|
|
3711
|
+
const remoteName = remote
|
|
3712
|
+
|| config.all[`branch.${status.current}.pushremote`]
|
|
3713
|
+
|| config.all['remote.pushdefault']
|
|
3714
|
+
|| config.all[`branch.${status.current}.remote`]
|
|
3715
|
+
|| (remotes.length === 1 ? remotes[0].name : 'origin');
|
|
3716
|
+
|
|
3717
|
+
const pushTo = async (target, branch, pushOptions) => {
|
|
3718
|
+
// simple-git drops forced updates and puts no-ops in `pushed`. Read Git's
|
|
3719
|
+
// porcelain status flags so feedback reflects actual remote ref changes.
|
|
3720
|
+
let output = '';
|
|
3721
|
+
git.outputHandler((_command, stdout) => {
|
|
3722
|
+
stdout.on('data', (chunk) => { output += chunk.toString(); });
|
|
3723
|
+
});
|
|
3724
|
+
const result = await git.push(target, branch, pushOptions);
|
|
3725
|
+
const pushed = [];
|
|
3726
|
+
for (const line of output.split(/\r?\n/)) {
|
|
3727
|
+
const match = /^([ *+\-])\t([^:]*):([^\t]+)\t/.exec(line);
|
|
3728
|
+
if (match) {
|
|
3729
|
+
pushed.push({ local: match[2], remote: remoteName });
|
|
3730
|
+
}
|
|
3731
|
+
}
|
|
3454
3732
|
return {
|
|
3455
3733
|
success: true,
|
|
3456
|
-
pushed
|
|
3457
|
-
repo: result.repo,
|
|
3458
|
-
ref: result.ref,
|
|
3734
|
+
pushed,
|
|
3735
|
+
repo: result.repo || directory,
|
|
3736
|
+
ref: result.ref || null,
|
|
3459
3737
|
};
|
|
3460
3738
|
};
|
|
3461
3739
|
|
|
3462
|
-
const remote = String(options.remote || '').trim();
|
|
3463
|
-
|
|
3464
3740
|
if (!remote && !options.branch) {
|
|
3465
3741
|
try {
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
repo: directory,
|
|
3471
|
-
ref: null,
|
|
3472
|
-
};
|
|
3742
|
+
const pushOptions = status.current && !status.tracking
|
|
3743
|
+
? buildUpstreamOptions(options.options)
|
|
3744
|
+
: options.options || {};
|
|
3745
|
+
return await pushTo(undefined, undefined, pushOptions);
|
|
3473
3746
|
} catch (error) {
|
|
3474
3747
|
if (!looksLikeMissingUpstream(error)) {
|
|
3475
3748
|
const message = describePushError(error);
|
|
@@ -3478,17 +3751,13 @@ export async function push(directory, options = {}) {
|
|
|
3478
3751
|
}
|
|
3479
3752
|
|
|
3480
3753
|
try {
|
|
3481
|
-
const status = await git.status();
|
|
3482
3754
|
const branch = status.current;
|
|
3483
|
-
|
|
3484
|
-
const fallbackRemote = remotes.find((entry) => entry.name === 'origin')?.name || remotes[0]?.name;
|
|
3485
|
-
if (!branch || !fallbackRemote) {
|
|
3755
|
+
if (!branch || !remoteName) {
|
|
3486
3756
|
const message = describePushError(error);
|
|
3487
3757
|
throw new Error(message);
|
|
3488
3758
|
}
|
|
3489
3759
|
|
|
3490
|
-
|
|
3491
|
-
return normalizePushResult(result);
|
|
3760
|
+
return await pushTo(remoteName, branch, buildUpstreamOptions(options.options));
|
|
3492
3761
|
} catch (fallbackError) {
|
|
3493
3762
|
const message = describePushError(fallbackError);
|
|
3494
3763
|
console.error('Failed to push (including upstream fallback):', fallbackError);
|
|
@@ -3497,26 +3766,14 @@ export async function push(directory, options = {}) {
|
|
|
3497
3766
|
}
|
|
3498
3767
|
}
|
|
3499
3768
|
|
|
3500
|
-
const remoteName = remote || 'origin';
|
|
3501
|
-
|
|
3502
3769
|
// If caller didn't specify a branch, this is the common "Push"/"Commit & Push" path.
|
|
3503
3770
|
// When there's no upstream yet (typical for freshly-created worktree branches), publish it on first push.
|
|
3504
|
-
if (!options.branch) {
|
|
3505
|
-
|
|
3506
|
-
const status = await git.status();
|
|
3507
|
-
if (status.current && !status.tracking) {
|
|
3508
|
-
const result = await git.push(remoteName, status.current, buildUpstreamOptions(options.options));
|
|
3509
|
-
return normalizePushResult(result);
|
|
3510
|
-
}
|
|
3511
|
-
} catch (error) {
|
|
3512
|
-
// If we can't read status, fall back to the regular push path below.
|
|
3513
|
-
console.warn('Failed to read git status before push:', error);
|
|
3514
|
-
}
|
|
3771
|
+
if (!options.branch && status.current && !status.tracking) {
|
|
3772
|
+
return pushTo(remoteName, status.current, buildUpstreamOptions(options.options));
|
|
3515
3773
|
}
|
|
3516
3774
|
|
|
3517
3775
|
try {
|
|
3518
|
-
|
|
3519
|
-
return normalizePushResult(result);
|
|
3776
|
+
return await pushTo(remoteName, options.branch, options.options || {});
|
|
3520
3777
|
} catch (error) {
|
|
3521
3778
|
// Last-resort fallback: retry with upstream if the error suggests it's missing.
|
|
3522
3779
|
if (!looksLikeMissingUpstream(error)) {
|
|
@@ -3526,15 +3783,13 @@ export async function push(directory, options = {}) {
|
|
|
3526
3783
|
}
|
|
3527
3784
|
|
|
3528
3785
|
try {
|
|
3529
|
-
const status = await git.status();
|
|
3530
3786
|
const branch = options.branch || status.current;
|
|
3531
3787
|
if (!branch) {
|
|
3532
3788
|
console.error('Failed to push: missing branch name for upstream setup:', error);
|
|
3533
3789
|
throw error;
|
|
3534
3790
|
}
|
|
3535
3791
|
|
|
3536
|
-
|
|
3537
|
-
return normalizePushResult(result);
|
|
3792
|
+
return await pushTo(remoteName, branch, buildUpstreamOptions(options.options));
|
|
3538
3793
|
} catch (fallbackError) {
|
|
3539
3794
|
const message = describePushError(fallbackError);
|
|
3540
3795
|
console.error('Failed to push (including upstream fallback):', fallbackError);
|
|
@@ -5161,7 +5416,7 @@ export async function canonicalizeWorktreeState(directory) {
|
|
|
5161
5416
|
|
|
5162
5417
|
// Detect attention reasons from getStatus side-effects
|
|
5163
5418
|
try {
|
|
5164
|
-
const status = await git.status(['-
|
|
5419
|
+
const status = await git.status(['-unormal']);
|
|
5165
5420
|
if (status.current && (await git.raw(['rev-parse', '--verify', 'MERGE_HEAD']).then(() => true).catch(() => false))) {
|
|
5166
5421
|
attentionReason = 'merge';
|
|
5167
5422
|
} else {
|