git_gate
git_gate
¶
Host-side git gate (mirror) management and upstream comparison.
The git gate is a bare mirror of the upstream repository stored on the host. In gatekeeping mode, it is the only repository the container can access, enforcing human review before changes reach upstream. In online mode, it serves as a read-only clone accelerator (faster than cloning over the network).
:class:GitGate is the main service class — wraps git CLI operations for
syncing, comparing, and querying the mirror.
All constructor parameters are plain values (strings, paths) — no
terok-specific types like ProjectConfig.
Value types returned by GitGate methods:
- :class:
GateSyncResult— full sync outcome (created, updated branches, errors) - :class:
BranchSyncResult— selective branch sync outcome - :class:
CommitInfo— single commit metadata (hash, date, author, message) - :class:
GateStalenessInfo— frozen comparison of gate HEAD vs upstream HEAD
GateSyncResult
¶
Bases: TypedDict
Result of a full gate sync operation.
BranchSyncResult
¶
Bases: TypedDict
Result of a branch sync operation.
CommitInfo
¶
Bases: TypedDict
Information about a single git commit.
GateStalenessInfo(branch, gate_head, upstream_head, is_stale, commits_behind, commits_ahead, last_checked, error)
dataclass
¶
Result of comparing gate vs upstream.
GitGate(*, project_id, gate_path, upstream_url=None, default_branch=None, ssh_host_dir=None, ssh_key_name=None, validate_gate_fn=None)
¶
Repository + Gateway for a host-side git gate mirror.
Manages the bare git mirror that containers clone from. Provides operations for initial creation, incremental sync from upstream, selective branch fetching, and staleness detection.
Constructor takes plain parameters — no terok-specific types.
Initialise with plain parameters.
Parameters¶
project_id:
Identifier for this gate's owner.
gate_path:
Path to the bare git mirror on the host.
upstream_url:
Git upstream URL to sync from.
default_branch:
Branch name used for staleness comparisons.
ssh_host_dir:
Explicit SSH directory for git operations. When None,
falls back to SandboxConfig().ssh_keys_dir / project_id.
ssh_key_name:
Explicit SSH key filename.
validate_gate_fn:
Optional callback (project_id) -> None that validates no other
project uses the same gate with a different upstream. Injected by
the orchestration layer; omitted for standalone use.
Source code in src/terok_sandbox/git_gate.py
sync(branches=None, force_reinit=False)
¶
Sync the host-side git mirror gate.
- Uses SSH configuration via GIT_SSH_COMMAND.
- If gate doesn't exist (or force_reinit), performs a fresh
git clone --mirror. - Always runs the sync logic afterward for consistent side effects.
Returns:
| Type | Description |
|---|---|
GateSyncResult
|
Dict with keys: path, upstream_url, created (bool), success, |
GateSyncResult
|
updated_branches, errors. |
Source code in src/terok_sandbox/git_gate.py
sync_branches(branches=None)
¶
Sync specific branches in the gate from upstream.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
branches
|
list[str] | None
|
List of branches to sync (default: all via remote update) |
None
|
Returns:
| Type | Description |
|---|---|
BranchSyncResult
|
Dict with keys: success, updated_branches, errors |
Source code in src/terok_sandbox/git_gate.py
compare_vs_upstream(branch=None)
¶
Compare gate HEAD vs upstream HEAD for a branch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
branch
|
str | None
|
Branch to compare (default: configured default_branch) |
None
|
Returns:
| Type | Description |
|---|---|
GateStalenessInfo
|
GateStalenessInfo with comparison results |
Source code in src/terok_sandbox/git_gate.py
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 | |
last_commit()
¶
Get information about the last commit on the configured branch.
Returns None if the gate doesn't exist or is not accessible.