You've already forked agentic-coding-workflow
feat(workspace): fetch+checkout when switching default_branch
This commit is contained in:
@@ -167,7 +167,24 @@ func (s *workspaceService) Update(ctx context.Context, c Caller, wsID uuid.UUID,
|
||||
if in.Description != nil {
|
||||
desc = *in.Description
|
||||
}
|
||||
if in.DefaultBranch != nil {
|
||||
if in.DefaultBranch != nil && *in.DefaultBranch != ws.DefaultBranch {
|
||||
// 切换 default_branch:先校验→拉远端→切到新分支,再写 DB。
|
||||
// 任一 git 步骤失败则不改库,让调用方感知并自行重试/回滚。
|
||||
if err := ValidateBranch(*in.DefaultBranch); err != nil {
|
||||
return nil, errs.Wrap(err, errs.CodeInvalidInput, "invalid default branch")
|
||||
}
|
||||
cred, credErr := s.loadDecryptedCredential(ctx, wsID)
|
||||
if credErr != nil {
|
||||
return nil, credErr
|
||||
}
|
||||
if fetchErr := s.gitr.FetchRemoteBranch(ctx, ws.MainPath, *in.DefaultBranch, cred); fetchErr != nil {
|
||||
return nil, errs.Wrap(fetchErr, errs.CodeGitCmdFailed, "fetch remote branch")
|
||||
}
|
||||
if coErr := s.gitr.Checkout(ctx, ws.MainPath, *in.DefaultBranch); coErr != nil {
|
||||
return nil, errs.Wrap(coErr, errs.CodeGitCmdFailed, "checkout branch")
|
||||
}
|
||||
defaultBr = *in.DefaultBranch
|
||||
} else if in.DefaultBranch != nil {
|
||||
if err := ValidateBranch(*in.DefaultBranch); err != nil {
|
||||
return nil, errs.Wrap(err, errs.CodeInvalidInput, "invalid default branch")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user