Documentation
¶
Index ¶
- Variables
- func Clone(remote, dest string) error
- type Error
- type Info
- type Repo
- func (r *Repo) Add(paths ...string) error
- func (r *Repo) AddRemote(name, url string) error
- func (r *Repo) Commit(message string) (string, error)
- func (r *Repo) CurrentBranch() (string, error)
- func (r *Repo) HasUncommittedChanges() (bool, error)
- func (r *Repo) HasUnpulledChanges() (bool, error)
- func (r *Repo) IsEmpty() (bool, error)
- func (r *Repo) Mv(from, to string) error
- func (r *Repo) Pull() error
- func (r *Repo) Push() error
- func (r *Repo) PushSetUpstream(remote, branch string) error
- func (r *Repo) RemoteHasContent(remote string) (bool, error)
- func (r *Repo) WriteGitattributes(content string) error
Constants ¶
This section is empty.
Variables ¶
var ErrNotARepo = errors.New("not inside a git repository")
Functions ¶
Types ¶
type Error ¶
Error wraps a failed git invocation with the command line and the captured stderr. Returned (wrapped) by every method on *Repo when the underlying `git` exits non-zero.
type Info ¶
type Info struct {
Root string // absolute path
Name string // basename of root
RemoteURL string // empty if no origin configured
}
type Repo ¶
type Repo struct {
Root string
}
Repo wraps a local git working tree at Root. Every method shells out to `git` via os/exec, matching detect.go's existing pattern. We don't pull in go-git for two reasons: (1) sync repos are small, the cost of the subprocess is negligible, and (2) `git` is already on every developer's PATH and behaves the same as the user's manual invocations — handy for debugging.
Errors from each method wrap stderr from git via *Error so callers can `errors.As` the wrapped form to surface the original command and stderr without re-shelling.
func Init ¶
Init runs `git init -b main` at path and returns a *Repo bound to it. The directory is created if it doesn't yet exist. We pin the initial branch to `main` so sync repos look the same regardless of the user's `init.defaultBranch` (Linux/older git defaults to `master`, which mismatches the bare remote we push to and produces an empty checkout for the next cloner).
func Open ¶
Open returns a *Repo at path if it contains a .git directory or file (a worktree pointer). Errors with ErrNotARepo otherwise so callers can distinguish "not a repo" from "filesystem error".
func (*Repo) Add ¶
Add runs `git add` on the supplied paths. With no paths, equivalent to `git add -A`.
func (*Repo) Commit ¶
Commit runs `git commit -m <message>` and returns the resulting SHA. If the index has no staged changes, returns ("", nil) so the caller can distinguish "nothing to commit" from a hard error.
func (*Repo) CurrentBranch ¶
CurrentBranch returns the name of the currently checked-out branch (e.g. "main", "master", or whatever the user's `init.defaultBranch` resolved to). Used so we don't hardcode "main" when push --set-upstream runs after `git init`.
func (*Repo) HasUncommittedChanges ¶
HasUncommittedChanges reports whether the working tree or index has any uncommitted changes. `git status --porcelain` produces no output on a clean tree.
func (*Repo) HasUnpulledChanges ¶
HasUnpulledChanges reports whether the upstream branch has commits not yet present locally. Best-effort — if the repo has no upstream configured (e.g., immediately after `git init` and before the first push), returns false with no error.
func (*Repo) IsEmpty ¶
IsEmpty reports whether the repository has no commits at all. Detected by `git rev-parse HEAD` failing — the canonical "no commits yet" signal in git.
func (*Repo) Mv ¶
Mv runs `git mv <from> <to>`. The caller is responsible for any parent-directory creation on the new side; git mv will fail if the parent doesn't exist.
func (*Repo) Pull ¶
Pull runs a fast-forward-only `git pull --ff-only`. We use ff-only rather than allowing merge so a sync race that produces a true conflict surfaces immediately rather than silently merging in the background.
func (*Repo) PushSetUpstream ¶
PushSetUpstream runs `git push --set-upstream <remote> <branch>`. Used on first push from `bacio sync init` so subsequent `git push` invocations have a tracking branch.
func (*Repo) RemoteHasContent ¶
RemoteHasContent reports whether the named remote currently has any branch heads. Used by `bacio sync init` to refuse to bootstrap against a populated remote.
func (*Repo) WriteGitattributes ¶
WriteGitattributes writes the supplied content to .gitattributes at the repo root. Used by `bacio sync init` to pin LF line endings (`* -text`) so git's autocrlf doesn't rewrite the canonical YAML on Windows checkouts.