Help us shape the future of Go! Take the 2026 Go Developer Survey

git

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrPathEscape = errors.New("git: path escapes novel directory")

Functions

func ChapterPath

func ChapterPath(num int) string

── 文件路径 ────────────────────────────────────────────── 此处都是相对路径,位于小说目录之下的,小说目录由config决定

func CoverPath

func CoverPath() string

func GoinkPath

func GoinkPath() string

func OutlinePath

func OutlinePath(num int) string

func PlanPath

func PlanPath(scope string) string

func ReadFile

func ReadFile(novelID int64, path string) (string, error)

func ResolvePath

func ResolvePath(path string, novelID int64) (string, error)

ResolvePath 将用户输入路径解析为真实文件系统路径。 ~/.goink/ 展开到用户目录;其他相对路径基于小说目录。

func SafePath

func SafePath(base, rel string) (string, error)

SafePath 对给定的上级目录和相对路径求最终路径,如果路径跳出上级目录则返回 error。

func WriteFile

func WriteFile(novelID int64, path, content string) error

Types

type CommitInfo

type CommitInfo struct {
	Hash         string    `json:"hash"`
	ShortHash    string    `json:"shortHash"`
	Message      string    `json:"message"`
	Time         time.Time `json:"time"`
	AuthorName   string    `json:"authorName"`
	AuthorEmail  string    `json:"authorEmail"`
	FilesChanged int       `json:"filesChanged"`
	Insertions   int       `json:"insertions"`
	Deletions    int       `json:"deletions"`
}

CommitInfo 是 git log 的单条记录。

type FileDiff

type FileDiff struct {
	Path            string `json:"path"`
	ChangeType      string `json:"changeType"`
	OriginalContent string `json:"original"`
	ModifiedContent string `json:"modified"`
}

FileDiff 表示一次 commit 中单个文件的变更。

type FileEntry

type FileEntry struct {
	Path       string `json:"path"`
	ChangeType string `json:"changeType"` // "added" | "modified" | "deleted" | "renamed"
	OldPath    string `json:"oldPath"`    // 仅 renamed 时有值,表示重命名前的路径
}

FileEntry 表示 commit 中一个变更文件的简要信息(不含内容)。

type Repo

type Repo struct {
	// contains filtered or unexported fields
}

Repo 管理单部小说的 Git 仓库,提供文件读写和版本控制。

func New

func New(novelID int64, gitName, gitEmail string, logger *slog.Logger) (*Repo, error)

New 为指定小说打开已有仓库,不存在则 git init + 首次空 commit。 gitName 和 gitEmail 用于设置仓库级 git config。空字符串时使用默认值。 logger 为 nil 时使用 slog.Default()。

func (*Repo) Commit

func (r *Repo) Commit(msg string) (string, error)

func (*Repo) CommitFileList

func (r *Repo) CommitFileList(hash string) (*CommitInfo, []FileEntry, error)

CommitFileList 返回指定 commit 的详细信息和变更文件列表(不含文件内容)。

func (*Repo) DiffContent

func (r *Repo) DiffContent(relPath, proposed string) (string, error)

DiffContent 对比当前工作区文件与 proposed 内容,返回 unified diff。 文件不存在时以空内容为基准。用临时文件 + git diff --no-index 实现。

func (*Repo) HasUncommitted

func (r *Repo) HasUncommitted() (bool, error)

func (*Repo) Log

func (r *Repo) Log(relPath string, n int) ([]CommitInfo, error)

func (*Repo) LogDetailed

func (r *Repo) LogDetailed(n int, afterHash string) ([]CommitInfo, error)

LogDetailed 返回带详细统计的提交历史,按时间降序(最新在前)。 afterHash 非空时,返回该 commit 之后的更早提交(基于 git log <afterHash> --skip=1)。

func (*Repo) RevertAbort

func (r *Repo) RevertAbort() error

RevertAbort 取消进行中的 revert,丢弃所有暂存的 revert 内容。

func (*Repo) RevertNoCommit

func (r *Repo) RevertNoCommit(hashes []string) error

RevertNoCommit 逆序 revert 所有 hash,仅暂存不提交。冲突时自动 abort。 调用方负责最终 commit(或 abort)。

func (*Repo) SetGitConfig

func (r *Repo) SetGitConfig(gitName, gitEmail string) error

SetGitConfig 在已有仓库上更新仓库级 user.name / user.email 配置。

func (*Repo) ShowFile

func (r *Repo) ShowFile(hash, filePath string) (*FileDiff, error)

ShowFile 返回指定 commit 中某个文件的前后内容。 对于 added 文件 original 为空,对于 deleted 文件 modified 为空。

func (*Repo) StageAll

func (r *Repo) StageAll() error

Jump to

Keyboard shortcuts

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