gitops

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package gitops 封裝所有 git 操作,根據 workspace config 決定 monorepo 或 multi-repo 模式。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Branch

func Branch(featureID string) string

Branch 回傳 feature 對應的 branch 名稱(兩種模式共用)。

func CopyFileIfExists

func CopyFileIfExists(src, dst string) error

CopyFileIfExists 複製檔案,來源不存在時靜默忽略(回 nil);讀寫失敗回傳 error。供外部 package 使用。

func CopyFileIfNewer

func CopyFileIfNewer(src, dst string) (copied bool, err error)

CopyFileIfNewer 僅在來源比目標新(或目標不存在)時複製,用於差量化 worktree sync, 避免每輪 final sync 與每 2 秒 live-sync 對未變更檔案重複全量複製。 回傳是否實際複製、以及錯誤;來源不存在視為靜默成功(false, nil)。 比對採 mtime-only:dst 不存在則複製;兩者皆存在時 srcInfo.ModTime().After(dstInfo.ModTime()) 才複製。

func Dir

func Dir(root, featureID string) string

Dir 回傳 worktree 組合目錄的路徑(兩種模式共用)。

func ScopeRoot added in v0.1.13

func ScopeRoot(fallback, featureID string) string

ScopeRoot 回傳掃描 feature scope 變更時應使用的根目錄。 若 feature 的 worktree 目錄存在且確為 linked worktree,回傳其 top-level 根目錄; 否則回退到 fallback(通常為 main workspace 根),維持非 worktree 情境的既有行為。

Types

type MergeResult

type MergeResult struct {
	Skipped      bool
	Conflict     bool
	Error        string
	Files        []string
	ConflictRepo string
}

MergeResult 描述 Merge 操作的結果。

type Ops

type Ops interface {
	SetupWorktree(featureID string, featureRepos []string) (wtRoot string, err error)
	Commit(wtRoot, featureID, msg string) error
	Merge(featureID, featureName string) MergeResult
	Cleanup(featureID string) error
	DetectChangedRepos(featureID string) []string
	DetectChangedFiles(featureID string) []protocol.ChangedFile
	CaptureBaseline(featureID string, featureRepos []string) error
	IsMultiRepo() bool
}

Ops 封裝所有 git 操作,根據 workspace config 決定 monorepo 或 multi-repo 模式。

func New

func New(root string, ws *protocol.Workspace, cfg protocol.Config) Ops

New 根據 workspace config 建立對應的 Ops 實作。

type WorktreeInfo added in v0.1.13

type WorktreeInfo struct {
	// Root 是該目錄所屬 worktree 的 top-level 根目錄(git rev-parse --show-toplevel)。
	Root string
	// IsLinked 為 true 表示這是 git worktree add 產生的 linked worktree;
	// false 表示主工作區(main working tree)。
	IsLinked bool
}

WorktreeInfo 描述某個目錄所屬的 git worktree 狀態。

func DetectWorktree added in v0.1.13

func DetectWorktree(dir string) (WorktreeInfo, bool)

DetectWorktree 偵測 dir 所屬的 git worktree,回傳其 top-level 根目錄與是否為 linked worktree。

scope 檢查在 worktree 隔離模式下,git 操作的根目錄會被解析到 main workspace, 導致誤把 main 的未提交變更算進 feature 的 changed repos。此 helper 讓呼叫端能 把 git 操作限定在 worktree 自身的根目錄。

判定方式:以 git rev-parse --git-dir 與 --git-common-dir 是否相異判定是否為 linked worktree(linked worktree 的 git-dir 指向 <common>/.git/worktrees/<name>,與 common dir 不同)。dir 不在 git repo 內時回傳 ok=false。

Jump to

Keyboard shortcuts

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