Documentation
¶
Overview ¶
Package gitexec wraps git-upload-pack / git-receive-pack as subprocesses, per DESIGN.md §8 ("pas de réécriture du protocole git : on wrappe git-receive-pack / git-upload-pack").
Index ¶
- func Archive(repoPath, ref, format string) ([]byte, error)
- func CloneMirror(ctx context.Context, path, sourceURL string) error
- func CommitDiff(repoPath, hash string) (diff string, truncated bool, err error)
- func CountCommits(repoPath string) (count int, found bool, err error)
- func CountContributors(repoPath string) (count int, found bool, err error)
- func DefaultBranchName(repoPath string) (string, bool)
- func DiskUsage(repoPath string) (int64, error)
- func DominantLanguage(repoPath string) (language string, found bool, err error)
- func InitBareRepo(path string) error
- func ListBranches(repoPath string) ([]string, error)
- func ListTags(repoPath string) ([]string, error)
- func ReadFileAtHEAD(repoPath, filename string) (content string, found bool, err error)
- func ReadFileAtRef(repoPath, ref, filename string) (content string, found bool, err error)
- func ResolvePath(reposRoot, repoName string) (string, error)
- func Serve(verb Verb, path string, stdin io.Reader, stdout, stderr io.Writer) error
- type Commit
- type CommitDetail
- type DiffFile
- type MergeResult
- type TreeEntry
- type Verb
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Archive ¶ added in v1.2.21
Archive returns a tar.gz or zip snapshot of ref (a branch or tag name — the caller is responsible for ref being real, same contract as ListTreeAtRef/ReadFileAtRef) via `git archive`, hardened with --end-of-options for the same reason as everywhere else a ref reaches a git subprocess.
func CloneMirror ¶
CloneMirror clones the repository at sourceURL into a new bare repo at path (one-shot import — see ROADMAP.md §3, "distinguished from continuous mirroring"), then drops the resulting "origin" remote so the bare repo never tries to re-contact the source on its own; nothing here ever fetches from it again. The caller must validate sourceURL first (scheme, host) — this only adds --end-of-options so a hostile URL starting with "-" can't be reinterpreted as a git flag, the same defense used everywhere else a user-controlled string reaches a git subprocess.
func CommitDiff ¶
CommitDiff returns the unified diff patch text for a commit (all files), capped at commitDiffMaxLines lines. truncated reports whether the cap was hit.
func CountCommits ¶ added in v1.2.11
CountCommits returns how many commits are reachable from the repo's default branch (see resolveDefaultRef). found is false (nil error) for a repo with no commits yet, matching ListCommits's contract.
func CountContributors ¶ added in v1.2.22
CountContributors returns the number of distinct commit authors (by email — the same identity git itself groups by) reachable from the repo's default branch. found is false (nil error) for a repo with no commits yet, same contract as CountCommits.
func DefaultBranchName ¶
DefaultBranchName returns the short branch name (e.g. "main") backing resolveDefaultRef, for display purposes. ok is false under the same conditions as resolveDefaultRef.
func DiskUsage ¶ added in v1.2.29
DiskUsage returns the total size in bytes of every regular file under repoPath. Repos are always bare (see InitBareRepo) — the whole directory *is* the repo's storage (packfiles, refs, objects), there's no separate working tree to exclude.
func DominantLanguage ¶ added in v1.2.22
DominantLanguage returns the most common recognized programming language among the files in the repo's default-branch tree, counted by file count (not byte size — simpler, and consistent with this being a cosmetic estimate, not a real linguist-style analysis). found is false (nil error) for an empty repo or one with no recognized-language files (e.g. all Markdown/config).
func InitBareRepo ¶
InitBareRepo creates a new bare repository at path if it doesn't exist.
func ListBranches ¶
ListBranches returns the repo's branch names, alphabetically.
func ListTags ¶
ListTags returns the repo's git tags, most recently created first.
func ReadFileAtHEAD ¶
ReadFileAtHEAD returns the content of filename as it exists in the tree at the repo's default branch (see resolveDefaultRef). found is false (with a nil error) if the repo has no commits yet or the file doesn't exist there — both are expected, unremarkable states for e.g. an optional README.
func ReadFileAtRef ¶ added in v1.2.18
ReadFileAtRef is ReadFileAtHEAD against an explicit ref (e.g. a non-default branch someone picked from the repo page's branch dropdown) instead of the repo's default branch. The caller is responsible for ref being a real, known ref (e.g. checked against ListBranches) — --end-of-options is only defense in depth against a dash-prefixed value being reinterpreted as a git flag, not a substitute for that check.
func ResolvePath ¶
ResolvePath maps a repo name to its bare-repo path under reposRoot.
Types ¶
type Commit ¶
type Commit struct {
Hash string `json:"hash"`
ShortHash string `json:"short_hash"`
Author string `json:"author"`
Email string `json:"email"`
Date time.Time `json:"date"`
Subject string `json:"subject"` // first line of the commit message only
}
Commit is one entry in a repo's history, as shown by ListCommits.
func ListCommits ¶
ListCommits returns up to limit commits reachable from the repo's default branch (see resolveDefaultRef), most recent first. found is false (nil error) for a repo with no commits yet.
func ListCommitsPage ¶ added in v1.2.24
ListCommitsPage is ListCommits with an additional offset (via `git log --skip=`), for the commits page's pagination — most recent first, so offset 0 is always the newest page regardless of how many commits have landed since a caller last asked.
type CommitDetail ¶
type CommitDetail struct {
Commit
Body string // commit message with the subject line removed, trimmed
Parents []string // full parent hashes, empty for a root commit
Files []DiffFile
}
CommitDetail is a single commit's full metadata plus the files it changed.
func ShowCommit ¶
func ShowCommit(repoPath, hash string) (detail CommitDetail, found bool, err error)
ShowCommit returns a commit's full metadata and changed-file summary. found is false (nil error) if hash doesn't resolve to a commit in repoPath.
type DiffFile ¶
type DiffFile struct {
Path string
Status string // "added", "modified", "deleted", "renamed", "copied"
Insertions int
Deletions int
Binary bool
}
DiffFile summarizes one file changed by a commit.
func BranchDiff ¶
func BranchDiff(repoPath, target, source string) (files []DiffFile, diff string, truncated bool, found bool, err error)
BranchDiff returns the changed-file summary and unified diff patch for what merging source into target would introduce — diffed against their merge base (git's "..." range), the same comparison a merge itself would make, not a flat two-tree diff. found is false (nil error) if either branch doesn't exist.
type MergeResult ¶
MergeResult reports the outcome of a mergeability check or an attempted merge: either Clean, or blocked with the specific files that conflict.
func CheckMergeable ¶
func CheckMergeable(repoPath, target, source string) (MergeResult, error)
CheckMergeable reports whether source merges cleanly into target, without touching any real ref — the attempt happens in a scratch worktree that's discarded either way.
func MergeBranches ¶
func MergeBranches(repoPath, target, source, message, authorName, authorEmail string) (mergeCommit string, result MergeResult, err error)
MergeBranches merges source into target with a real merge commit (always --no-ff, so the merge is traceable even when a fast-forward would have sufficed) and atomically updates refs/heads/target via compare-and-swap: if target moved (e.g. a concurrent push) between the merge being computed and the ref update, the update is rejected instead of silently discarding that commit. The merge itself happens in a scratch worktree so target's checked-out state, if any, is never touched directly.
type TreeEntry ¶
type TreeEntry struct {
Name string `json:"name"`
Type string `json:"type"` // "blob" (file) or "tree" (directory)
}
TreeEntry is one immediate child of a directory in the repo's tree.
func ListTree ¶
ListTree returns the immediate children (files and directories) at path in the tree at the repo's default branch (see resolveDefaultRef), directories first then files, alphabetically within each. path == "" lists the repo root. found is false (nil error) for an empty repo or a path that doesn't exist — both unremarkable.
Source Files
¶
- gitexec.go