git

package
v1.801.30 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: Apache-2.0 Imports: 47 Imported by: 0

Documentation

Overview

Package git mounts the Hanzo Cloud /v1/git surface: S3-backed Git hosting native in the unified cloud binary — Hanzo Git, the internal git host foundation agents push code into.

A repo is the Git LAYER (source code, buildable/deployable) that lives UNDER an IAM project. It is NOT the IAM project itself: `project` is org-scoping CONTEXT (org → project → env); a repo is scoped BY that context. Every repo belongs to exactly one org (the gateway-minted X-Org-Id, HIP-0026) and an optional project sub-scope (X-Project-Id), enforced on every query, so one org can never read, clone, push to, or delete another's repos.

Surface:

POST   /v1/git/repos            create a bare repo            -> repoView (201)
GET    /v1/git/repos            list the org's repos       -> {data:[repoView]}
GET    /v1/git/repos/:name      repo detail (branches, HEAD)  -> repoView
DELETE /v1/git/repos/:name      delete + purge storage        -> 204
GET    /v1/git/usage            per-repo + total bytes        -> usageView

Smart-HTTP git protocol (so `git clone` / `git push` work natively):

GET  /v1/git/:org/:repo/info/refs?service=git-upload-pack|git-receive-pack
POST /v1/git/:org/:repo/git-upload-pack     (clone/fetch)
POST /v1/git/:org/:repo/git-receive-pack    (push)

Storage is bare git repos on a real filesystem (osfs) rooted under {DataDir}/git; go-git initializes + reads them, while the heavy clone/push/ mirror paths stream through the `git` CLI (gitexec.go) so multi-GB packs stay bounded in memory. See storage.go for the hanzoai/vfs (S3) storage seam.

Billing: every repo tracks sizeBytes, re-measured on create and after each push. /v1/git/usage exposes per-repo + total bytes per org, and each measurement emits a "git.usage" log line a metering consumer can bill on.

ui.go — Hanzo Git's web UI: the browser surface of the embedded, IAM-native git host. Server-rendered HTML in the ONE cloud binary (no separate app, no stock git-host image), reading the SAME org-scoped store + go-git object storage the API/protocol handlers use. This is what lets git.hanzo.ai retire the standalone git web app: repo list, repo home, tree browse, file view, commit log — all native.

Isolation is identical to the rest of git: every page is scoped to the gateway-minted, IAM-VALIDATED X-Org-Id (org(c)); the :org path segment MUST equal the caller's own org, so the UI can never browse another tenant's repos. html/template auto-escaping is the XSS boundary — repo names, paths, and file contents are all rendered through it, never concatenated into HTML.

Routes (browser, distinct from the /v1/git API + smart-HTTP protocol):

