Documentation
¶
Index ¶
- Constants
- Variables
- func AbsolutePath(repoRoot, relPath string) string
- func ComputeTreeHash(entries []TreeEntry) string
- func ComputeTreeHashLegacy(entries []TreeEntryLegacy) string
- func ConfigPath(repoRoot string) string
- func ContentHashEqual(a, b []byte) bool
- func ContentHashFromHex(s string) ([]byte, error)
- func ContentHashToHex(hash []byte) string
- func DetectBinary(content []byte) bool
- func FileMode(path string) (int, error)
- func FindRepoRoot() (string, error)
- func FindRepoRootFrom(start string) (string, error)
- func HashBytes(data []byte) string
- func HashBytesBlake3(data []byte) []byte
- func HashBytesBlake3Hex(data []byte) string
- func HashFile(path string) (string, error)
- func HashFileBlake3(path string) ([]byte, error)
- func HashFileBlake3Hex(path string) (string, error)
- func HashPath(path string) string
- func HeadPath(repoRoot string) string
- func IndexPath(repoRoot string) string
- func IsBinaryFile(path string) (bool, error)
- func IsInsideRepo(repoRoot, path string) bool
- func IsSymlink(path string) (bool, error)
- func NewULID() string
- func NewULIDWithTime(t time.Time) string
- func ParseULID(s string) (time.Time, error)
- func PgitPath(repoRoot string) string
- func ReadSymlink(path string) (string, error)
- func RelativePath(repoRoot, absPath string) (string, error)
- func RelativeTime(t time.Time) string
- func RelativeTimeShort(t time.Time) string
- func ShortID(id string) string
- func ToValidUTF8(s string) string
- func ToValidUTF8Bytes(b []byte) []byte
- func ValidateULID(s string) bool
- type PgitError
- func CommitNotFoundError(ref string) *PgitError
- func ContainerNotRunningError() *PgitError
- func DatabaseConnectionError(url string, err error) *PgitError
- func MissingArgumentError(argName, example string) *PgitError
- func NewError(title string) *PgitError
- func NoContainerError() *PgitError
- func NotARepoError() *PgitError
- func RemoteNotFoundError(name string) *PgitError
- func TooManyArgumentsError(expected int, got int) *PgitError
- func (e *PgitError) Error() string
- func (e *PgitError) Format() string
- func (e *PgitError) Unwrap() error
- func (e *PgitError) WithCause(cause string) *PgitError
- func (e *PgitError) WithCauses(causes ...string) *PgitError
- func (e *PgitError) WithContext(ctx string) *PgitError
- func (e *PgitError) WithMessage(msg string) *PgitError
- func (e *PgitError) WithSuggestion(sug string) *PgitError
- func (e *PgitError) WithSuggestions(sugs ...string) *PgitError
- func (e *PgitError) Wrap(err error) *PgitError
- type TreeEntry
- type TreeEntryLegacy
Constants ¶
const ( PgitDir = ".pgit" ConfigFile = "config.toml" IndexFile = "index" HeadFile = "HEAD" )
const ContentHashSize = 16
ContentHashSize is the size of BLAKE3 content hashes (16 bytes)
Variables ¶
var ( ErrNotARepository = errors.New("not a pgit repository (or any parent up to mount point)") ErrAlreadyInitialized = errors.New("pgit repository already exists") ErrNoContainerRuntime = errors.New("no container runtime found (docker or podman required)") ErrContainerNotRunning = errors.New("local container is not running") ErrDatabaseNotFound = errors.New("database not found") ErrNoCommits = errors.New("no commits yet") ErrNothingToCommit = errors.New("nothing to commit (working tree clean)") ErrNothingStaged = errors.New("nothing staged for commit") ErrUncommittedChanges = errors.New("uncommitted changes would be overwritten") ErrMergeConflict = errors.New("merge conflict detected") ErrRemoteNotFound = errors.New("remote not found") ErrRemoteExists = errors.New("remote already exists") ErrNotConnected = errors.New("not connected to database") ErrInvalidCommitID = errors.New("invalid commit ID") ErrCommitNotFound = errors.New("commit not found") ErrFileNotFound = errors.New("file not found") ErrPathNotInRepo = errors.New("path is outside repository") )
Common errors used throughout pgit
Functions ¶
func AbsolutePath ¶
AbsolutePath converts a relative path to an absolute path.
func ComputeTreeHash ¶
ComputeTreeHash computes the tree hash from a list of files using BLAKE3. Files must have non-empty ContentHash (deleted files are excluded). The hash is computed as BLAKE3 of sorted entries in format: "{mode} {path}\0{content_hash_bytes}"
func ComputeTreeHashLegacy ¶
func ComputeTreeHashLegacy(entries []TreeEntryLegacy) string
ComputeTreeHashLegacy computes tree hash using the old SHA256 format. Deprecated: Only use for reading existing commits.
func ConfigPath ¶
ConfigPath returns the path to the config file.
func ContentHashEqual ¶
ContentHashEqual compares two content hashes for equality. Handles nil hashes (nil == nil is true, nil != non-nil is true).
func ContentHashFromHex ¶
ContentHashFromHex parses a hex string to content hash. Returns nil for empty string.
func ContentHashToHex ¶
ContentHashToHex converts a content hash to hex string for display. Returns empty string for nil hash.
func DetectBinary ¶
DetectBinary returns true if content appears to be binary. Scans the entire content for NUL bytes (\x00). While git only checks the first 8000 bytes, PostgreSQL's TEXT type rejects \x00 anywhere, so we must scan everything to avoid insertion failures.
func FindRepoRoot ¶
FindRepoRoot walks up from the current directory to find .pgit directory. Returns the repository root path or error if not found.
func FindRepoRootFrom ¶
FindRepoRootFrom walks up from the given directory to find .pgit directory.
func HashBytes ¶
HashBytes computes SHA256 hash of bytes and returns hex string. Deprecated: Use HashBytesBlake3 for new code.
func HashBytesBlake3 ¶
HashBytesBlake3 computes BLAKE3 hash of bytes and returns 16-byte slice. This is the primary hash function for content hashing in the new schema.
func HashBytesBlake3Hex ¶
HashBytesBlake3Hex computes BLAKE3 hash and returns 32-char hex string. Useful for debugging and display purposes.
func HashFile ¶
HashFile computes SHA256 hash of a file and returns hex string. Deprecated: Use HashFileBlake3 for new code.
func HashFileBlake3 ¶
HashFileBlake3 computes BLAKE3 hash of a file and returns 16-byte slice.
func HashFileBlake3Hex ¶
HashFileBlake3Hex computes BLAKE3 hash of a file and returns 32-char hex string.
func IsBinaryFile ¶
IsBinaryFile checks if a file is binary by looking for NUL bytes in the first 8KB.
func IsInsideRepo ¶
IsInsideRepo checks if a path is inside the repository (not in .pgit).
func NewULID ¶
func NewULID() string
NewULID generates a new ULID string. ULIDs are time-sortable unique identifiers.
func NewULIDWithTime ¶
NewULIDWithTime generates a ULID for a specific time. Useful for importing commits with preserved timestamps.
func ReadSymlink ¶
ReadSymlink returns the target of a symbolic link.
func RelativePath ¶
RelativePath converts an absolute path to a path relative to the repo root.
func RelativeTime ¶
RelativeTime formats a time as relative (e.g., "2 hours ago")
func RelativeTimeShort ¶
RelativeTimeShort formats a time as a short relative string (e.g., "2h ago")
func ShortID ¶
ShortID returns the last 7 characters of an ID in lowercase. For ULIDs, the last part has more entropy than the first (timestamp) part. Lowercase matches git's convention for short hashes.
func ToValidUTF8 ¶
ToValidUTF8 ensures a string is valid UTF-8. If the string contains invalid UTF-8 sequences, it attempts to decode as Latin-1 (ISO-8859-1), which is a common encoding in older git repos. This preserves characters like ä, ö, ü, é, etc. instead of replacing them.
func ToValidUTF8Bytes ¶
ToValidUTF8Bytes ensures bytes represent valid UTF-8.
func ValidateULID ¶
ValidateULID checks if a string is a valid ULID.
Types ¶
type PgitError ¶
type PgitError struct {
Title string // Short error title
Message string // Detailed message
Context string // What was being attempted
Causes []string // Possible causes
Suggestions []string // Actionable suggestions with commands
Err error // Wrapped error
}
PgitError is a structured error with context and suggestions
func CommitNotFoundError ¶
CommitNotFoundError returns a structured error for missing commit
func ContainerNotRunningError ¶
func ContainerNotRunningError() *PgitError
ContainerNotRunningError returns a structured error for stopped container
func DatabaseConnectionError ¶
DatabaseConnectionError returns a structured error for DB connection issues
func MissingArgumentError ¶
MissingArgumentError returns an error for missing required argument
func NoContainerError ¶
func NoContainerError() *PgitError
NoContainerError returns a structured error for missing container runtime
func NotARepoError ¶
func NotARepoError() *PgitError
NotARepoError returns a structured error for "not a repository"
func RemoteNotFoundError ¶
RemoteNotFoundError returns a structured error for missing remote
func TooManyArgumentsError ¶
TooManyArgumentsError returns an error for too many arguments
func (*PgitError) WithCauses ¶
WithCauses adds multiple possible causes
func (*PgitError) WithContext ¶
WithContext adds context about what was being attempted
func (*PgitError) WithMessage ¶
WithMessage adds a detailed message
func (*PgitError) WithSuggestion ¶
WithSuggestion adds an actionable suggestion
func (*PgitError) WithSuggestions ¶
WithSuggestions adds multiple suggestions
type TreeEntryLegacy ¶
TreeEntryLegacy represents a file in the tree for hashing (legacy format). Used for backwards compatibility with existing commit tree hashes.