Documentation
¶
Index ¶
- Variables
- func ChapterPath(num int) string
- func CoverPath() string
- func GoinkPath() string
- func OutlinePath(num int) string
- func PlanPath(scope string) string
- func ReadFile(novelID int64, path string) (string, error)
- func ResolvePath(path string, novelID int64) (string, error)
- func SafePath(base, rel string) (string, error)
- func WriteFile(novelID int64, path, content string) error
- type CommitInfo
- type FileDiff
- type FileEntry
- type Repo
- func (r *Repo) Commit(msg string) (string, error)
- func (r *Repo) CommitFileList(hash string) (*CommitInfo, []FileEntry, error)
- func (r *Repo) DiffContent(relPath, proposed string) (string, error)
- func (r *Repo) HasUncommitted() (bool, error)
- func (r *Repo) Log(relPath string, n int) ([]CommitInfo, error)
- func (r *Repo) LogDetailed(n int, afterHash string) ([]CommitInfo, error)
- func (r *Repo) RevertAbort() error
- func (r *Repo) RevertNoCommit(hashes []string) error
- func (r *Repo) SetGitConfig(gitName, gitEmail string) error
- func (r *Repo) ShowFile(hash, filePath string) (*FileDiff, error)
- func (r *Repo) StageAll() error
Constants ¶
This section is empty.
Variables ¶
var ErrPathEscape = errors.New("git: path escapes novel directory")
Functions ¶
func ChapterPath ¶
── 文件路径 ────────────────────────────────────────────── 此处都是相对路径,位于小说目录之下的,小说目录由config决定
func OutlinePath ¶
func ResolvePath ¶
ResolvePath 将用户输入路径解析为真实文件系统路径。 ~/.goink/ 展开到用户目录;其他相对路径基于小说目录。
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 ¶
New 为指定小说打开已有仓库,不存在则 git init + 首次空 commit。 gitName 和 gitEmail 用于设置仓库级 git config。空字符串时使用默认值。 logger 为 nil 时使用 slog.Default()。
func (*Repo) CommitFileList ¶
func (r *Repo) CommitFileList(hash string) (*CommitInfo, []FileEntry, error)
CommitFileList 返回指定 commit 的详细信息和变更文件列表(不含文件内容)。
func (*Repo) DiffContent ¶
DiffContent 对比当前工作区文件与 proposed 内容,返回 unified diff。 文件不存在时以空内容为基准。用临时文件 + git diff --no-index 实现。
func (*Repo) HasUncommitted ¶
func (*Repo) LogDetailed ¶
func (r *Repo) LogDetailed(n int, afterHash string) ([]CommitInfo, error)
LogDetailed 返回带详细统计的提交历史,按时间降序(最新在前)。 afterHash 非空时,返回该 commit 之后的更早提交(基于 git log <afterHash> --skip=1)。
func (*Repo) RevertAbort ¶
RevertAbort 取消进行中的 revert,丢弃所有暂存的 revert 内容。
func (*Repo) RevertNoCommit ¶
RevertNoCommit 逆序 revert 所有 hash,仅暂存不提交。冲突时自动 abort。 调用方负责最终 commit(或 abort)。
func (*Repo) SetGitConfig ¶
SetGitConfig 在已有仓库上更新仓库级 user.name / user.email 配置。