GET /git                         the caller's org repo list (home)
GET /git/:org/:repo              repo home: branches, HEAD, root tree, clone
GET /git/:org/:repo/tree/*?ref=  browse a subtree
GET /git/:org/:repo/blob/*?ref=  view a file
GET /git/:org/:repo/commits?ref= commit log

ui_templates.go — the Hanzo Git UI's view layer: data shapes, the render() helper, and the html/template set (chrome + pages). Kept apart from ui.go so the handlers read as flow and the markup lives in one place. All dynamic values pass through html/template auto-escaping — the XSS boundary.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloneURL added in v1.801.23

func CloneURL(org, name string) string

CloneURL returns the HTTPS smart-HTTP clone URL for an org's repo (https://<domain>/v1/git/<org>/<repo>.git) — the exact URL the git handlers serve. Empty when git is not mounted. The credential is NEVER embedded here; the sandbox presents it out of band (env-fed http.extraHeader), so this URL is safe to log and to hand to a subprocess on argv.

func IndexRepoActivity added in v1.801.23

func IndexRepoActivity(ctx context.Context, in indexInput) error

IndexRepoActivity is the durable index step: read the repo tip's tree from the object plane and fold its text files into the org's code index. Idempotent (full-tree reconcile with prune), so a retry or redelivery re-converges. Exported for worker registration; not called directly.

func IndexRepoWorkflow added in v1.801.23

func IndexRepoWorkflow(ctx workflow.Context, in indexInput) error

IndexRepoWorkflow indexes one repo's pushed tip as a single durable activity, with retry/backoff. Exported for worker registration; not called directly.

func Mount

func Mount(app *zip.App, deps cloud.Deps) error

Mount wires the git surface onto app per HIP-0106.

func SetIndexer added in v1.801.23

func SetIndexer(fn Indexer)

SetIndexer injects the code-index reactor. The composition root calls it once, after the git and code subsystems both mount. Nil leaves push-index inert.

func Shutdown

func Shutdown() error

Shutdown stops the SSH listener and closes every open store (per-org repo metadata + the SSH key registry). Idempotent.

func VerifyRef added in v1.801.23

func VerifyRef(ctx context.Context, org, repo, branch string) (sha string, ok bool)

VerifyRef reports the tip commit of branch in an org's repo, reading the on-disk bare repo directly (the shared git storage every cloud replica mounts). It is the independent, in-process confirmation that a branch a sandbox claims to have pushed actually LANDED in native git — cloud trusts the branch tips it can read, not the remote runner's self-report. ok is false when git is unmounted, the repo/branch is absent, or the read fails (fail-closed: an unverifiable ref is treated as absent).

Types

type IndexedFile added in v1.801.23

type IndexedFile struct {
	Path    string
	Content string
}

IndexedFile is one text file handed across the seam to the code index: its repo-relative path and content.

type Indexer added in v1.801.23

type Indexer func(ctx context.Context, org, billingOrg, project, repo string, files []IndexedFile) error

Indexer folds a pushed repo's text files into the code-intelligence index. Injected at the composition root so the git plane stays free of a clients/code import (the two planes never import each other).

type MirrorTarget added in v1.800.1

type MirrorTarget struct {
	ID        string
	Org       string
	Project   string
	Repo      string
	Host      string
	URL       string
	CreatedAt int64
}

MirrorTarget is a downstream remote a repo's advanced refs are mirrored to (GitHub/GitLab/self). Keyed by (org, repo, host): one target per host per repo.

type Repo

type Repo struct {
	ID            string
	Org           string
	Project       string // may be "" (org-level repo)
	Name          string
	Description   string
	DefaultBranch string
	SizeBytes     int64
	CreatedAt     int64
	UpdatedAt     int64
}

Repo is the org-scoped, canonical metadata record for one Git repository. Org isolation is the (org, project) pair, enforced at the query layer; the gateway-minted X-Org-Id (HIP-0026) selects the org and X-Project-Id an optional sub-scope. The repo's OBJECTS (packs, refs) live on the billy-backed storage under the same (org, project, name) path — this row is only the metadata + the last-measured storage size that commerce meters on.

type Store

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

Store is one org's repo-metadata database — ONE SQLite file per org at {DataDir}/orgs/{orgSlug}/git.db (opened via cloud.OrgDB). git is org-scoped, not project-scoped: /v1/git/usage is a deliberate org-wide rollup across every project, so the physical boundary is the org and the (optional) project is a row column. MaxOpenConns(1) serializes writes against the file lock.

func (*Store) ClearConflict added in v1.801.23

func (s *Store) ClearConflict(ctx context.Context, org, project, repo, branch string) error

ClearConflict removes one branch's divergence marker — a later ff-apply reconciled it. Idempotent (no row ⇒ no-op).

func (*Store) ClearRepoConflicts added in v1.801.23

func (s *Store) ClearRepoConflicts(ctx context.Context, org, project, repo string) error

ClearRepoConflicts removes every branch's divergence marker for a repo — a full re-import force-fetches every ref, reconciling the repo wholesale. Idempotent.

func (*Store) Close

func (s *Store) Close() error

Close closes the underlying database.

func (*Store) ConflictRepoSet added in v1.801.23

func (s *Store) ConflictRepoSet(ctx context.Context, org, project string) (map[string]bool, error)

ConflictRepoSet returns the set of repos (by name) with ≥1 unresolved inbound conflict in (org, project) — one query backing the repo-list status roll-up.

func (*Store) Create

func (s *Store) Create(ctx context.Context, r Repo) error

Create inserts a new repo row. Returns errConflict when (org,project,name) already exists in the org.

func (*Store) CreateMirror added in v1.800.1

func (s *Store) CreateMirror(ctx context.Context, v MirrorTarget) error

CreateMirror inserts a mirror target. errConflict when (org,repo,host) exists.

func (*Store) CreateSubscription added in v1.800.1

func (s *Store) CreateSubscription(ctx context.Context, v Subscription) error

CreateSubscription inserts a subscription. errConflict when (org,repo,channel) already exists — one repo can subscribe a given channel exactly once.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, org, project, name string) (bool, error)

Delete removes a repo row AND cascade-deletes its lifecycle config (subscriptions + mirror targets) in one transaction, so a deleted repo can never leave an orphaned external mirror target that a re-created repo of the same name would silently inherit (Red MED-3: exfil-on-recreate). Reports whether the repo row went.

func (*Store) DeleteMirror added in v1.800.1

func (s *Store) DeleteMirror(ctx context.Context, org, project, repo, id string) (bool, error)

DeleteMirror removes a mirror target by (org, project, repo, id). Reports whether a row went.

func (*Store) DeleteSubscription added in v1.800.1

func (s *Store) DeleteSubscription(ctx context.Context, org, project, repo, id string) (bool, error)

DeleteSubscription removes a subscription by (org, project, repo, id) — a caller may only delete their own org's subscription of the named repo IN SCOPE. Reports whether a row went.

func (*Store) Get

func (s *Store) Get(ctx context.Context, org, project, name string) (Repo, error)

Get returns the repo for (org,project,name) or errNotFound.

func (*Store) List

func (s *Store) List(ctx context.Context, org, project string) ([]Repo, error)

List returns every repo for (org,project), most-recently-updated first.

func (*Store) ListMirrors added in v1.800.1

func (s *Store) ListMirrors(ctx context.Context, org, project, repo string) ([]MirrorTarget, error)

ListMirrors returns every mirror target for the repo (org, project, repo), newest first.

func (*Store) ListOrg

func (s *Store) ListOrg(ctx context.Context, org string) ([]Repo, error)

ListOrg returns every repo across ALL projects for org (usage rollup), most-recently-updated first.

func (*Store) ListSubscriptions added in v1.800.1

func (s *Store) ListSubscriptions(ctx context.Context, org, project, repo string) ([]Subscription, error)

ListSubscriptions returns every subscription for the repo (org, project, repo), newest first.

func (*Store) RecordConflict added in v1.801.23

func (s *Store) RecordConflict(ctx context.Context, org, project, repo, branch, detail string, at int64) error

RecordConflict upserts the divergence marker for one branch: the upstream push could not fast-forward native, so native was preserved and this row records the split-brain for the console + operator. Upsert (not insert) so a repeated diverging push refreshes the detail/timestamp instead of erroring.

func (*Store) SetSize

func (s *Store) SetSize(ctx context.Context, org, project, name string, sizeBytes, updatedAt int64) error

SetSize records the last-measured storage size for a repo and bumps updated_at. Called on create and after each push, so the metered number is always the real on-disk size, never a fabricated rollup.

type Subscription added in v1.800.1

type Subscription struct {
	ID        string
	Org       string
	Project   string
	Repo      string
	Channel   string
	Events    string
	CreatedAt int64
}

Subscription binds a repo (by org+name) to a Slack channel for lifecycle notifications. Events is a CSV of LifecycleKind wire names; "" means every supported kind. Project is the scope it was created in (display only) — routing keys on (org, repo).

Jump to

Keyboard shortcuts

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