Documentation
¶
Index ¶
- Constants
- Variables
- func AbsolutePath(repoRoot, relPath string) string
- func ComputeTreeHash(entries []TreeEntry) string
- func ConfigPath(repoRoot string) string
- func FileMode(path string) (int, error)
- func FindRepoRoot() (string, error)
- func FindRepoRootFrom(start string) (string, error)
- func HashBytes(data []byte) string
- func HashFile(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 NewError(title string) *PgitError
- func NoContainerError() *PgitError
- func NotARepoError() *PgitError
- func RemoteNotFoundError(name string) *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
Constants ¶
const ( PgitDir = ".pgit" ConfigFile = "config.toml" IndexFile = "index" HeadFile = "HEAD" )
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. Files must have non-empty ContentHash (deleted files are excluded). The hash is computed as SHA256 of sorted entries in format: "{mode} {path}\0{content_hash}"
func ConfigPath ¶
ConfigPath returns the path to the config file.
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 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 ¶ added in v1.1.0
RelativeTime formats a time as relative (e.g., "2 hours ago")
func RelativeTimeShort ¶ added in v1.1.0
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 ¶ added in v1.1.0
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 ¶ added in v1.1.0
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 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 (*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