git

package
v1.801.7 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: Apache-2.0 Imports: 42 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 Mount

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

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

func Shutdown

func Shutdown() error

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

Types

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) Close

func (s *Store) Close() error

Close closes the underlying database.

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) 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