gitexec

package
v1.2.33 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: AGPL-3.0, AGPL-3.0-or-later Imports: 13 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Archive added in v1.2.21

func Archive(repoPath, ref, format string) ([]byte, error)

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

func CloneMirror(ctx context.Context, path, sourceURL string) error

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

func CommitDiff(repoPath, hash string) (diff string, truncated bool, err error)

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

func CountCommits(repoPath string) (count int, found bool, err error)

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

func CountContributors(repoPath string) (count int, found bool, err error)

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

func DefaultBranchName(repoPath string) (string, bool)

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

func DiskUsage(repoPath string) (int64, error)

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

func DominantLanguage(repoPath string) (language string, found bool, err error)

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

func InitBareRepo(path string) error

InitBareRepo creates a new bare repository at path if it doesn't exist.

func ListBranches

func ListBranches(repoPath string) ([]string, error)

ListBranches returns the repo's branch names, alphabetically.

func ListTags

func ListTags(repoPath string) ([]string, error)

ListTags returns the repo's git tags, most recently created first.

func ReadFileAtHEAD

func ReadFileAtHEAD(repoPath, filename string) (content string, found bool, err error)

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

func ReadFileAtRef(repoPath, ref, filename string) (content string, found bool, err error)

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

func ResolvePath(reposRoot, repoName string) (string, error)

ResolvePath maps a repo name to its bare-repo path under reposRoot.

func Serve

func Serve(verb Verb, path string, stdin io.Reader, stdout, stderr io.Writer) error

Serve runs the requested git service against path, wiring stdin/stdout to the SSH channel and stderr to the given writer.

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

func ListCommits(repoPath string, limit int) (commits []Commit, found bool, err error)

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

func ListCommitsPage(repoPath string, limit, offset int) (commits []Commit, found bool, err error)

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

type MergeResult struct {
	Clean         bool
	ConflictFiles []string
}

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

func ListTree(repoPath, path string) (entries []TreeEntry, found bool, err error)

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.

func ListTreeAtRef added in v1.2.18

func ListTreeAtRef(repoPath, ref, path string) (entries []TreeEntry, found bool, err error)

ListTreeAtRef is ListTree against an explicit ref instead of the repo's default branch — same caller-must-validate-ref contract as ReadFileAtRef.

type Verb

type Verb string

Verb identifies which git service was requested.

const (
	UploadPack  Verb = "git-upload-pack"
	ReceivePack Verb = "git-receive-pack"
)

func ParseCommand

func ParseCommand(cmd string) (Verb, string, error)

ParseCommand parses an SSH exec command line such as `git-upload-pack 'alice/repo.git'` or `git upload-pack 'alice/repo.git'` (both forms are accepted by real git clients) into a verb and repo name.

Source Files

  • gitexec.go

Jump to

Keyboard shortcuts

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