git 逻辑

This commit is contained in:
2026-06-10 15:30:52 +08:00
parent 41f2a84979
commit 023ab2f30e
17 changed files with 221 additions and 64 deletions
+9 -6
View File
@@ -9,18 +9,21 @@ import (
// WorktreeAdd 在 dir(main worktree)创建一个支线 worktree。
//
// path: 绝对路径,由 workspace 包计算
// branch: 用 -B 强制创建/重置 — 已存在的分支会被 reset 到 origin/HEAD
// (本地未推送 commit 会丢失,可从 reflog 找回);--track 让分支
// 默认 track origin/HEAD(通常是 main),首次 push 时由 service
// 层 set-upstream 到对应远端分支
// path: 绝对路径,由 workspace 包计算
// branch: 用 -B 强制创建/重置 — 已存在的分支会被重置(本地未推送
// commit 会丢失,可从 reflog 找回)
// startPoint: 为空时分支基于当前 HEAD;非空时分支基于该 start-point,
// 且 --track 会把 upstream 指向它
//
// 失败时如果 stderr 含 "already exists" / "is already used by worktree",
// errors.IsConflict 返回 true,调用方应映射为 WORKTREE_BRANCH_CONFLICT。
func (r *DefaultRunner) WorktreeAdd(ctx context.Context, dir, branch, path string) error {
func (r *DefaultRunner) WorktreeAdd(ctx context.Context, dir, branch, path, startPoint string) error {
ctx, cancel := withCtx(ctx, r.cfg.OpsTimeout)
defer cancel()
args := []string{"worktree", "add", "--track", "-B", branch, path}
if startPoint != "" {
args = append(args, startPoint)
}
_, _, err := r.exec(ctx, dir, nil, args...)
return err
}