返回 DeepSeek-Reasonix
delivery_worktree.go
根目录 / desktop / delivery_worktree.go
1 package main
2
3 import (
4 "fmt"
5 "strings"
6
7 "reasonix/internal/boot"
8 "reasonix/internal/config"
9 "reasonix/internal/worktree"
10 )
11
12 var (
13 inspectDeliveryWorktree = worktree.Inspect
14 createDeliveryWorktree = worktree.Create
15 )
16
17 // DeliveryWorktreeOpenResult is returned after an isolated Git workspace has
18 // been created and opened as a normal Reasonix project.
19 type DeliveryWorktreeOpenResult struct {
20 WorkspaceRoot string `json:"workspaceRoot"`
21 WorktreeRoot string `json:"worktreeRoot"`
22 SourceRoot string `json:"sourceRoot"`
23 Branch string `json:"branch"`
24 SourceDirty bool `json:"sourceDirty"`
25 Tab TabMeta `json:"tab"`
26 }
27
28 // DeliveryWorktreeAvailability reports whether workspaceRoot can use the
29 // optional Git isolation path. A false result never disables Delivery itself;
30 // the cross-platform workspace writer lease remains the no-Git fallback.
31 func (a *App) DeliveryWorktreeAvailability(workspaceRoot string) worktree.Availability {
32 return inspectDeliveryWorktree(a.bootContext(), workspaceRoot)
33 }
34
35 // CreateDeliveryWorktree creates a durable branch-backed worktree and opens it
36 // as a project. It never switches or modifies the source checkout, and it does
37 // not delete the new worktree if later UI registration fails.
38 func (a *App) CreateDeliveryWorktree(workspaceRoot string) (DeliveryWorktreeOpenResult, error) {
39 workspaceRoot = strings.TrimSpace(workspaceRoot)
40 created, err := createDeliveryWorktree(a.bootContext(), workspaceRoot, config.DeliveryWorktreeDir())
41 if err != nil {
42 return DeliveryWorktreeOpenResult{}, err
43 }
44
45 var tab TabMeta
46 if a.singleSurfaceLayoutEnabled() {
47 tab, err = a.ensureBlankSurface("project", created.WorkspaceRoot, boot.TokenModeDelivery)
48 } else {
49 tab, err = a.ensureBlankTab("project", created.WorkspaceRoot, boot.TokenModeDelivery)
50 }
51 if err != nil {
52 return DeliveryWorktreeOpenResult{}, fmt.Errorf("isolated worktree was created at %s but Reasonix could not open it: %w", created.WorktreeRoot, err)
53 }
54 return DeliveryWorktreeOpenResult{
55 WorkspaceRoot: created.WorkspaceRoot,
56 WorktreeRoot: created.WorktreeRoot,
57 SourceRoot: created.SourceRoot,
58 Branch: created.Branch,
59 SourceDirty: created.SourceDirty,
60 Tab: tab,
61 }, nil
62 }
63
63 lines GO