safegit v0.26.0 /internal/repo
On this page

Package repo manages the .git/safegit/ data directory including initialization, configuration loading, validation, and path helpers for all state files.

#internal/repo

#internal/repo

Package repo manages the .git/safegit/ data directory including initialization, configuration loading, validation, and path helpers for all state files.

#Config

Go go
type Config struct

Config holds safegit configuration persisted in config.json.

#CommitConfig

Go go
type CommitConfig struct

CommitConfig holds commit-related settings.

#LockConfig

Go go
type LockConfig struct

LockConfig holds ref-lock acquisition settings.

#HooksConfig

Go go
type HooksConfig struct

HooksConfig holds hook-related settings.

#PrePrePushConfig

Go go
type PrePrePushConfig struct

PrePrePushConfig holds pre-pre-push hook timeout settings.

#PushConfig

Go go
type PushConfig struct

PushConfig holds push retry settings.

#LogConfig

Go go
type LogConfig struct

LogConfig holds operation log size settings.

#DefaultConfig

Go go
func DefaultConfig() Config

DefaultConfig returns the default safegit configuration.

#SafegitDir

Go go
func SafegitDir(gitDir string) string

SafegitDir returns the path to .git/safegit/ given a .git directory path.

#SharedSafegitDir

Go go
func SharedSafegitDir(ctx context.Context, gitDir string) string

SharedSafegitDir returns the safegit directory under the common .git dir. For normal repos this is identical to SafegitDir(gitDir). For worktrees it returns /safegit so that lock files are shared across all worktrees, ensuring proper serialization of ref updates.

The parameter accepts either the git directory (.git) or the safegit directory (.git/safegit); callers use both forms.

#IsInitialized

Go go
func IsInitialized(gitDir string) bool

IsInitialized checks whether the .git/safegit/ directory exists.

#Init

Go go
func Init(gitDir string) error

Init creates the .git/safegit/ directory structure and writes default config.json. Idempotent: returns nil if already initialized.

#EnsureInitialized

Go go
func EnsureInitialized(gitDir string) error

EnsureInitialized auto-initializes .git/safegit/ if it doesn't exist yet.

#Uninstall

Go go
func Uninstall(gitDir string) error

Uninstall removes the .git/safegit/ directory entirely. In worktree setups, also cleans up the shared lock directory.

#LoadConfig

Go go
func LoadConfig(gitDir string) (*Config, error)

LoadConfig reads and parses config.json from the safegit directory.

#LoadConfigFrom

Go go
func LoadConfigFrom(path string) (*Config, error)

LoadConfigFrom reads and parses config from an arbitrary path.

#MarshalConfig

Go go
func MarshalConfig(cfg *Config) ([]byte, error)

MarshalConfig renders the config exactly as SaveConfig would write it. It is split out so callers can mint the write as an effect instead of performing it here, which is what lets --dry-run record a config change without making one.

#ConfigPath

Go go
func ConfigPath(gitDir string) string

ConfigPath is the path SaveConfig writes to for the given git dir.

#SaveConfigTo

Go go
func SaveConfigTo(path string, cfg *Config) error

SaveConfigTo writes config to an arbitrary path.

#SaveConfig

Go go
func SaveConfig(gitDir string, cfg *Config) error

SaveConfig writes config back to config.json.

#GetConfigValue

Go go
func GetConfigValue(cfg *Config, key string) (interface{}, error)

GetConfigValue returns the value for a dot-separated config key.

#SetConfigValue

Go go
func SetConfigValue(cfg *Config, key, value string) error

SetConfigValue sets a dot-separated config key to the given string value.

#ValidConfigKeys

Go go
func ValidConfigKeys() []string

ValidConfigKeys returns the list of supported config keys.

#Config.Validate

Go go
func (c *Config) Validate() error

Validate checks that all config values are within acceptable ranges.

Search