@myrialabs/clopen 0.4.46 → 0.4.48
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/README.md +11 -11
- package/backend/artifacts/project/sources.ts +1 -1
- package/backend/auth/auth-service.ts +52 -358
- package/backend/auth/onboarding.test.ts +2 -3
- package/backend/auth/permissions.test.ts +10 -20
- package/backend/auth/permissions.ts +4 -290
- package/backend/auth/rate-limiter.test.ts +8 -9
- package/backend/auth/rate-limiter.ts +0 -2
- package/backend/auth/tokens.ts +1 -8
- package/backend/bootstrap.ts +7 -0
- package/backend/chat/attachments.test.ts +88 -0
- package/backend/chat/attachments.ts +159 -0
- package/backend/chat/engine-handoff.test.ts +0 -2
- package/backend/chat/stream-manager.ts +62 -62
- package/backend/chat/turn-answer.test.ts +64 -0
- package/backend/chat/turn-answer.ts +125 -0
- package/backend/chat-apps/awaiting.test.ts +39 -0
- package/backend/chat-apps/awaiting.ts +49 -0
- package/backend/chat-apps/conversation.ts +746 -0
- package/backend/chat-apps/inbound.ts +324 -0
- package/backend/chat-apps/index.ts +309 -0
- package/backend/chat-apps/link-events.ts +20 -0
- package/backend/chat-apps/media.test.ts +62 -0
- package/backend/chat-apps/media.ts +208 -0
- package/backend/chat-apps/messages.test.ts +229 -0
- package/backend/chat-apps/messages.ts +365 -0
- package/backend/chat-apps/outbound.ts +243 -0
- package/backend/chat-apps/pairing.test.ts +45 -0
- package/backend/chat-apps/pairing.ts +74 -0
- package/backend/chat-apps/platforms/index.ts +20 -0
- package/backend/chat-apps/platforms/telegram.test.ts +35 -0
- package/backend/chat-apps/platforms/telegram.ts +191 -0
- package/backend/chat-apps/platforms/types.ts +114 -0
- package/backend/chat-apps/questions.ts +133 -0
- package/backend/chat-apps/runtime.ts +572 -0
- package/backend/chat-apps/storage.test.ts +201 -0
- package/backend/chat-apps/turns.test.ts +45 -0
- package/backend/chat-apps/turns.ts +208 -0
- package/backend/containers/pty.ts +3 -11
- package/backend/control/actions/accounts.ts +89 -0
- package/backend/control/actions/files.ts +116 -0
- package/backend/control/actions/models.ts +188 -0
- package/backend/control/actions/projects.ts +272 -0
- package/backend/control/actions/sessions.ts +280 -0
- package/backend/control/actions/skills.ts +111 -0
- package/backend/control/control.test.ts +169 -0
- package/backend/control/define.ts +20 -0
- package/backend/control/folders.test.ts +67 -0
- package/backend/control/index.ts +213 -0
- package/backend/control/invoke.ts +44 -0
- package/backend/control/links.ts +35 -0
- package/backend/control/paging.ts +26 -0
- package/backend/control/types.ts +117 -0
- package/backend/control/workspace.ts +127 -0
- package/backend/database/migrations/084_create_channel_links.ts +71 -0
- package/backend/database/migrations/085_add_home_projects.ts +36 -0
- package/backend/database/migrations/086_single_owner.test.ts +170 -0
- package/backend/database/migrations/086_single_owner.ts +418 -0
- package/backend/database/migrations/index.ts +21 -0
- package/backend/database/queries/auth-queries.ts +7 -85
- package/backend/database/queries/channel-queries.ts +270 -0
- package/backend/database/queries/db-client-connection-queries.ts +18 -56
- package/backend/database/queries/file-share-queries.ts +5 -23
- package/backend/database/queries/git-identity-queries.ts +31 -42
- package/backend/database/queries/graph-queries.ts +1 -1
- package/backend/database/queries/index.ts +13 -1
- package/backend/database/queries/message-queries.test.ts +146 -0
- package/backend/database/queries/message-queries.ts +42 -1
- package/backend/database/queries/permission-set-queries.ts +1 -1
- package/backend/database/queries/profile-queries.ts +1 -1
- package/backend/database/queries/project-mcp-trust-queries.ts +1 -1
- package/backend/database/queries/project-queries.ts +50 -63
- package/backend/database/queries/session-queries.ts +28 -56
- package/backend/database/queries/ssh-connection-queries.ts +18 -41
- package/backend/db-client/integrations/projector.ts +0 -5
- package/backend/engine/adapters/claude/message-converter.test.ts +47 -0
- package/backend/engine/adapters/claude/message-converter.ts +25 -2
- package/backend/engine/adapters/cline/message-converter.ts +0 -1
- package/backend/engine/adapters/cline/stream.ts +11 -15
- package/backend/engine/adapters/codex/message-converter.ts +0 -2
- package/backend/engine/adapters/copilot/message-converter.ts +1 -2
- package/backend/engine/adapters/cursor/message-converter.ts +0 -1
- package/backend/engine/adapters/opencode/message-converter.ts +2 -4
- package/backend/engine/adapters/opencode/presets.ts +27 -2
- package/backend/engine/adapters/opencode/server.ts +6 -4
- package/backend/engine/adapters/opencode/stream.ts +11 -0
- package/backend/engine/adapters/parent-scope.test.ts +38 -0
- package/backend/engine/adapters/parent-scope.ts +44 -0
- package/backend/engine/adapters/pi/message-converter.ts +0 -1
- package/backend/engine/adapters/pi/stream.ts +4 -5
- package/backend/engine/adapters/qwen/message-converter.ts +0 -2
- package/backend/engine/bootstrap-default-engine.ts +2 -2
- package/backend/engine/docs/adapter-contract.md +8 -1
- package/backend/engine/install-runner.ts +8 -17
- package/backend/files/file-shares.ts +20 -44
- package/backend/files/file-size-limit.ts +3 -3
- package/backend/files/image-processing.ts +1 -1
- package/backend/files/os-clipboard.ts +2 -2
- package/backend/git/git-executor.ts +25 -5
- package/backend/git/git-service.ts +420 -19
- package/backend/git/identity/credential-helper.test.ts +2 -7
- package/backend/git/identity/import-local.test.ts +11 -16
- package/backend/git/identity/import-local.ts +12 -12
- package/backend/git/identity/index.ts +10 -24
- package/backend/git/identity/resolve.ts +13 -14
- package/backend/git/identity/scope-config.ts +33 -28
- package/backend/git/identity/service.ts +44 -47
- package/backend/git/op-lock.test.ts +111 -0
- package/backend/git/op-lock.ts +180 -0
- package/backend/git/remote-sync.test.ts +249 -0
- package/backend/host/metrics.ts +1 -1
- package/backend/http/bearer-auth.ts +1 -2
- package/backend/http/files-download.test.ts +8 -9
- package/backend/http/files-download.ts +2 -2
- package/backend/http/files-shared.test.ts +62 -89
- package/backend/http/files-shared.ts +2 -2
- package/backend/http/files-upload.test.ts +3 -7
- package/backend/http/files-upload.ts +3 -3
- package/backend/http/notes-images.test.ts +15 -38
- package/backend/http/notes-images.ts +6 -8
- package/backend/http/ssh-sftp.ts +5 -10
- package/backend/index.ts +21 -7
- package/backend/integrations/accounts.ts +61 -3
- package/backend/integrations/index.ts +2 -2
- package/backend/integrations/registry/define.ts +15 -0
- package/backend/integrations/registry/index.ts +2 -0
- package/backend/integrations/registry/providers/telegram.ts +54 -0
- package/backend/integrations/registry/types.ts +21 -1
- package/backend/integrations/webhooks/gateway.ts +7 -6
- package/backend/integrations/webhooks/verify.test.ts +30 -0
- package/backend/integrations/webhooks/verify.ts +4 -0
- package/backend/mcp/external/project.ts +1 -1
- package/backend/mcp/internal/remote-server.test.ts +1 -3
- package/backend/mcp/internal/remote-server.ts +4 -4
- package/backend/mcp/internal/servers/browser-automation/actions/dialogs.ts +67 -0
- package/backend/mcp/internal/servers/browser-automation/actions/index.ts +3 -1
- package/backend/mcp/internal/servers/browser-automation/actions/input.ts +5 -5
- package/backend/mcp/internal/servers/browser-automation/actions/tabs.ts +157 -28
- package/backend/mcp/internal/servers/browser-automation/context.ts +1 -0
- package/backend/mcp/internal/servers/browser-automation/description.ts +5 -2
- package/backend/mcp/internal/servers/browser-automation/format.ts +24 -1
- package/backend/mcp/internal/servers/browser-automation/runner.ts +68 -3
- package/backend/memory/redact.ts +1 -1
- package/backend/notes/access.test.ts +28 -29
- package/backend/notes/access.ts +6 -11
- package/backend/permissions/service.ts +1 -1
- package/backend/preview/browser/browser-clipboard.test.ts +46 -0
- package/backend/preview/browser/browser-clipboard.ts +67 -0
- package/backend/preview/browser/browser-dialog-handler.ts +95 -6
- package/backend/preview/browser/browser-host-bridge.ts +9 -0
- package/backend/preview/browser/browser-interaction-handler.ts +316 -86
- package/backend/preview/browser/browser-mcp-control.ts +34 -0
- package/backend/preview/browser/browser-pool.ts +67 -6
- package/backend/preview/browser/browser-preview-service.ts +361 -25
- package/backend/preview/browser/browser-tab-manager.ts +66 -23
- package/backend/preview/browser/browser-video-capture.ts +92 -5
- package/backend/preview/browser/element-locator.ts +190 -17
- package/backend/preview/browser/keyboard-chords.test.ts +68 -0
- package/backend/preview/browser/keyboard-chords.ts +132 -0
- package/backend/preview/browser/paste.ts +81 -0
- package/backend/preview/browser/process-usage.ts +142 -0
- package/backend/preview/browser/profile-lock.ts +209 -0
- package/backend/preview/browser/scripts/host-bridge.ts +59 -0
- package/backend/preview/browser/scripts/video-stream.ts +58 -0
- package/backend/preview/browser/types.ts +40 -2
- package/backend/preview/browser/viewport.test.ts +45 -0
- package/backend/preview/browser/viewport.ts +96 -0
- package/backend/profiles/service.ts +2 -2
- package/backend/project/status-manager.ts +43 -172
- package/backend/projects/home.ts +61 -0
- package/backend/projects/project-cleanup.integration.test.ts +2 -2
- package/backend/projects/project-cleanup.ts +0 -8
- package/backend/skills/service.ts +2 -3
- package/backend/snapshot/helpers.ts +0 -1
- package/backend/snapshot/restore.ts +252 -0
- package/backend/ssh/ptykit.ts +1 -2
- package/backend/terminal/ptykit.ts +5 -8
- package/backend/tunnel/public-origin.ts +31 -20
- package/backend/utils/user-helpers.ts +0 -55
- package/backend/utils/ws.ts +61 -154
- package/backend/worktrees/branching/engine.ts +3 -16
- package/backend/worktrees/branching/index.ts +1 -1
- package/backend/worktrees/branching/projector.ts +1 -1
- package/backend/worktrees/branching/service.ts +13 -25
- package/backend/ws/access.ts +12 -21
- package/backend/ws/artifacts/generate.ts +2 -2
- package/backend/ws/auth/device.ts +16 -71
- package/backend/ws/auth/index.ts +4 -22
- package/backend/ws/auth/login.test.ts +14 -60
- package/backend/ws/auth/login.ts +24 -124
- package/backend/ws/auth/status.ts +0 -1
- package/backend/ws/chat/composer.ts +118 -118
- package/backend/ws/chat/stream.ts +64 -47
- package/backend/ws/chat-apps/index.ts +117 -0
- package/backend/ws/containers/actions.ts +11 -25
- package/backend/ws/containers/index.ts +3 -4
- package/backend/ws/containers/list.ts +10 -36
- package/backend/ws/containers/logs.ts +2 -2
- package/backend/ws/containers/tunnel.ts +1 -2
- package/backend/ws/db-client/access.ts +2 -16
- package/backend/ws/db-client/accounts.ts +5 -15
- package/backend/ws/db-client/connections.ts +17 -25
- package/backend/ws/db-client/context.ts +1 -1
- package/backend/ws/db-client/env.ts +7 -10
- package/backend/ws/db-client/index.ts +2 -2
- package/backend/ws/db-client/io.ts +5 -5
- package/backend/ws/db-client/query-history-retention.test.ts +8 -8
- package/backend/ws/db-client/query.ts +18 -17
- package/backend/ws/db-client/schema.ts +13 -13
- package/backend/ws/db-client/structure.ts +35 -35
- package/backend/ws/db-client/supabase.ts +4 -21
- package/backend/ws/deployments/context.ts +1 -1
- package/backend/ws/deployments/crud.ts +0 -5
- package/backend/ws/engine/access.ts +7 -20
- package/backend/ws/engine/claude/accounts.ts +4 -4
- package/backend/ws/engine/cline/accounts.ts +5 -5
- package/backend/ws/engine/codex/accounts.ts +3 -3
- package/backend/ws/engine/opencode/providers.ts +2 -1
- package/backend/ws/engine/pi/accounts.ts +5 -5
- package/backend/ws/files/clipboard.ts +8 -27
- package/backend/ws/files/image-edit.ts +6 -6
- package/backend/ws/files/index.ts +1 -1
- package/backend/ws/files/path-access.test.ts +32 -131
- package/backend/ws/files/path-access.ts +8 -87
- package/backend/ws/files/read.ts +15 -19
- package/backend/ws/files/reveal.ts +3 -3
- package/backend/ws/files/search.ts +7 -7
- package/backend/ws/files/share.ts +9 -13
- package/backend/ws/files/state.ts +9 -12
- package/backend/ws/files/watch.ts +3 -3
- package/backend/ws/files/write.ts +30 -31
- package/backend/ws/git/branch.ts +80 -59
- package/backend/ws/git/commit.ts +63 -44
- package/backend/ws/git/conflict.ts +16 -18
- package/backend/ws/git/identity-context.ts +8 -17
- package/backend/ws/git/identity.ts +17 -27
- package/backend/ws/git/index.ts +3 -1
- package/backend/ws/git/op-state.ts +139 -0
- package/backend/ws/git/remote.ts +241 -141
- package/backend/ws/git/repo-context.ts +67 -0
- package/backend/ws/git/staging.ts +18 -28
- package/backend/ws/git/status.ts +5 -2
- package/backend/ws/index.ts +5 -1
- package/backend/ws/instructions/crud.ts +1 -1
- package/backend/ws/integrations/crud.ts +1 -3
- package/backend/ws/mcp/crud.ts +3 -5
- package/backend/ws/mcp/tools.ts +1 -1
- package/backend/ws/memory/crud.ts +14 -46
- package/backend/ws/memory/index.ts +2 -2
- package/backend/ws/messages/crud.ts +29 -8
- package/backend/ws/notes/index.ts +33 -39
- package/backend/ws/permissions/crud.ts +3 -4
- package/backend/ws/ports/index.ts +1 -2
- package/backend/ws/ports/kill.ts +5 -10
- package/backend/ws/ports/list.ts +4 -10
- package/backend/ws/preview/access.ts +1 -1
- package/backend/ws/preview/browser/interact.ts +52 -79
- package/backend/ws/preview/browser/native-ui.ts +24 -0
- package/backend/ws/preview/browser/stats.ts +98 -1
- package/backend/ws/preview/browser/tab-info.ts +15 -0
- package/backend/ws/preview/browser/tab.ts +19 -4
- package/backend/ws/preview/index.ts +27 -0
- package/backend/ws/profiles/crud.ts +6 -8
- package/backend/ws/project-artifacts/index.ts +30 -31
- package/backend/ws/projects/crud.ts +33 -35
- package/backend/ws/projects/index.ts +3 -8
- package/backend/ws/projects/info.ts +3 -3
- package/backend/ws/projects/overview.ts +19 -30
- package/backend/ws/projects/status.ts +17 -57
- package/backend/ws/sessions/crud.ts +34 -45
- package/backend/ws/sessions/index.ts +1 -1
- package/backend/ws/settings/crud.ts +1 -1
- package/backend/ws/skills/crud.ts +3 -4
- package/backend/ws/skills/index.ts +1 -1
- package/backend/ws/snapshot/changes.ts +7 -7
- package/backend/ws/snapshot/restore.ts +11 -295
- package/backend/ws/snapshot/timeline.ts +2 -4
- package/backend/ws/ssh/access.ts +6 -21
- package/backend/ws/ssh/connections.ts +21 -31
- package/backend/ws/ssh/forwards.ts +12 -12
- package/backend/ws/ssh/sftp.ts +34 -34
- package/backend/ws/ssh/tunnel.ts +1 -2
- package/backend/ws/stack/install.ts +7 -17
- package/backend/ws/subagents/crud.ts +1 -1
- package/backend/ws/tunnel/share.ts +0 -2
- package/backend/ws/user/crud.ts +1 -59
- package/backend/ws/user/index.ts +1 -1
- package/backend/ws/work/context.ts +1 -1
- package/backend/ws/work/crud.ts +0 -5
- package/backend/ws/workspace/state.ts +10 -13
- package/backend/ws/worktrees/branching.ts +7 -36
- package/backend/ws/worktrees/crud.ts +2 -2
- package/bin/clopen.ts +10 -11
- package/dist/assets/{index-CwuKQelV.js → index-CONlwAXZ.js} +1 -1
- package/dist/assets/{index-BTcR1byF.js → index-DJzwt-hq.js} +1 -1
- package/dist/assets/main-BUiUL3eZ.css +1 -0
- package/dist/assets/main-nBOb9YOA.js +1240 -0
- package/dist/index.html +2 -2
- package/package.json +2 -1
- package/shared/constants/attachments.ts +14 -0
- package/shared/constants/engine-tools.ts +1 -1
- package/shared/constants/preview.test.ts +259 -0
- package/shared/constants/preview.ts +1018 -57
- package/shared/constants/tool-icons.ts +5 -0
- package/shared/types/containers/container.ts +1 -1
- package/shared/types/database/schema.ts +9 -6
- package/shared/types/git-identity.ts +1 -1
- package/shared/types/git.ts +116 -0
- package/shared/types/integrations.ts +7 -0
- package/shared/types/stores/settings.ts +1 -1
- package/shared/types/unified/index.ts +1 -1
- package/shared/types/unified/message.ts +0 -7
- package/shared/types/unified/stream.ts +2 -4
- package/shared/types/unified/tool.ts +15 -1
- package/shared/utils/ask-user-question.test.ts +319 -0
- package/shared/utils/ask-user-question.ts +154 -0
- package/shared/utils/home-project.ts +25 -0
- package/shared/utils/logger.ts +2 -0
- package/shared/utils/ws-server.ts +32 -7
- package/backend/auth/session-invalidation.test.ts +0 -112
- package/backend/auth/session-invalidation.ts +0 -77
- package/backend/project/status-manager.test.ts +0 -32
- package/backend/ws/auth/invites.ts +0 -94
- package/backend/ws/auth/users.ts +0 -112
- package/backend/ws/projects/presence.ts +0 -46
- package/backend/ws/stack/access.ts +0 -31
- package/dist/assets/main-BiDNMWb3.css +0 -1
- package/dist/assets/main-BlhKWz2B.js +0 -1241
package/backend/ws/git/remote.ts
CHANGED
|
@@ -3,28 +3,18 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { t } from 'elysia';
|
|
6
|
-
import path from 'node:path';
|
|
7
6
|
import { createRouter } from '$shared/utils/ws-server';
|
|
8
7
|
import { gitService } from '../../git/git-service';
|
|
9
8
|
import { requireProjectWorkspace } from '../access';
|
|
10
9
|
import { identityEnvFor, identityEnvForRemote } from './identity-context';
|
|
11
|
-
import {
|
|
10
|
+
import { gitRepoContext, resolveRepoCwd, withRepoLock } from './repo-context';
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const resolved = path.resolve(repoPath);
|
|
20
|
-
const projectRoot = path.resolve(projectPath);
|
|
21
|
-
const sep = path.sep;
|
|
22
|
-
if (resolved !== projectRoot && !resolved.startsWith(projectRoot + sep)) {
|
|
23
|
-
debug.warn('git', `Rejected nested repoPath outside project: ${resolved}`);
|
|
24
|
-
return projectPath;
|
|
25
|
-
}
|
|
26
|
-
return resolved;
|
|
27
|
-
}
|
|
12
|
+
const PUSH_LABELS = {
|
|
13
|
+
'with-tags': 'Push with tags',
|
|
14
|
+
'all-tags': 'Push all tags',
|
|
15
|
+
'force-lease': 'Force push (lease)',
|
|
16
|
+
force: 'Force push'
|
|
17
|
+
} as const;
|
|
28
18
|
|
|
29
19
|
export const remoteHandler = createRouter()
|
|
30
20
|
.http('git:remotes', {
|
|
@@ -53,14 +43,16 @@ export const remoteHandler = createRouter()
|
|
|
53
43
|
message: t.String()
|
|
54
44
|
})
|
|
55
45
|
}, async ({ data, conn }) => {
|
|
56
|
-
const
|
|
57
|
-
const cwd =
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
46
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
47
|
+
const { cwd } = ctx;
|
|
48
|
+
return withRepoLock(ctx, { category: 'fetch', label: 'Fetch', target: data.remote }, async () => {
|
|
49
|
+
const message = await gitService.fetch(
|
|
50
|
+
cwd,
|
|
51
|
+
data.remote,
|
|
52
|
+
await identityEnvForRemote(data.projectId, cwd, data.remote)
|
|
53
|
+
);
|
|
54
|
+
return { message };
|
|
55
|
+
});
|
|
64
56
|
})
|
|
65
57
|
|
|
66
58
|
.http('git:pull', {
|
|
@@ -68,22 +60,91 @@ export const remoteHandler = createRouter()
|
|
|
68
60
|
projectId: t.String(),
|
|
69
61
|
remote: t.Optional(t.String()),
|
|
70
62
|
branch: t.Optional(t.String()),
|
|
63
|
+
/** Legacy flag, same as `mode: 'rebase'`. */
|
|
71
64
|
rebase: t.Optional(t.Boolean()),
|
|
65
|
+
mode: t.Optional(t.Union([
|
|
66
|
+
t.Literal('default'),
|
|
67
|
+
t.Literal('merge'),
|
|
68
|
+
t.Literal('rebase'),
|
|
69
|
+
t.Literal('ff-only')
|
|
70
|
+
])),
|
|
71
|
+
/** Stash local changes around the pull. */
|
|
72
|
+
autostash: t.Optional(t.Boolean()),
|
|
72
73
|
repoPath: t.Optional(t.String())
|
|
73
74
|
}),
|
|
74
75
|
response: t.Object({
|
|
75
76
|
success: t.Boolean(),
|
|
76
|
-
message: t.String()
|
|
77
|
+
message: t.String(),
|
|
78
|
+
reason: t.Optional(t.Union([t.Literal('diverged'), t.Literal('conflict'), t.Literal('local-changes')])),
|
|
79
|
+
ahead: t.Optional(t.Number()),
|
|
80
|
+
behind: t.Optional(t.Number()),
|
|
81
|
+
pulledCount: t.Optional(t.Number())
|
|
77
82
|
})
|
|
78
83
|
}, async ({ data, conn }) => {
|
|
79
|
-
const
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
84
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
85
|
+
const mode = data.mode ?? (data.rebase ? 'rebase' : 'default');
|
|
86
|
+
const label = mode === 'rebase' ? 'Pull (rebase)' : mode === 'ff-only' ? 'Pull (fast-forward)' : mode === 'merge' ? 'Pull (merge)' : 'Pull';
|
|
87
|
+
return withRepoLock(ctx, { category: 'pull', label, target: data.branch }, async () =>
|
|
88
|
+
gitService.pull(
|
|
89
|
+
ctx.cwd,
|
|
90
|
+
data.remote,
|
|
91
|
+
data.branch,
|
|
92
|
+
mode,
|
|
93
|
+
data.autostash ?? false,
|
|
94
|
+
await identityEnvForRemote(data.projectId, ctx.cwd, data.remote)
|
|
95
|
+
)
|
|
96
|
+
);
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
// What a force pull would throw away — fetched fresh, for the confirmation.
|
|
100
|
+
.http('git:force-pull-preview', {
|
|
101
|
+
data: t.Object({
|
|
102
|
+
projectId: t.String(),
|
|
103
|
+
remote: t.Optional(t.String()),
|
|
104
|
+
branch: t.Optional(t.String()),
|
|
105
|
+
repoPath: t.Optional(t.String())
|
|
106
|
+
}),
|
|
107
|
+
response: t.Object({
|
|
108
|
+
target: t.String(),
|
|
109
|
+
localCommits: t.Number(),
|
|
110
|
+
incomingCommits: t.Number(),
|
|
111
|
+
changedFiles: t.Number(),
|
|
112
|
+
collidingUntracked: t.Array(t.String())
|
|
113
|
+
})
|
|
114
|
+
}, async ({ data, conn }) => {
|
|
115
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
116
|
+
return withRepoLock(ctx, { category: 'fetch', label: 'Fetch', target: data.branch }, async () =>
|
|
117
|
+
gitService.forcePullPreview(
|
|
118
|
+
ctx.cwd,
|
|
119
|
+
data.remote,
|
|
120
|
+
data.branch,
|
|
121
|
+
await identityEnvForRemote(data.projectId, ctx.cwd, data.remote)
|
|
122
|
+
)
|
|
123
|
+
);
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
.http('git:force-pull', {
|
|
127
|
+
data: t.Object({
|
|
128
|
+
projectId: t.String(),
|
|
129
|
+
remote: t.Optional(t.String()),
|
|
130
|
+
branch: t.Optional(t.String()),
|
|
131
|
+
repoPath: t.Optional(t.String())
|
|
132
|
+
}),
|
|
133
|
+
response: t.Object({
|
|
134
|
+
previousHead: t.String(),
|
|
135
|
+
newHead: t.String(),
|
|
136
|
+
discardedCommits: t.Number(),
|
|
137
|
+
stashMessage: t.Optional(t.String())
|
|
138
|
+
})
|
|
139
|
+
}, async ({ data, conn }) => {
|
|
140
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
141
|
+
return withRepoLock(ctx, { category: 'pull', label: 'Force pull', target: data.branch }, async () =>
|
|
142
|
+
gitService.forcePull(
|
|
143
|
+
ctx.cwd,
|
|
144
|
+
data.remote,
|
|
145
|
+
data.branch,
|
|
146
|
+
await identityEnvForRemote(data.projectId, ctx.cwd, data.remote)
|
|
147
|
+
)
|
|
87
148
|
);
|
|
88
149
|
})
|
|
89
150
|
|
|
@@ -105,15 +166,17 @@ export const remoteHandler = createRouter()
|
|
|
105
166
|
message: t.String()
|
|
106
167
|
})
|
|
107
168
|
}, async ({ data, conn }) => {
|
|
108
|
-
const
|
|
109
|
-
const cwd =
|
|
110
|
-
return
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
169
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
170
|
+
const { cwd } = ctx;
|
|
171
|
+
return withRepoLock(ctx, { category: 'push', label: PUSH_LABELS[data.mode], target: data.branch }, async () => {
|
|
172
|
+
return await gitService.pushAdvanced(
|
|
173
|
+
cwd,
|
|
174
|
+
data.mode,
|
|
175
|
+
data.remote,
|
|
176
|
+
data.branch,
|
|
177
|
+
await identityEnvForRemote(data.projectId, cwd, data.remote)
|
|
178
|
+
);
|
|
179
|
+
});
|
|
117
180
|
})
|
|
118
181
|
|
|
119
182
|
.http('git:fetch-all', {
|
|
@@ -125,13 +188,15 @@ export const remoteHandler = createRouter()
|
|
|
125
188
|
message: t.String()
|
|
126
189
|
})
|
|
127
190
|
}, async ({ data, conn }) => {
|
|
128
|
-
const
|
|
129
|
-
const cwd =
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
191
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
192
|
+
const { cwd } = ctx;
|
|
193
|
+
return withRepoLock(ctx, { category: 'fetch', label: 'Fetch all' }, async () => {
|
|
194
|
+
const message = await gitService.fetchAll(
|
|
195
|
+
cwd,
|
|
196
|
+
await identityEnvForRemote(data.projectId, cwd)
|
|
197
|
+
);
|
|
198
|
+
return { message };
|
|
199
|
+
});
|
|
135
200
|
})
|
|
136
201
|
|
|
137
202
|
.http('git:push', {
|
|
@@ -152,16 +217,18 @@ export const remoteHandler = createRouter()
|
|
|
152
217
|
message: t.String()
|
|
153
218
|
})
|
|
154
219
|
}, async ({ data, conn }) => {
|
|
155
|
-
const
|
|
156
|
-
const cwd =
|
|
157
|
-
return
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
220
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
221
|
+
const { cwd } = ctx;
|
|
222
|
+
return withRepoLock(ctx, { category: 'push', label: data.force ? 'Force push (lease)' : 'Push', target: data.branch }, async () => {
|
|
223
|
+
return await gitService.push(
|
|
224
|
+
cwd,
|
|
225
|
+
data.remote,
|
|
226
|
+
data.branch,
|
|
227
|
+
data.force,
|
|
228
|
+
{ useUpstream: data.useUpstream ?? true },
|
|
229
|
+
await identityEnvForRemote(data.projectId, cwd, data.remote)
|
|
230
|
+
);
|
|
231
|
+
});
|
|
165
232
|
})
|
|
166
233
|
|
|
167
234
|
/** Where a push would actually land — drives the Push button's label. */
|
|
@@ -194,10 +261,12 @@ export const remoteHandler = createRouter()
|
|
|
194
261
|
}),
|
|
195
262
|
response: t.Object({ ok: t.Boolean() })
|
|
196
263
|
}, async ({ data, conn }) => {
|
|
197
|
-
const
|
|
198
|
-
const cwd =
|
|
199
|
-
|
|
200
|
-
|
|
264
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
265
|
+
const { cwd } = ctx;
|
|
266
|
+
return withRepoLock(ctx, { category: 'configure', label: 'Set upstream', target: data.branch }, async () => {
|
|
267
|
+
await gitService.setUpstream(cwd, data.branch, data.remote, data.remoteBranch);
|
|
268
|
+
return { ok: true };
|
|
269
|
+
});
|
|
201
270
|
})
|
|
202
271
|
|
|
203
272
|
.http('git:unset-upstream', {
|
|
@@ -208,10 +277,12 @@ export const remoteHandler = createRouter()
|
|
|
208
277
|
}),
|
|
209
278
|
response: t.Object({ ok: t.Boolean() })
|
|
210
279
|
}, async ({ data, conn }) => {
|
|
211
|
-
const
|
|
212
|
-
const cwd =
|
|
213
|
-
|
|
214
|
-
|
|
280
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
281
|
+
const { cwd } = ctx;
|
|
282
|
+
return withRepoLock(ctx, { category: 'configure', label: 'Clear upstream', target: data.branch }, async () => {
|
|
283
|
+
await gitService.unsetUpstream(cwd, data.branch);
|
|
284
|
+
return { ok: true };
|
|
285
|
+
});
|
|
215
286
|
})
|
|
216
287
|
|
|
217
288
|
.http('git:add-remote', {
|
|
@@ -223,10 +294,12 @@ export const remoteHandler = createRouter()
|
|
|
223
294
|
}),
|
|
224
295
|
response: t.Object({ ok: t.Boolean() })
|
|
225
296
|
}, async ({ data, conn }) => {
|
|
226
|
-
const
|
|
227
|
-
const cwd =
|
|
228
|
-
|
|
229
|
-
|
|
297
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
298
|
+
const { cwd } = ctx;
|
|
299
|
+
return withRepoLock(ctx, { category: 'configure', label: 'Add remote', target: data.name }, async () => {
|
|
300
|
+
await gitService.addRemote(cwd, data.name, data.url);
|
|
301
|
+
return { ok: true };
|
|
302
|
+
});
|
|
230
303
|
})
|
|
231
304
|
|
|
232
305
|
.http('git:set-remote-url', {
|
|
@@ -238,10 +311,12 @@ export const remoteHandler = createRouter()
|
|
|
238
311
|
}),
|
|
239
312
|
response: t.Object({ ok: t.Boolean() })
|
|
240
313
|
}, async ({ data, conn }) => {
|
|
241
|
-
const
|
|
242
|
-
const cwd =
|
|
243
|
-
|
|
244
|
-
|
|
314
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
315
|
+
const { cwd } = ctx;
|
|
316
|
+
return withRepoLock(ctx, { category: 'configure', label: 'Edit remote', target: data.name }, async () => {
|
|
317
|
+
await gitService.setRemoteUrl(cwd, data.name, data.url);
|
|
318
|
+
return { ok: true };
|
|
319
|
+
});
|
|
245
320
|
})
|
|
246
321
|
|
|
247
322
|
.http('git:rename-remote', {
|
|
@@ -253,10 +328,12 @@ export const remoteHandler = createRouter()
|
|
|
253
328
|
}),
|
|
254
329
|
response: t.Object({ ok: t.Boolean() })
|
|
255
330
|
}, async ({ data, conn }) => {
|
|
256
|
-
const
|
|
257
|
-
const cwd =
|
|
258
|
-
|
|
259
|
-
|
|
331
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
332
|
+
const { cwd } = ctx;
|
|
333
|
+
return withRepoLock(ctx, { category: 'configure', label: 'Rename remote', target: data.oldName }, async () => {
|
|
334
|
+
await gitService.renameRemote(cwd, data.oldName, data.newName);
|
|
335
|
+
return { ok: true };
|
|
336
|
+
});
|
|
260
337
|
})
|
|
261
338
|
|
|
262
339
|
.http('git:edit-remote', {
|
|
@@ -269,13 +346,15 @@ export const remoteHandler = createRouter()
|
|
|
269
346
|
}),
|
|
270
347
|
response: t.Object({ ok: t.Boolean() })
|
|
271
348
|
}, async ({ data, conn }) => {
|
|
272
|
-
const
|
|
273
|
-
const cwd =
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
349
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
350
|
+
const { cwd } = ctx;
|
|
351
|
+
return withRepoLock(ctx, { category: 'configure', label: 'Edit remote', target: data.oldName }, async () => {
|
|
352
|
+
if (data.oldName !== data.newName) {
|
|
353
|
+
await gitService.renameRemote(cwd, data.oldName, data.newName);
|
|
354
|
+
}
|
|
355
|
+
await gitService.setRemoteUrl(cwd, data.newName, data.newUrl);
|
|
356
|
+
return { ok: true };
|
|
357
|
+
});
|
|
279
358
|
})
|
|
280
359
|
|
|
281
360
|
.http('git:remove-remote', {
|
|
@@ -286,10 +365,12 @@ export const remoteHandler = createRouter()
|
|
|
286
365
|
}),
|
|
287
366
|
response: t.Object({ ok: t.Boolean() })
|
|
288
367
|
}, async ({ data, conn }) => {
|
|
289
|
-
const
|
|
290
|
-
const cwd =
|
|
291
|
-
|
|
292
|
-
|
|
368
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
369
|
+
const { cwd } = ctx;
|
|
370
|
+
return withRepoLock(ctx, { category: 'configure', label: 'Remove remote', target: data.name }, async () => {
|
|
371
|
+
await gitService.removeRemote(cwd, data.name);
|
|
372
|
+
return { ok: true };
|
|
373
|
+
});
|
|
293
374
|
})
|
|
294
375
|
|
|
295
376
|
.http('git:delete-remote-branch', {
|
|
@@ -301,15 +382,17 @@ export const remoteHandler = createRouter()
|
|
|
301
382
|
}),
|
|
302
383
|
response: t.Object({ ok: t.Boolean() })
|
|
303
384
|
}, async ({ data, conn }) => {
|
|
304
|
-
const
|
|
305
|
-
const cwd =
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
385
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
386
|
+
const { cwd } = ctx;
|
|
387
|
+
return withRepoLock(ctx, { category: 'branch', cls: 'network', label: 'Delete remote branch', target: `${data.remote}/${data.branch}` }, async () => {
|
|
388
|
+
await gitService.deleteRemoteBranch(
|
|
389
|
+
cwd,
|
|
390
|
+
data.remote,
|
|
391
|
+
data.branch,
|
|
392
|
+
await identityEnvForRemote(data.projectId, cwd, data.remote)
|
|
393
|
+
);
|
|
394
|
+
return { ok: true };
|
|
395
|
+
});
|
|
313
396
|
})
|
|
314
397
|
|
|
315
398
|
.http('git:stash-list', {
|
|
@@ -333,19 +416,24 @@ export const remoteHandler = createRouter()
|
|
|
333
416
|
projectId: t.String(),
|
|
334
417
|
message: t.Optional(t.String()),
|
|
335
418
|
staged: t.Optional(t.Boolean()),
|
|
419
|
+
/** Stash untracked files too (`--include-untracked`). */
|
|
420
|
+
includeUntracked: t.Optional(t.Boolean()),
|
|
336
421
|
repoPath: t.Optional(t.String())
|
|
337
422
|
}),
|
|
338
423
|
response: t.Object({ ok: t.Boolean() })
|
|
339
424
|
}, async ({ data, conn }) => {
|
|
340
|
-
const
|
|
341
|
-
const cwd =
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
425
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
426
|
+
const { cwd } = ctx;
|
|
427
|
+
return withRepoLock(ctx, { category: 'stash', label: 'Stash' }, async () => {
|
|
428
|
+
await gitService.stashSave(
|
|
429
|
+
cwd,
|
|
430
|
+
data.message,
|
|
431
|
+
data.staged,
|
|
432
|
+
identityEnvFor(data.projectId),
|
|
433
|
+
data.includeUntracked
|
|
434
|
+
);
|
|
435
|
+
return { ok: true };
|
|
436
|
+
});
|
|
349
437
|
})
|
|
350
438
|
|
|
351
439
|
.http('git:stash-pop', {
|
|
@@ -360,9 +448,11 @@ export const remoteHandler = createRouter()
|
|
|
360
448
|
message: t.String()
|
|
361
449
|
})
|
|
362
450
|
}, async ({ data, conn }) => {
|
|
363
|
-
const
|
|
364
|
-
const cwd =
|
|
365
|
-
return
|
|
451
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
452
|
+
const { cwd } = ctx;
|
|
453
|
+
return withRepoLock(ctx, { category: 'stash', label: 'Pop stash' }, async () => {
|
|
454
|
+
return await gitService.stashPop(cwd, data.index);
|
|
455
|
+
});
|
|
366
456
|
})
|
|
367
457
|
|
|
368
458
|
.http('git:stash-apply', {
|
|
@@ -377,9 +467,11 @@ export const remoteHandler = createRouter()
|
|
|
377
467
|
message: t.String()
|
|
378
468
|
})
|
|
379
469
|
}, async ({ data, conn }) => {
|
|
380
|
-
const
|
|
381
|
-
const cwd =
|
|
382
|
-
return
|
|
470
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
471
|
+
const { cwd } = ctx;
|
|
472
|
+
return withRepoLock(ctx, { category: 'stash', label: 'Apply stash' }, async () => {
|
|
473
|
+
return await gitService.stashApply(cwd, data.index);
|
|
474
|
+
});
|
|
383
475
|
})
|
|
384
476
|
|
|
385
477
|
.http('git:stash-drop', {
|
|
@@ -390,10 +482,12 @@ export const remoteHandler = createRouter()
|
|
|
390
482
|
}),
|
|
391
483
|
response: t.Object({ ok: t.Boolean() })
|
|
392
484
|
}, async ({ data, conn }) => {
|
|
393
|
-
const
|
|
394
|
-
const cwd =
|
|
395
|
-
|
|
396
|
-
|
|
485
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
486
|
+
const { cwd } = ctx;
|
|
487
|
+
return withRepoLock(ctx, { category: 'stash', label: 'Drop stash' }, async () => {
|
|
488
|
+
await gitService.stashDrop(cwd, data.index);
|
|
489
|
+
return { ok: true };
|
|
490
|
+
});
|
|
397
491
|
})
|
|
398
492
|
|
|
399
493
|
.http('git:stash-diff', {
|
|
@@ -455,16 +549,18 @@ export const remoteHandler = createRouter()
|
|
|
455
549
|
}),
|
|
456
550
|
response: t.Object({ ok: t.Boolean() })
|
|
457
551
|
}, async ({ data, conn }) => {
|
|
458
|
-
const
|
|
459
|
-
const cwd =
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
552
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
553
|
+
const { cwd } = ctx;
|
|
554
|
+
return withRepoLock(ctx, { category: 'tag', label: 'Create tag', target: data.name }, async () => {
|
|
555
|
+
await gitService.createTag(
|
|
556
|
+
cwd,
|
|
557
|
+
data.name,
|
|
558
|
+
data.message,
|
|
559
|
+
data.commitHash,
|
|
560
|
+
identityEnvFor(data.projectId)
|
|
561
|
+
);
|
|
562
|
+
return { ok: true };
|
|
563
|
+
});
|
|
468
564
|
})
|
|
469
565
|
|
|
470
566
|
.http('git:delete-tag', {
|
|
@@ -475,10 +571,12 @@ export const remoteHandler = createRouter()
|
|
|
475
571
|
}),
|
|
476
572
|
response: t.Object({ ok: t.Boolean() })
|
|
477
573
|
}, async ({ data, conn }) => {
|
|
478
|
-
const
|
|
479
|
-
const cwd =
|
|
480
|
-
|
|
481
|
-
|
|
574
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
575
|
+
const { cwd } = ctx;
|
|
576
|
+
return withRepoLock(ctx, { category: 'tag', label: 'Delete tag', target: data.name }, async () => {
|
|
577
|
+
await gitService.deleteTag(cwd, data.name);
|
|
578
|
+
return { ok: true };
|
|
579
|
+
});
|
|
482
580
|
})
|
|
483
581
|
|
|
484
582
|
.http('git:push-tag', {
|
|
@@ -493,12 +591,14 @@ export const remoteHandler = createRouter()
|
|
|
493
591
|
message: t.String()
|
|
494
592
|
})
|
|
495
593
|
}, async ({ data, conn }) => {
|
|
496
|
-
const
|
|
497
|
-
const cwd =
|
|
498
|
-
return
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
594
|
+
const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
|
|
595
|
+
const { cwd } = ctx;
|
|
596
|
+
return withRepoLock(ctx, { category: 'tag', label: 'Push tag', target: data.name }, async () => {
|
|
597
|
+
return await gitService.pushTag(
|
|
598
|
+
cwd,
|
|
599
|
+
data.name,
|
|
600
|
+
data.remote,
|
|
601
|
+
await identityEnvForRemote(data.projectId, cwd, data.remote)
|
|
602
|
+
);
|
|
603
|
+
});
|
|
504
604
|
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared resolution of "which repository does this request address", plus the
|
|
3
|
+
* operation lock every mutating git handler runs under.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import type { WSConnection } from '$shared/utils/ws-server';
|
|
8
|
+
import { makeScopeKey } from '$shared/utils/workspace-scope';
|
|
9
|
+
import { debug } from '$shared/utils/logger';
|
|
10
|
+
import { requireProjectWorkspace } from '../access';
|
|
11
|
+
import { withGitOpLock, type GitOpSpec } from '../../git/op-lock';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Resolve the working directory for a git operation. Defaults to the project
|
|
15
|
+
* root; when `repoPath` is provided it must already be inside the project
|
|
16
|
+
* (these paths come from the backend's own `getBranches` response, but we
|
|
17
|
+
* re-validate to defend against a tampered/mismatched client).
|
|
18
|
+
*/
|
|
19
|
+
export function resolveRepoCwd(projectPath: string, repoPath: string | undefined): string {
|
|
20
|
+
if (!repoPath) return projectPath;
|
|
21
|
+
const resolved = path.resolve(repoPath);
|
|
22
|
+
const projectRoot = path.resolve(projectPath);
|
|
23
|
+
if (resolved !== projectRoot && !resolved.startsWith(projectRoot + path.sep)) {
|
|
24
|
+
debug.warn('git', `Rejected nested repoPath outside project: ${resolved}`);
|
|
25
|
+
return projectPath;
|
|
26
|
+
}
|
|
27
|
+
return resolved;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface GitRepoContext {
|
|
31
|
+
projectId: string;
|
|
32
|
+
/** The project's own directory — differs from `root` inside a worktree. */
|
|
33
|
+
projectRoot: string;
|
|
34
|
+
/** Root of the workspace the connection is viewing (project or worktree). */
|
|
35
|
+
root: string;
|
|
36
|
+
/** Working directory of the addressed repository. */
|
|
37
|
+
cwd: string;
|
|
38
|
+
/** Workspace scope key — the same key `git:changed` uses. */
|
|
39
|
+
scope: string;
|
|
40
|
+
/** Nested repo path as clients address it; absent for the workspace's own repo. */
|
|
41
|
+
repoPath?: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Resolve the repository a request addresses. `cwd` overrides `repoPath` when known. */
|
|
45
|
+
export function gitRepoContext(
|
|
46
|
+
conn: WSConnection,
|
|
47
|
+
projectId: string,
|
|
48
|
+
repoPath?: string,
|
|
49
|
+
cwdOverride?: string
|
|
50
|
+
): GitRepoContext {
|
|
51
|
+
const { project, root, worktreeId } = requireProjectWorkspace(conn, projectId);
|
|
52
|
+
const cwd = cwdOverride ?? resolveRepoCwd(root, repoPath);
|
|
53
|
+
const isRoot = path.resolve(cwd) === path.resolve(root);
|
|
54
|
+
return {
|
|
55
|
+
projectId: project.id,
|
|
56
|
+
projectRoot: project.path,
|
|
57
|
+
root,
|
|
58
|
+
cwd,
|
|
59
|
+
scope: makeScopeKey(project.id, worktreeId),
|
|
60
|
+
...(!isRoot && { repoPath: cwd })
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Run `fn` holding the repository's operation lock (see `op-lock.ts`). */
|
|
65
|
+
export function withRepoLock<T>(ctx: GitRepoContext, spec: GitOpSpec, fn: () => Promise<T>): Promise<T> {
|
|
66
|
+
return withGitOpLock({ cwd: path.resolve(ctx.cwd), scope: ctx.scope, repoPath: ctx.repoPath }, spec, fn);
|
|
67
|
+
}
|