@openchamber/web 1.23.2 → 1.24.1
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 +7 -6
- package/bin/lib/cli-http.js +5 -1
- package/dist/assets/{CodeMirrorCommentWidgets-DdNGwbBw.js → CodeMirrorCommentWidgets-DvUH815P.js} +1 -1
- package/dist/assets/DiffView-DkC3xlRJ.js +4 -0
- package/dist/assets/FilesView-D0bM9FVB.js +13 -0
- package/dist/assets/GitView-Bxuv3dfP.js +6 -0
- package/dist/assets/GuestAttachDialog-B0u3Q5uO.js +1 -0
- package/dist/assets/{JsonTreeView-Chzx5Y6N.js → JsonTreeView-BBVPFM5K.js} +1 -1
- package/dist/assets/LinearIssuesView-UI1FcSC8.js +1 -0
- package/dist/assets/{MarkdownImageGallery-CugnrZ6f.js → MarkdownImageGallery-CUJxH8Le.js} +1 -1
- package/dist/assets/MarkdownRendererImpl-D5BZOg8X.js +12 -0
- package/dist/assets/{OnboardingScreen-hH9xcTjA.js → OnboardingScreen-5Gou9cGD.js} +1 -1
- package/dist/assets/{PatchDiff-DRgNYc9l.js → PatchDiff-C4rE5k6z.js} +1 -1
- package/dist/assets/{PierreDiffViewer-ZT2CKuzJ.js → PierreDiffViewer-ByRVu6ss.js} +5 -5
- package/dist/assets/PlanView-u2yi5XGJ.js +5 -0
- package/dist/assets/PluginPane-QxjsKYeO.js +3 -0
- package/dist/assets/SettingsView-Fo5ZqMaT.js +29 -0
- package/dist/assets/{SettingsWindow-DisOghhD.js → SettingsWindow-HVDVANjJ.js} +1 -1
- package/dist/assets/SubmoduleDiffSummary-D3hzkybB.js +1 -0
- package/dist/assets/ToolOutputDialog-3J6IRayW.js +15 -0
- package/dist/assets/{ToolPartDiffPreview-oWxWCu-4.js → ToolPartDiffPreview-DarxPjSd.js} +2 -2
- package/dist/assets/{VirtualizedFileDiff-CiyrAq_I.js → VirtualizedFileDiff-CZgXWHjU.js} +4 -4
- package/dist/assets/{WalkthroughView-CKTevaea.js → WalkthroughView-wSpED5L4.js} +2 -2
- package/dist/assets/appThemeRegistry-Cf8KitzT.js +1 -0
- package/dist/assets/commitAndPush-DZnzlhvc.js +1 -0
- package/dist/assets/{computeVirtualFileMetrics-SUWoTyPe.js → computeVirtualFileMetrics-VYnT_A2h.js} +1 -1
- package/dist/assets/de-BM_8EDD3.js +10 -0
- package/dist/assets/es-CxZjlqpo.js +16 -0
- package/dist/assets/fr-VCixCnMW.js +14 -0
- package/dist/assets/{index-C4jJ3Ur5.js → index-3U4CtS9b.js} +1 -1
- package/dist/assets/index-B9Hvzjwl.css +1 -0
- package/dist/assets/index-DLHQogv8.js +40 -0
- package/dist/assets/{isDiffPlainText-DfG0cZxr.js → isDiffPlainText-ImDG3Uhg.js} +1 -1
- package/dist/assets/{isFilePlainText-CyNivOCU.js → isFilePlainText-D_YDVYDb.js} +1 -1
- package/dist/assets/ja-CZ5k_GyD.js +16 -0
- package/dist/assets/ko-7YM3A1Xh.js +16 -0
- package/dist/assets/{main-B8cGozKr.js → main-CycplCph.js} +2 -2
- package/dist/assets/main-DFYTCx5o.js +896 -0
- package/dist/assets/{markdown-shiki.worker-D5fBU-lw.js → markdown-shiki.worker-CahLvHIq.js} +5 -5
- package/dist/assets/markdownCore-DHvqMxPn.js +5 -0
- package/dist/assets/{miniChat-Cay99IxR.js → miniChat-DIQKfY2V.js} +2 -2
- package/dist/assets/{mobile-Zfhix7nz.js → mobile-BMwz5q-m.js} +2 -2
- package/dist/assets/{patchFileDiff-CJ5AN9Ql.js → patchFileDiff-DDQ6Rq5e.js} +3 -3
- package/dist/assets/pl-BcgDO_w5.js +16 -0
- package/dist/assets/{pt-BR-CLosVawq.js → pt-BR-CU2u_1q5.js} +4 -4
- package/dist/assets/renderElectronMiniChatApp-3_d6g6CU.js +2 -0
- package/dist/assets/renderMobileApp-D0Y8DtkA.js +25 -0
- package/dist/assets/runtimeEndpointReset-DhC3REb2.js +25 -0
- package/dist/assets/{scheduledTasksApi-CGFV4Pap.js → scheduledTasksApi-D8pq6gQz.js} +1 -1
- package/dist/assets/shikiHighlight-1imXsir9.js +1 -0
- package/dist/assets/textMateThemeFromAppTheme-Dgqc63LZ.js +1 -0
- package/dist/assets/tr-DuYhOzNe.js +7 -0
- package/dist/assets/uk-Cuk7-uvq.js +16 -0
- package/dist/assets/useAppFontEffects-BItUWdo4.js +7333 -0
- package/dist/assets/useInlineCommentController-CkbKsm7m.js +2 -0
- package/dist/assets/useRootScrollLock-vmzxZjWA.js +2 -0
- package/dist/assets/{vendor-base-ui-BY_5qla_.js → vendor-base-ui-CsXYnR5c.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-ES33GhKK.js → vendor-codemirror-language-data-BDyxuqK4.js} +2 -2
- package/dist/assets/vendor-framer-motion-Bq3iTZ6r.js +1 -0
- package/dist/assets/{vendor-motion-dom-D_o3BTI3.js → vendor-motion-dom-DcCgeG69.js} +1 -1
- package/dist/assets/vendor-strip-json-comments-5dJlOkP1.js +4 -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-B6551dwG.js → vendor-zod-fZppILAM.js} +4 -4
- package/dist/assets/{web-components-CJZwV5BE.js → web-components-D7FinaeH.js} +2 -2
- package/dist/assets/zh-CN-CUWoiRHd.js +16 -0
- package/dist/assets/zh-TW-CQ8EBSBN.js +16 -0
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +4 -4
- package/dist/mobile.html +4 -4
- package/package.json +9 -6
- package/server/built-in-extensions/registry.json +4 -0
- package/server/index.d.ts +2 -0
- package/server/index.js +41 -10
- 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 +8 -0
- package/server/lib/fs/git-process.test.js +77 -0
- package/server/lib/fs/routes.js +2 -1
- package/server/lib/fs/search.js +2 -1
- package/server/lib/git/DOCUMENTATION.md +19 -4
- package/server/lib/git/routes.js +16 -3
- 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 +336 -62
- package/server/lib/git/service.test.js +400 -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 +68 -0
- package/server/lib/guests/auth-store.js +184 -0
- package/server/lib/guests/auth-store.test.js +112 -0
- package/server/lib/guests/background.test.js +83 -0
- package/server/lib/guests/builtins.js +34 -0
- package/server/lib/guests/builtins.test.js +174 -0
- package/server/lib/guests/catalog.js +477 -0
- package/server/lib/guests/catalog.test.js +390 -0
- package/server/lib/guests/clone.js +297 -0
- package/server/lib/guests/extract-zip.js +136 -0
- package/server/lib/guests/extract-zip.test.js +109 -0
- package/server/lib/guests/files.js +308 -0
- package/server/lib/guests/files.test.js +262 -0
- package/server/lib/guests/grant-scope.js +81 -0
- package/server/lib/guests/grant-scope.test.js +75 -0
- package/server/lib/guests/host-session.js +73 -0
- package/server/lib/guests/host-session.test.js +30 -0
- package/server/lib/guests/html-styles.js +6 -0
- package/server/lib/guests/html-styles.test.js +45 -0
- package/server/lib/guests/html-tokens.js +73 -0
- package/server/lib/guests/html-tokens.test.js +53 -0
- package/server/lib/guests/install.js +406 -0
- package/server/lib/guests/install.test.js +338 -0
- package/server/lib/guests/oauth.js +501 -0
- package/server/lib/guests/oauth.test.js +481 -0
- package/server/lib/guests/persist.js +336 -0
- package/server/lib/guests/persist.test.js +288 -0
- package/server/lib/guests/request.js +112 -0
- package/server/lib/guests/request.test.js +206 -0
- package/server/lib/guests/routes.js +838 -0
- package/server/lib/guests/service.js +538 -0
- package/server/lib/guests/service.test.js +277 -0
- package/server/lib/guests/sockets.js +129 -0
- package/server/lib/guests/sockets.test.js +110 -0
- package/server/lib/guests/ssh-install.test.js +188 -0
- package/server/lib/guests/storage.js +68 -0
- package/server/lib/guests/storage.test.js +59 -0
- package/server/lib/guests/updates.js +294 -0
- package/server/lib/guests/updates.test.js +334 -0
- package/server/lib/guests/upload.js +50 -0
- package/server/lib/guests/upload.test.js +131 -0
- package/server/lib/linear/DOCUMENTATION.md +1 -1
- package/server/lib/message-queue/DOCUMENTATION.md +6 -0
- package/server/lib/message-queue/runtime.js +5 -0
- package/server/lib/message-queue/runtime.test.js +32 -1
- package/server/lib/openchamber-control/DOCUMENTATION.md +6 -0
- package/server/lib/openchamber-sessions/routes.js +44 -11
- package/server/lib/openchamber-sessions/routes.test.js +47 -0
- package/server/lib/opencode/DOCUMENTATION.md +40 -0
- package/server/lib/opencode/core-routes.js +39 -1
- package/server/lib/opencode/feature-routes-runtime.js +15 -0
- package/server/lib/opencode/lifecycle-process.test.js +84 -0
- package/server/lib/opencode/lifecycle.js +54 -67
- package/server/lib/opencode/settings-helpers.js +3 -0
- package/server/lib/opencode/settings-normalization-runtime.js +2 -0
- package/server/lib/opencode/settings-normalization-runtime.test.js +13 -0
- package/server/lib/opencode/settings-registry.json +12 -0
- package/server/lib/opencode/shutdown-runtime.js +3 -0
- package/server/lib/opencode/shutdown-runtime.test.js +24 -0
- package/server/lib/opencode/theme-archive.js +53 -0
- package/server/lib/opencode/theme-catalog.js +171 -0
- package/server/lib/opencode/theme-catalog.test.js +125 -0
- package/server/lib/opencode/theme-import.test.js +144 -0
- package/server/lib/opencode/theme-runtime.js +100 -28
- package/server/lib/opencode/theme-runtime.test.js +15 -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/quota/DOCUMENTATION.md +0 -1
- package/server/lib/quota/providers/index.js +0 -7
- package/server/lib/routing/DOCUMENTATION.md +81 -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/security/request-security.js +9 -5
- package/server/lib/security/request-security.test.js +37 -0
- package/server/lib/terminal/DOCUMENTATION.md +2 -0
- package/server/lib/terminal/runtime.js +17 -2
- package/server/lib/terminal/runtime.test.js +45 -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 +56 -17
- package/server/lib/ui-auth/ui-auth.test.js +96 -0
- package/dist/assets/DiffView-GYriC0Wk.js +0 -4
- package/dist/assets/DirtyBranchSwitchDialog-Bv0C99hc.js +0 -1
- package/dist/assets/FilesView-2Lin13wx.js +0 -13
- package/dist/assets/GitView-9wKba3UO.js +0 -6
- package/dist/assets/LinearIssuesView-DXS9QJiR.js +0 -1
- package/dist/assets/MarkdownRendererImpl-CaMyct2Q.js +0 -12
- package/dist/assets/PlanView-DiTBm2BD.js +0 -5
- package/dist/assets/SettingsView-CN8VeM99.js +0 -28
- package/dist/assets/ToolOutputDialog-BqiKydxR.js +0 -15
- package/dist/assets/appThemeRegistry-BK0dHKa6.js +0 -1
- package/dist/assets/de-DQWC94VK.js +0 -10
- package/dist/assets/es-DixFUD3m.js +0 -16
- package/dist/assets/fr-D6u8tvfA.js +0 -14
- package/dist/assets/index-BvpFzhLs.js +0 -40
- package/dist/assets/index-n5p3SnES.css +0 -1
- package/dist/assets/ja-4u4pCorB.js +0 -16
- package/dist/assets/ko-C27-LW_b.js +0 -16
- package/dist/assets/main-tEA-fFPg.js +0 -930
- package/dist/assets/markdownCore-kyGrWGsn.js +0 -5
- package/dist/assets/pl-FtCjsNdW.js +0 -16
- package/dist/assets/registerCustomTheme-BBXUCRnG.js +0 -1
- package/dist/assets/renderElectronMiniChatApp-CuHOGlF4.js +0 -2
- package/dist/assets/renderMobileApp-C4X_KUH8.js +0 -25
- package/dist/assets/runtimeEndpointReset-CMg-KUx3.js +0 -41
- package/dist/assets/shikiHighlight-DdKWYWrV.js +0 -1
- package/dist/assets/tr-D2j6wUez.js +0 -7
- package/dist/assets/uk-C6IzmwM_.js +0 -16
- package/dist/assets/useAppFontEffects-DgCHy6Mr.js +0 -7282
- package/dist/assets/useGitComparison-BIaI0WZI.js +0 -1
- package/dist/assets/useInlineCommentController-2wcCtpM3.js +0 -2
- package/dist/assets/useRootScrollLock-CbWA03xR.js +0 -1
- package/dist/assets/vendor-framer-motion-livSKyyV.js +0 -1
- package/dist/assets/zh-CN-Wl6tIDz1.js +0 -16
- package/dist/assets/zh-TW-hgphoWSN.js +0 -16
- package/server/lib/quota/providers/crof.js +0 -96
- package/server/lib/quota/providers/crof.test.js +0 -98
|
@@ -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,6 +350,12 @@ 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
|
|
|
@@ -510,12 +517,46 @@ const resolveGitInternalPath = async (repoRoot, git, gitPath) => {
|
|
|
510
517
|
return path.resolve(repoRoot, resolved.trim());
|
|
511
518
|
};
|
|
512
519
|
|
|
520
|
+
const GITLINK_MODE = '160000';
|
|
521
|
+
|
|
522
|
+
// Paths from `git status` can stop resolving: the file was removed after the
|
|
523
|
+
// listing, or the entry is a nested repository git reports as `dir/`. Callers
|
|
524
|
+
// tell these apart by `code`, and diff routes send the code to clients as is.
|
|
525
|
+
const GIT_PATH_NOT_FOUND = 'path_not_found';
|
|
526
|
+
const GIT_PATH_IS_NESTED_REPOSITORY = 'nested_repository';
|
|
527
|
+
const GIT_PATH_IS_UNTRACKED_DIRECTORY = 'untracked_directory';
|
|
528
|
+
|
|
529
|
+
const GIT_PATH_ERROR_MESSAGES = {
|
|
530
|
+
[GIT_PATH_IS_NESTED_REPOSITORY]: (filePath) => `Path is a separate Git repository: ${filePath}`,
|
|
531
|
+
[GIT_PATH_IS_UNTRACKED_DIRECTORY]: (filePath) => `Path is a directory of untracked files: ${filePath}`,
|
|
532
|
+
[GIT_PATH_NOT_FOUND]: (filePath) => `Path not found in working tree, index, or HEAD: ${filePath}`,
|
|
533
|
+
};
|
|
534
|
+
|
|
535
|
+
const createGitPathError = (code, filePath) => Object.assign(new Error(GIT_PATH_ERROR_MESSAGES[code](filePath)), { code });
|
|
536
|
+
|
|
537
|
+
// Mode of the exact entry at `repoPath`, or null. `cat-file -e` cannot answer
|
|
538
|
+
// this: a gitlink's commit lives in the submodule's object store, so git exits 1
|
|
539
|
+
// without stderr, which simple-git reports as success.
|
|
540
|
+
const readGitEntryMode = async (repoRoot, args, repoPath) => {
|
|
541
|
+
const result = await runGitCommand(repoRoot, args);
|
|
542
|
+
if (!result.success) return null;
|
|
543
|
+
for (const record of result.stdout.split('\0')) {
|
|
544
|
+
const tab = record.indexOf('\t');
|
|
545
|
+
if (tab !== -1 && record.slice(tab + 1) === repoPath) {
|
|
546
|
+
return record.slice(0, record.indexOf(' '));
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
return null;
|
|
550
|
+
};
|
|
551
|
+
|
|
513
552
|
const resolveGitFileContext = async (directoryPath, git, filePath, repoRootOverride = null) => {
|
|
514
553
|
const repoRoot = repoRootOverride || await resolveGitRepositoryRoot(directoryPath, git);
|
|
515
554
|
const candidates = Array.from(new Set([
|
|
516
555
|
path.resolve(repoRoot, filePath),
|
|
517
556
|
path.resolve(directoryPath, filePath),
|
|
518
557
|
]));
|
|
558
|
+
let nestedRepository = false;
|
|
559
|
+
let untrackedDirectory = false;
|
|
519
560
|
|
|
520
561
|
for (const absolutePath of candidates) {
|
|
521
562
|
if (!isInsideOrSameDirectory(repoRoot, absolutePath)) {
|
|
@@ -526,20 +567,68 @@ const resolveGitFileContext = async (directoryPath, git, filePath, repoRootOverr
|
|
|
526
567
|
const worktreeEntry = await fsp.lstat(absolutePath).catch(() => null);
|
|
527
568
|
const isSymbolicLink = worktreeEntry?.isSymbolicLink() ?? false;
|
|
528
569
|
const existsInWorktree = worktreeEntry?.isFile() || isSymbolicLink;
|
|
529
|
-
const
|
|
530
|
-
const
|
|
570
|
+
const indexMode = await readGitEntryMode(repoRoot, ['ls-files', '--stage', '-z', '--', `:(literal)${repoPath}`], repoPath);
|
|
571
|
+
const headMode = await readGitEntryMode(repoRoot, ['ls-tree', '-z', 'HEAD', '--', repoPath], repoPath);
|
|
531
572
|
|
|
532
|
-
if (existsInWorktree ||
|
|
573
|
+
if (existsInWorktree || indexMode || headMode) {
|
|
533
574
|
return {
|
|
534
575
|
absolutePath,
|
|
535
576
|
repoPath,
|
|
536
577
|
repoRoot,
|
|
537
578
|
isSymbolicLink,
|
|
579
|
+
isSubmodule: indexMode === GITLINK_MODE || headMode === GITLINK_MODE,
|
|
538
580
|
};
|
|
539
581
|
}
|
|
582
|
+
|
|
583
|
+
if (worktreeEntry?.isDirectory()) {
|
|
584
|
+
if (await fsp.lstat(path.join(absolutePath, '.git')).then(() => true, () => false)) {
|
|
585
|
+
nestedRepository = true;
|
|
586
|
+
} else {
|
|
587
|
+
// Status lists a directory whose untracked files were not expanded
|
|
588
|
+
// (see readStatus) as `dir/`; there is no single patch for it.
|
|
589
|
+
untrackedDirectory = true;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
540
592
|
}
|
|
541
593
|
|
|
542
|
-
throw
|
|
594
|
+
if (nestedRepository) throw createGitPathError(GIT_PATH_IS_NESTED_REPOSITORY, filePath);
|
|
595
|
+
if (untrackedDirectory) throw createGitPathError(GIT_PATH_IS_UNTRACKED_DIRECTORY, filePath);
|
|
596
|
+
throw createGitPathError(GIT_PATH_NOT_FOUND, filePath);
|
|
597
|
+
};
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* What a submodule entry records, since its text patch cannot show everything:
|
|
601
|
+
* with only untracked files inside, `git status` marks it modified while
|
|
602
|
+
* `git diff` prints nothing.
|
|
603
|
+
*/
|
|
604
|
+
const readSubmoduleState = async (repoRoot, fileContext) => {
|
|
605
|
+
const status = await runGitCommand(repoRoot, ['status', '--porcelain=v2', '-z', '--', `:(literal)${fileContext.repoPath}`]);
|
|
606
|
+
if (!status.success) {
|
|
607
|
+
throw new Error(status.message || 'Failed to read submodule status');
|
|
608
|
+
}
|
|
609
|
+
// Changed: "1 XY S<c><m><u> mH mI mW hH hI path" ("2" adds rename fields
|
|
610
|
+
// after hI). Unmerged: "u XY S<c><m><u> m1 m2 m3 mW h1 h2 h3 path", with no
|
|
611
|
+
// stage-0 index entry. A clean submodule has no record, so HEAD and the index
|
|
612
|
+
// record the same commit.
|
|
613
|
+
const record = status.stdout.split('\0').find((entry) => /^[12u] /.test(entry))?.split(' ');
|
|
614
|
+
const hasConflict = record?.[0] === 'u';
|
|
615
|
+
const readHead = async () => (await runGitCommand(repoRoot, ['rev-parse', '--verify', '--quiet', `HEAD:${fileContext.repoPath}`])).stdout.trim();
|
|
616
|
+
const head = record && !hasConflict ? record[6] : await readHead();
|
|
617
|
+
const index = hasConflict ? '' : (record ? record[7] : head);
|
|
618
|
+
const flags = record ? record[2] : 'S...';
|
|
619
|
+
// Without its own `.git`, rev-parse would answer for the parent repository.
|
|
620
|
+
const initialized = await fsp.lstat(path.join(fileContext.absolutePath, '.git')).then(() => true, () => false);
|
|
621
|
+
const worktree = initialized ? await runGitCommand(fileContext.absolutePath, ['rev-parse', '--verify', 'HEAD']) : null;
|
|
622
|
+
const commitOrNull = (value) => (value && !/^0+$/.test(value) ? value : null);
|
|
623
|
+
|
|
624
|
+
return {
|
|
625
|
+
headCommit: commitOrNull(head),
|
|
626
|
+
indexCommit: commitOrNull(index),
|
|
627
|
+
worktreeCommit: worktree?.success ? worktree.stdout.trim() : null,
|
|
628
|
+
hasTrackedChanges: flags[2] === 'M',
|
|
629
|
+
hasUntrackedFiles: flags[3] === 'U',
|
|
630
|
+
hasConflict,
|
|
631
|
+
};
|
|
543
632
|
};
|
|
544
633
|
|
|
545
634
|
const cleanBranchName = (branch) => {
|
|
@@ -2187,13 +2276,149 @@ export async function setLocalIdentity(directory, profile) {
|
|
|
2187
2276
|
}
|
|
2188
2277
|
}
|
|
2189
2278
|
|
|
2279
|
+
// Beyond this many untracked files, a directory stays one `dir/` entry in
|
|
2280
|
+
// status. Every file would otherwise become a row, a diff request, and a stat
|
|
2281
|
+
// on the server, and the only directories that large are ones that belong in
|
|
2282
|
+
// .gitignore.
|
|
2283
|
+
const UNTRACKED_DIRECTORY_EXPANSION_LIMIT = 1000;
|
|
2284
|
+
|
|
2285
|
+
// Untracked files under `dirPath` (repository-relative, trailing slash), read
|
|
2286
|
+
// from a streamed `ls-files` that is stopped once the bound is exceeded so a
|
|
2287
|
+
// huge directory is never listed in full. `paths` is complete when
|
|
2288
|
+
// `truncated` is false.
|
|
2289
|
+
const listUntrackedFilesBounded = async (repoRoot, dirPath, limit) => {
|
|
2290
|
+
const env = await buildGitEnv();
|
|
2291
|
+
return new Promise((resolve, reject) => {
|
|
2292
|
+
const child = spawn(getGitBinary(), ['ls-files', '--others', '--exclude-standard', '-z', '--', dirPath], {
|
|
2293
|
+
cwd: repoRoot,
|
|
2294
|
+
env,
|
|
2295
|
+
windowsHide: true,
|
|
2296
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
2297
|
+
});
|
|
2298
|
+
const paths = [];
|
|
2299
|
+
let pending = '';
|
|
2300
|
+
let truncated = false;
|
|
2301
|
+
let settled = false;
|
|
2302
|
+
const finish = (error) => {
|
|
2303
|
+
if (settled) return;
|
|
2304
|
+
settled = true;
|
|
2305
|
+
if (error) {
|
|
2306
|
+
reject(error);
|
|
2307
|
+
return;
|
|
2308
|
+
}
|
|
2309
|
+
resolve({ paths, truncated });
|
|
2310
|
+
};
|
|
2311
|
+
child.stdout.on('data', (chunk) => {
|
|
2312
|
+
if (truncated) return;
|
|
2313
|
+
pending += chunk.toString('utf8');
|
|
2314
|
+
const records = pending.split('\0');
|
|
2315
|
+
pending = records.pop() ?? '';
|
|
2316
|
+
for (const record of records) {
|
|
2317
|
+
if (!record) continue;
|
|
2318
|
+
paths.push(record);
|
|
2319
|
+
if (paths.length > limit) {
|
|
2320
|
+
truncated = true;
|
|
2321
|
+
child.kill();
|
|
2322
|
+
finish();
|
|
2323
|
+
return;
|
|
2324
|
+
}
|
|
2325
|
+
}
|
|
2326
|
+
});
|
|
2327
|
+
child.on('error', (error) => finish(error));
|
|
2328
|
+
child.on('close', (code) => {
|
|
2329
|
+
if (truncated) {
|
|
2330
|
+
finish();
|
|
2331
|
+
return;
|
|
2332
|
+
}
|
|
2333
|
+
if (code !== 0) {
|
|
2334
|
+
finish(new Error(`git ls-files exited with code ${code} for ${dirPath}`));
|
|
2335
|
+
return;
|
|
2336
|
+
}
|
|
2337
|
+
if (pending) paths.push(pending);
|
|
2338
|
+
finish();
|
|
2339
|
+
});
|
|
2340
|
+
});
|
|
2341
|
+
};
|
|
2342
|
+
|
|
2343
|
+
// Replaces each untracked `dir/` entry from `-unormal` with one entry per file
|
|
2344
|
+
// inside it, the listing `-uall` would have produced, unless the directory
|
|
2345
|
+
// holds more than the bound; then the `dir/` entry stays. A nested repository
|
|
2346
|
+
// lists as itself and stays a `dir/` entry too, which is what the diff routes
|
|
2347
|
+
// expect. A listing failure keeps the `dir/` entry rather than dropping the
|
|
2348
|
+
// change from the status.
|
|
2349
|
+
const expandUntrackedDirectories = async (repoRoot, files) => {
|
|
2350
|
+
const expanded = [];
|
|
2351
|
+
for (const file of files) {
|
|
2352
|
+
const isUntrackedDirectory = file.path.endsWith('/')
|
|
2353
|
+
&& (file.working_dir || '').trim() === '?'
|
|
2354
|
+
&& (file.index || '').trim() === '?';
|
|
2355
|
+
if (!isUntrackedDirectory) {
|
|
2356
|
+
expanded.push(file);
|
|
2357
|
+
continue;
|
|
2358
|
+
}
|
|
2359
|
+
const listing = await listUntrackedFilesBounded(repoRoot, file.path, UNTRACKED_DIRECTORY_EXPANSION_LIMIT)
|
|
2360
|
+
.catch((error) => {
|
|
2361
|
+
console.warn(`[GitService] Could not expand untracked directory ${file.path}:`, error?.message || error);
|
|
2362
|
+
return null;
|
|
2363
|
+
});
|
|
2364
|
+
if (!listing || listing.truncated || listing.paths.some((entry) => entry === file.path)) {
|
|
2365
|
+
expanded.push(file);
|
|
2366
|
+
continue;
|
|
2367
|
+
}
|
|
2368
|
+
for (const entryPath of listing.paths) {
|
|
2369
|
+
expanded.push({ ...file, path: entryPath });
|
|
2370
|
+
}
|
|
2371
|
+
}
|
|
2372
|
+
return expanded;
|
|
2373
|
+
};
|
|
2374
|
+
|
|
2375
|
+
// A status read walks the working tree and runs a dozen Git processes; on a
|
|
2376
|
+
// large repository it takes seconds. Clients ask for it after every completed
|
|
2377
|
+
// agent tool call, from several surfaces, and from PR polling, so without a
|
|
2378
|
+
// bound one slow repository ends up with many identical `git status` processes
|
|
2379
|
+
// side by side. Runs are serialized per directory and capped across
|
|
2380
|
+
// directories; a caller that asks during a run gets a run started after it
|
|
2381
|
+
// asked, so results are never older than the request.
|
|
2382
|
+
const MAX_CONCURRENT_STATUS_READS = 4;
|
|
2383
|
+
const statusRefresh = createSerialRefresh({ maxConcurrent: MAX_CONCURRENT_STATUS_READS });
|
|
2384
|
+
|
|
2190
2385
|
export async function getStatus(directory, options = {}) {
|
|
2191
|
-
const lightMode = options.mode === 'light';
|
|
2192
2386
|
const normalizedDirectory = normalizeDirectoryPath(directory);
|
|
2193
2387
|
if (typeof normalizedDirectory !== 'string' || !normalizedDirectory.trim()) {
|
|
2194
2388
|
throw new Error('directory is required');
|
|
2195
2389
|
}
|
|
2390
|
+
const lightMode = options.mode === 'light';
|
|
2391
|
+
// A full read satisfies light callers too, so one run serves whichever
|
|
2392
|
+
// callers it answers, at the widest mode any of them asked for.
|
|
2393
|
+
return statusRefresh.run(
|
|
2394
|
+
normalizedDirectory,
|
|
2395
|
+
{ lightMode },
|
|
2396
|
+
(requests) => readStatus(normalizedDirectory, requests.every((request) => request.lightMode)),
|
|
2397
|
+
);
|
|
2398
|
+
}
|
|
2196
2399
|
|
|
2400
|
+
/**
|
|
2401
|
+
* Upstream of the checked-out branch as `remote/branch`, or `null` when HEAD
|
|
2402
|
+
* is detached, unborn, or the branch has no upstream configured. Reads refs
|
|
2403
|
+
* and config only, never the working tree: callers that only need the
|
|
2404
|
+
* tracking name must not pay for a status read.
|
|
2405
|
+
*/
|
|
2406
|
+
export async function getTrackingBranch(directory) {
|
|
2407
|
+
const normalizedDirectory = normalizeDirectoryPath(directory);
|
|
2408
|
+
if (!normalizedDirectory) {
|
|
2409
|
+
return null;
|
|
2410
|
+
}
|
|
2411
|
+
const head = await runGitCommand(normalizedDirectory, ['symbolic-ref', '--quiet', 'HEAD']);
|
|
2412
|
+
const headRef = head.success ? head.stdout.trim() : '';
|
|
2413
|
+
if (!headRef.startsWith('refs/heads/')) {
|
|
2414
|
+
return null;
|
|
2415
|
+
}
|
|
2416
|
+
const upstream = await runGitCommand(normalizedDirectory, ['for-each-ref', '--format=%(upstream:short)', headRef]);
|
|
2417
|
+
const tracking = upstream.success ? upstream.stdout.trim() : '';
|
|
2418
|
+
return tracking || null;
|
|
2419
|
+
}
|
|
2420
|
+
|
|
2421
|
+
async function readStatus(normalizedDirectory, lightMode) {
|
|
2197
2422
|
try {
|
|
2198
2423
|
// Prefer an explicit non-repo check before simple-git status so a missing
|
|
2199
2424
|
// repository never depends on process.cwd() or an opaque GitError shape.
|
|
@@ -2203,10 +2428,18 @@ export async function getStatus(directory, options = {}) {
|
|
|
2203
2428
|
|
|
2204
2429
|
const { directoryPath, repoRoot, git } = await createRepositoryGitContext(normalizedDirectory);
|
|
2205
2430
|
|
|
2206
|
-
//
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
//
|
|
2431
|
+
// `-unormal` lists a directory with no tracked files as one `dir/` entry
|
|
2432
|
+
// and stops walking it at its first file. `-uall` would walk every file
|
|
2433
|
+
// in it: on a forgotten build or dependency directory that is a scan of
|
|
2434
|
+
// tens of thousands of files and hundreds of megabytes per status read.
|
|
2435
|
+
// Directories are expanded to their files afterwards, up to a bound.
|
|
2436
|
+
const status = await git.status(['-unormal']);
|
|
2437
|
+
status.files = await expandUntrackedDirectories(repoRoot, status.files);
|
|
2438
|
+
|
|
2439
|
+
// Light mode: skip numstat + new-file line counting for faster response.
|
|
2440
|
+
// Staged (`--cached`: HEAD -> index) and working (`--numstat`: index -> worktree)
|
|
2441
|
+
// stay in separate maps. A partially staged file has an entry in both, and the
|
|
2442
|
+
// UI shows each row's own scope instead of a combined total.
|
|
2210
2443
|
const [stagedStatsRaw, workingStatsRaw] = lightMode
|
|
2211
2444
|
? ['', '']
|
|
2212
2445
|
: await Promise.all([
|
|
@@ -2214,9 +2447,10 @@ export async function getStatus(directory, options = {}) {
|
|
|
2214
2447
|
git.raw(['diff', '--numstat']).catch(() => ''),
|
|
2215
2448
|
]);
|
|
2216
2449
|
|
|
2217
|
-
const
|
|
2450
|
+
const stagedDiffStats = {};
|
|
2451
|
+
const workingDiffStats = {};
|
|
2218
2452
|
|
|
2219
|
-
const accumulateStats = (raw) => {
|
|
2453
|
+
const accumulateStats = (raw, target) => {
|
|
2220
2454
|
if (!raw) return;
|
|
2221
2455
|
raw
|
|
2222
2456
|
.split('\n')
|
|
@@ -2235,18 +2469,18 @@ export async function getStatus(directory, options = {}) {
|
|
|
2235
2469
|
const insertions = insertionsRaw === '-' ? 0 : parseInt(insertionsRaw, 10) || 0;
|
|
2236
2470
|
const deletions = deletionsRaw === '-' ? 0 : parseInt(deletionsRaw, 10) || 0;
|
|
2237
2471
|
|
|
2238
|
-
const existing =
|
|
2239
|
-
|
|
2472
|
+
const existing = target[path] || { insertions: 0, deletions: 0 };
|
|
2473
|
+
target[path] = {
|
|
2240
2474
|
insertions: existing.insertions + insertions,
|
|
2241
2475
|
deletions: existing.deletions + deletions,
|
|
2242
|
-
}
|
|
2476
|
+
};
|
|
2243
2477
|
});
|
|
2244
2478
|
};
|
|
2245
2479
|
|
|
2246
|
-
accumulateStats(stagedStatsRaw);
|
|
2247
|
-
accumulateStats(workingStatsRaw);
|
|
2480
|
+
accumulateStats(stagedStatsRaw, stagedDiffStats);
|
|
2481
|
+
accumulateStats(workingStatsRaw, workingDiffStats);
|
|
2248
2482
|
|
|
2249
|
-
const diffStats =
|
|
2483
|
+
const diffStats = { staged: stagedDiffStats, working: workingDiffStats };
|
|
2250
2484
|
|
|
2251
2485
|
const MAX_NEW_FILE_STATS = 200;
|
|
2252
2486
|
const MAX_NEW_FILE_STAT_SIZE = 1024 * 1024;
|
|
@@ -2266,7 +2500,10 @@ export async function getStatus(directory, options = {}) {
|
|
|
2266
2500
|
continue;
|
|
2267
2501
|
}
|
|
2268
2502
|
|
|
2269
|
-
|
|
2503
|
+
// Untracked and working-tree-added files belong to the working scope;
|
|
2504
|
+
// a file whose 'A' code is on the index belongs to the staged scope.
|
|
2505
|
+
const target = working === '?' || working === 'A' ? workingDiffStats : stagedDiffStats;
|
|
2506
|
+
const existing = target[file.path];
|
|
2270
2507
|
if (existing && existing.insertions > 0) {
|
|
2271
2508
|
continue;
|
|
2272
2509
|
}
|
|
@@ -2282,6 +2519,7 @@ export async function getStatus(directory, options = {}) {
|
|
|
2282
2519
|
const buffer = await fsp.readFile(absolutePath);
|
|
2283
2520
|
if (buffer.indexOf(0) !== -1) {
|
|
2284
2521
|
newFileStats.push({
|
|
2522
|
+
target,
|
|
2285
2523
|
path: file.path,
|
|
2286
2524
|
insertions: existing?.insertions ?? 0,
|
|
2287
2525
|
deletions: existing?.deletions ?? 0,
|
|
@@ -2292,6 +2530,7 @@ export async function getStatus(directory, options = {}) {
|
|
|
2292
2530
|
const normalized = buffer.toString('utf8').replace(/\r\n/g, '\n');
|
|
2293
2531
|
if (!normalized.length) {
|
|
2294
2532
|
newFileStats.push({
|
|
2533
|
+
target,
|
|
2295
2534
|
path: file.path,
|
|
2296
2535
|
insertions: 0,
|
|
2297
2536
|
deletions: 0,
|
|
@@ -2306,6 +2545,7 @@ export async function getStatus(directory, options = {}) {
|
|
|
2306
2545
|
|
|
2307
2546
|
const lineCount = segments.length;
|
|
2308
2547
|
newFileStats.push({
|
|
2548
|
+
target,
|
|
2309
2549
|
path: file.path,
|
|
2310
2550
|
insertions: lineCount,
|
|
2311
2551
|
deletions: 0,
|
|
@@ -2319,7 +2559,7 @@ export async function getStatus(directory, options = {}) {
|
|
|
2319
2559
|
}
|
|
2320
2560
|
|
|
2321
2561
|
for (const entry of newFileStats) {
|
|
2322
|
-
|
|
2562
|
+
entry.target[entry.path] = {
|
|
2323
2563
|
insertions: entry.insertions,
|
|
2324
2564
|
deletions: entry.deletions,
|
|
2325
2565
|
};
|
|
@@ -2481,11 +2721,29 @@ const getNoIndexDiff = async (repoRoot, repoPath, contextLines) => {
|
|
|
2481
2721
|
};
|
|
2482
2722
|
|
|
2483
2723
|
export async function getDiff(directory, { path: filePath, staged = false, contextLines = 3 } = {}) {
|
|
2484
|
-
const
|
|
2724
|
+
const context = await createRepositoryGitContext(directory);
|
|
2725
|
+
const fileContext = filePath
|
|
2726
|
+
? await resolveGitFileContext(context.directoryPath, context.directoryGit, filePath, context.repoRoot)
|
|
2727
|
+
: null;
|
|
2728
|
+
return readDiff(context, fileContext, { staged, contextLines });
|
|
2729
|
+
}
|
|
2485
2730
|
|
|
2731
|
+
/**
|
|
2732
|
+
* `getDiff` for one path, plus what a submodule records. A submodule patch is
|
|
2733
|
+
* empty when only untracked files changed inside it, so callers need the state
|
|
2734
|
+
* to show anything truthful.
|
|
2735
|
+
*/
|
|
2736
|
+
export async function getPathDiff(directory, { path: filePath, staged = false, contextLines = 3 } = {}) {
|
|
2737
|
+
const context = await createRepositoryGitContext(directory);
|
|
2738
|
+
const fileContext = await resolveGitFileContext(context.directoryPath, context.directoryGit, filePath, context.repoRoot);
|
|
2739
|
+
const diff = await readDiff(context, fileContext, { staged, contextLines });
|
|
2740
|
+
if (!fileContext.isSubmodule) return { diff, submodule: null };
|
|
2741
|
+
return { diff, submodule: await readSubmoduleState(context.repoRoot, fileContext) };
|
|
2742
|
+
}
|
|
2743
|
+
|
|
2744
|
+
async function readDiff({ repoRoot, git }, fileContext, { staged, contextLines }) {
|
|
2486
2745
|
try {
|
|
2487
2746
|
const args = ['diff', '--no-color', '--full-index'];
|
|
2488
|
-
const fileContext = filePath ? await resolveGitFileContext(directoryPath, directoryGit, filePath, repoRoot) : null;
|
|
2489
2747
|
|
|
2490
2748
|
if (typeof contextLines === 'number' && !Number.isNaN(contextLines)) {
|
|
2491
2749
|
args.push(`-U${Math.max(0, contextLines)}`);
|
|
@@ -2682,7 +2940,7 @@ export async function getRangeDiff(directory, { base, head, path: filePath, cont
|
|
|
2682
2940
|
const fileContext = await resolveGitFileContext(directoryPath, directoryGit, filePath, repoRoot);
|
|
2683
2941
|
paths.push(fileContext.repoPath);
|
|
2684
2942
|
} catch (error) {
|
|
2685
|
-
if (error.
|
|
2943
|
+
if (error.code !== GIT_PATH_NOT_FOUND) throw error;
|
|
2686
2944
|
// A committed deletion is absent from HEAD, the index, and the working
|
|
2687
2945
|
// tree. It is still a valid range path when it exists at the merge base.
|
|
2688
2946
|
const mergeBase = (await git.raw(['merge-base', baseRef, headRef])).trim();
|
|
@@ -2907,7 +3165,22 @@ export async function getFileDiff(directory, { path: filePath, staged = false }
|
|
|
2907
3165
|
const { directoryPath, directoryGit, repoRoot, git } = await createRepositoryGitContext(directory);
|
|
2908
3166
|
const isImage = isImageFile(filePath);
|
|
2909
3167
|
const mimeType = isImage ? getImageMimeType(filePath) : null;
|
|
2910
|
-
const
|
|
3168
|
+
const fileContext = await resolveGitFileContext(directoryPath, directoryGit, filePath, repoRoot);
|
|
3169
|
+
const { absolutePath, repoPath, isSymbolicLink } = fileContext;
|
|
3170
|
+
|
|
3171
|
+
if (fileContext.isSubmodule) {
|
|
3172
|
+
// Git's own text form of a gitlink, so a plain two-pane view still shows
|
|
3173
|
+
// the recorded commits; `submodule` carries what the text cannot.
|
|
3174
|
+
const submodule = await readSubmoduleState(repoRoot, fileContext);
|
|
3175
|
+
const describeCommit = (commit) => (commit ? `Subproject commit ${commit}\n` : '');
|
|
3176
|
+
return {
|
|
3177
|
+
original: describeCommit(submodule.headCommit),
|
|
3178
|
+
modified: describeCommit(staged ? submodule.indexCommit : submodule.worktreeCommit),
|
|
3179
|
+
path: filePath,
|
|
3180
|
+
isBinary: false,
|
|
3181
|
+
submodule,
|
|
3182
|
+
};
|
|
3183
|
+
}
|
|
2911
3184
|
|
|
2912
3185
|
if (!isImage && !isSymbolicLink) {
|
|
2913
3186
|
const isBinaryBySniff = await looksBinaryBySniff(absolutePath);
|
|
@@ -3346,26 +3619,45 @@ export async function push(directory, options = {}) {
|
|
|
3346
3619
|
);
|
|
3347
3620
|
};
|
|
3348
3621
|
|
|
3349
|
-
const
|
|
3622
|
+
const remote = String(options.remote || '').trim();
|
|
3623
|
+
const status = await git.status();
|
|
3624
|
+
const config = await git.listConfig();
|
|
3625
|
+
const remotes = await git.getRemotes(true);
|
|
3626
|
+
const remoteName = remote
|
|
3627
|
+
|| config.all[`branch.${status.current}.pushremote`]
|
|
3628
|
+
|| config.all['remote.pushdefault']
|
|
3629
|
+
|| config.all[`branch.${status.current}.remote`]
|
|
3630
|
+
|| (remotes.length === 1 ? remotes[0].name : 'origin');
|
|
3631
|
+
|
|
3632
|
+
const pushTo = async (target, branch, pushOptions) => {
|
|
3633
|
+
// simple-git drops forced updates and puts no-ops in `pushed`. Read Git's
|
|
3634
|
+
// porcelain status flags so feedback reflects actual remote ref changes.
|
|
3635
|
+
let output = '';
|
|
3636
|
+
git.outputHandler((_command, stdout) => {
|
|
3637
|
+
stdout.on('data', (chunk) => { output += chunk.toString(); });
|
|
3638
|
+
});
|
|
3639
|
+
const result = await git.push(target, branch, pushOptions);
|
|
3640
|
+
const pushed = [];
|
|
3641
|
+
for (const line of output.split(/\r?\n/)) {
|
|
3642
|
+
const match = /^([ *+\-])\t([^:]*):([^\t]+)\t/.exec(line);
|
|
3643
|
+
if (match) {
|
|
3644
|
+
pushed.push({ local: match[2], remote: remoteName });
|
|
3645
|
+
}
|
|
3646
|
+
}
|
|
3350
3647
|
return {
|
|
3351
3648
|
success: true,
|
|
3352
|
-
pushed
|
|
3353
|
-
repo: result.repo,
|
|
3354
|
-
ref: result.ref,
|
|
3649
|
+
pushed,
|
|
3650
|
+
repo: result.repo || directory,
|
|
3651
|
+
ref: result.ref || null,
|
|
3355
3652
|
};
|
|
3356
3653
|
};
|
|
3357
3654
|
|
|
3358
|
-
const remote = String(options.remote || '').trim();
|
|
3359
|
-
|
|
3360
3655
|
if (!remote && !options.branch) {
|
|
3361
3656
|
try {
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
repo: directory,
|
|
3367
|
-
ref: null,
|
|
3368
|
-
};
|
|
3657
|
+
const pushOptions = status.current && !status.tracking
|
|
3658
|
+
? buildUpstreamOptions(options.options)
|
|
3659
|
+
: options.options || {};
|
|
3660
|
+
return await pushTo(undefined, undefined, pushOptions);
|
|
3369
3661
|
} catch (error) {
|
|
3370
3662
|
if (!looksLikeMissingUpstream(error)) {
|
|
3371
3663
|
const message = describePushError(error);
|
|
@@ -3374,17 +3666,13 @@ export async function push(directory, options = {}) {
|
|
|
3374
3666
|
}
|
|
3375
3667
|
|
|
3376
3668
|
try {
|
|
3377
|
-
const status = await git.status();
|
|
3378
3669
|
const branch = status.current;
|
|
3379
|
-
|
|
3380
|
-
const fallbackRemote = remotes.find((entry) => entry.name === 'origin')?.name || remotes[0]?.name;
|
|
3381
|
-
if (!branch || !fallbackRemote) {
|
|
3670
|
+
if (!branch || !remoteName) {
|
|
3382
3671
|
const message = describePushError(error);
|
|
3383
3672
|
throw new Error(message);
|
|
3384
3673
|
}
|
|
3385
3674
|
|
|
3386
|
-
|
|
3387
|
-
return normalizePushResult(result);
|
|
3675
|
+
return await pushTo(remoteName, branch, buildUpstreamOptions(options.options));
|
|
3388
3676
|
} catch (fallbackError) {
|
|
3389
3677
|
const message = describePushError(fallbackError);
|
|
3390
3678
|
console.error('Failed to push (including upstream fallback):', fallbackError);
|
|
@@ -3393,26 +3681,14 @@ export async function push(directory, options = {}) {
|
|
|
3393
3681
|
}
|
|
3394
3682
|
}
|
|
3395
3683
|
|
|
3396
|
-
const remoteName = remote || 'origin';
|
|
3397
|
-
|
|
3398
3684
|
// If caller didn't specify a branch, this is the common "Push"/"Commit & Push" path.
|
|
3399
3685
|
// When there's no upstream yet (typical for freshly-created worktree branches), publish it on first push.
|
|
3400
|
-
if (!options.branch) {
|
|
3401
|
-
|
|
3402
|
-
const status = await git.status();
|
|
3403
|
-
if (status.current && !status.tracking) {
|
|
3404
|
-
const result = await git.push(remoteName, status.current, buildUpstreamOptions(options.options));
|
|
3405
|
-
return normalizePushResult(result);
|
|
3406
|
-
}
|
|
3407
|
-
} catch (error) {
|
|
3408
|
-
// If we can't read status, fall back to the regular push path below.
|
|
3409
|
-
console.warn('Failed to read git status before push:', error);
|
|
3410
|
-
}
|
|
3686
|
+
if (!options.branch && status.current && !status.tracking) {
|
|
3687
|
+
return pushTo(remoteName, status.current, buildUpstreamOptions(options.options));
|
|
3411
3688
|
}
|
|
3412
3689
|
|
|
3413
3690
|
try {
|
|
3414
|
-
|
|
3415
|
-
return normalizePushResult(result);
|
|
3691
|
+
return await pushTo(remoteName, options.branch, options.options || {});
|
|
3416
3692
|
} catch (error) {
|
|
3417
3693
|
// Last-resort fallback: retry with upstream if the error suggests it's missing.
|
|
3418
3694
|
if (!looksLikeMissingUpstream(error)) {
|
|
@@ -3422,15 +3698,13 @@ export async function push(directory, options = {}) {
|
|
|
3422
3698
|
}
|
|
3423
3699
|
|
|
3424
3700
|
try {
|
|
3425
|
-
const status = await git.status();
|
|
3426
3701
|
const branch = options.branch || status.current;
|
|
3427
3702
|
if (!branch) {
|
|
3428
3703
|
console.error('Failed to push: missing branch name for upstream setup:', error);
|
|
3429
3704
|
throw error;
|
|
3430
3705
|
}
|
|
3431
3706
|
|
|
3432
|
-
|
|
3433
|
-
return normalizePushResult(result);
|
|
3707
|
+
return await pushTo(remoteName, branch, buildUpstreamOptions(options.options));
|
|
3434
3708
|
} catch (fallbackError) {
|
|
3435
3709
|
const message = describePushError(fallbackError);
|
|
3436
3710
|
console.error('Failed to push (including upstream fallback):', fallbackError);
|
|
@@ -5057,7 +5331,7 @@ export async function canonicalizeWorktreeState(directory) {
|
|
|
5057
5331
|
|
|
5058
5332
|
// Detect attention reasons from getStatus side-effects
|
|
5059
5333
|
try {
|
|
5060
|
-
const status = await git.status(['-
|
|
5334
|
+
const status = await git.status(['-unormal']);
|
|
5061
5335
|
if (status.current && (await git.raw(['rev-parse', '--verify', 'MERGE_HEAD']).then(() => true).catch(() => false))) {
|
|
5062
5336
|
attentionReason = 'merge';
|
|
5063
5337
|
} else {
|