localsync

package
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package localsync 负责把远程执行机上的任务分支同步到协调者本地仓库。

职责:

  • 以 git fetch <url> <branch>:<branch> 把远程任务分支拉到本地同名分支
  • 报告本次同步的增量(新建分支 / 新增提交数),供 CLI 打印给协调者

边界:

  • 只 fetch,不 checkout、不 merge、不碰 HEAD——协调者本地可能正在改别的东西, 合不合、怎么合是人的决定
  • 不解析 ssh 配置、不管凭证:RemoteURL 原样交给 git,认证由 ssh 自身完成
  • 不判断「该不该同步」:触发时机由调用方(wait/pull)决定

Index

Constants

This section is empty.

Variables

View Source
var FetchTimeout = 2 * time.Minute

FetchTimeout 是一次同步的时长上限:走 ssh 网络,且可能拉较大的提交集。

Functions

This section is empty.

Types

type Opts

type Opts struct {
	LocalRepo string
	RemoteURL string
	Branch    string
}

Opts 描述一次同步。

  • LocalRepo: 本地仓库路径(通常是协调者的 cwd)
  • RemoteURL: 远程仓库地址,形如 host:/path/to/repo(也接受本地路径,git 同一条路径处理)
  • Branch: 要同步的任务分支名(取 task.Branch,不是从任务 ID 派生)

type Result

type Result struct {
	Branch  string
	Commits int
	Created bool
}

Result 是一次同步的结果。

  • Branch: 同步的分支名
  • Commits: 相对同步前本地分支尖端新增的提交数;Created=true 时为 0(无基准可比)
  • Created: 本地此前没有该分支,本次新建

func Fetch

func Fetch(ctx context.Context, o Opts) (Result, error)

Fetch 把远程任务分支同步到本地同名分支。

参数:

  • ctx: 上层上下文;内部叠加 FetchTimeout
  • o: 同步参数,见 Opts

返回:

  • Result: 同步增量
  • err: LocalRepo 不是 git 仓库、参数非法、ssh/网络失败、或本地分支与远程分叉 (非快进)时返回错误,错误文本含 git stderr 原文

注意:

  • 非快进由 git 自身拒绝(fetch <src>:<dst> 的默认语义),这正是要的行为—— 宁可报错也不能悄悄覆盖协调者的本地提交

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL