Documentation
¶
Index ¶
- Variables
- type Author
- type AuthorError
- type Blob
- type Client
- type Commit
- type CommitFile
- type Committer
- type FlatTree
- type FlatTreeEntry
- type ListCommitsOptions
- type ObjectAlreadyExistsError
- type ObjectNotFoundError
- type PackfileStorageMode
- type PathNotFoundError
- type Ref
- type RefAlreadyExistsError
- type RefNotFoundError
- type StagedWriter
- type Tree
- type TreeEntry
- type UnexpectedObjectCountError
- type UnexpectedObjectTypeError
- type WriterOption
- type WriterOptions
Constants ¶
This section is empty.
Variables ¶
var ( // ErrObjectNotFound is returned when a requested Git object cannot be found in the repository. // This error should only be used with errors.Is() for comparison, not for type assertions. ErrObjectNotFound = errors.New("object not found") // ErrObjectAlreadyExists is returned when attempting to create a Git object that already exists. // This error should only be used with errors.Is() for comparison, not for type assertions. ErrObjectAlreadyExists = errors.New("object already exists") // ErrUnexpectedObjectType is returned when a Git object has a different type than expected. // This error should only be used with errors.Is() for comparison, not for type assertions. ErrUnexpectedObjectType = errors.New("unexpected object type") // ErrNothingToPush is returned when attempting to push changes but no objects have been staged. // This error should only be used with errors.Is() for comparison, not for type assertions. ErrNothingToPush = errors.New("nothing to push") // ErrNothingToCommit is returned when attempting to commit but no changes have been staged. // This error should only be used with errors.Is() for comparison, not for type assertions. ErrNothingToCommit = errors.New("nothing to commit") // ErrUnexpectedObjectCount is returned when the number of objects returned by the server is unexpected. // This error should only be used with errors.Is() for comparison, not for type assertions. ErrUnexpectedObjectCount = errors.New("unexpected object count") // ErrEmptyCommitMessage is returned when attempting to create a commit with an empty message. // This error should only be used with errors.Is() for comparison, not for type assertions. ErrEmptyCommitMessage = errors.New("empty commit message") // ErrEmptyPath is returned when a path is empty. // This error should only be used with errors.Is() for comparison, not for type assertions. ErrEmptyPath = errors.New("empty path") // ErrEmptyRefName is returned when a ref name is empty. // This error should only be used with errors.Is() for comparison, not for type assertions. ErrEmptyRefName = errors.New("empty ref name") // ErrInvalidAuthor is returned when author information is invalid. // This error should only be used with errors.Is() for comparison, not for type assertions. ErrInvalidAuthor = errors.New("invalid author information") )
var ErrWriterCleanedUp = errors.New("writer has been cleaned up and can no longer be used")
ErrWriterCleanedUp is returned when trying to use a writer after cleanup has been called.
Functions ¶
This section is empty.
Types ¶
type Author ¶
type Author struct { // Name is the full name of the author (e.g., "John Doe") Name string // Email is the email address of the author (e.g., "john@example.com") Email string // Time is when the changes were originally made by the author Time time.Time }
Author represents the person who created the changes in the commit. It includes their name, email, and the timestamp of when they made the changes. This is typically the person who wrote the code or made the modifications.
type AuthorError ¶
AuthorError provides structured information about invalid author information.
func NewAuthorError ¶
func NewAuthorError(field, reason string) *AuthorError
NewAuthorError creates a new AuthorError with the specified details.
func (*AuthorError) Error ¶
func (e *AuthorError) Error() string
func (*AuthorError) Unwrap ¶
func (e *AuthorError) Unwrap() error
type Blob ¶
type Blob struct { // Hash is the SHA-1 hash of the blob object Hash hash.Hash // Content is the raw file content as bytes Content []byte }
Blob represents a Git blob object, which stores the content of a file. In Git, all file content is stored as blob objects in the object database.
type Client ¶
type Client interface { // Repo operations IsAuthorized(ctx context.Context) (bool, error) RepoExists(ctx context.Context) (bool, error) // Ref operations ListRefs(ctx context.Context) ([]Ref, error) GetRef(ctx context.Context, refName string) (Ref, error) CreateRef(ctx context.Context, ref Ref) error UpdateRef(ctx context.Context, ref Ref) error DeleteRef(ctx context.Context, refName string) error // Blob operations GetBlob(ctx context.Context, hash hash.Hash) (*Blob, error) GetBlobByPath(ctx context.Context, rootHash hash.Hash, path string) (*Blob, error) // Tree operations GetFlatTree(ctx context.Context, hash hash.Hash) (*FlatTree, error) GetTree(ctx context.Context, hash hash.Hash) (*Tree, error) GetTreeByPath(ctx context.Context, rootHash hash.Hash, path string) (*Tree, error) // Commit operations GetCommit(ctx context.Context, hash hash.Hash) (*Commit, error) CompareCommits(ctx context.Context, baseCommit, headCommit hash.Hash) ([]CommitFile, error) ListCommits(ctx context.Context, startCommit hash.Hash, options ListCommitsOptions) ([]Commit, error) // Write operations NewStagedWriter(ctx context.Context, ref Ref, options ...WriterOption) (StagedWriter, error) }
Client defines the interface for interacting with a Git repository. It provides methods for repository operations, reference management,
func NewHTTPClient ¶
NewHTTPClient creates a new Git client for the specified repository URL. The client implements the Git Smart Protocol version 2 over HTTP/HTTPS transport. It supports both HTTP and HTTPS URLs and can be configured with various options for authentication, logging, and HTTP client customization.
Parameters:
- repo: Repository URL (must be HTTP or HTTPS)
- options: Configuration options for authentication, logging, etc.
Returns:
- Client: Configured Git client interface
- error: Error if URL is invalid or configuration fails
Example:
// Create client with basic authentication client, err := nanogit.NewHTTPClient( "https://github.com/user/repo", options.WithBasicAuth("username", "password"), options.WithLogger(logger), ) if err != nil { return err }
type Commit ¶
type Commit struct { // Hash is the SHA-1 hash of the commit object Hash hash.Hash // Tree is the hash of the root tree object that represents the state // of the repository at the time of the commit Tree hash.Hash // Parent is the hash of the parent commit // TODO: Merge commits can have multiple parents, but currently only single parent is supported Parent hash.Hash // Author is the person who created the changes in the commit Author Author // Committer is the person who created the commit object Committer Committer // Message is the commit message that describes the changes made in this commit Message string }
Commit represents a Git commit object. It contains metadata about the commit, including the author, committer, commit message, and references to the parent commits and tree.
func (*Commit) Time ¶
Time returns the timestamp when the commit object was created. This is equivalent to the committer's timestamp, as the committer is the person who actually created the commit object in the repository. For most commits, this will be the same as the author time, but they can differ in some workflows.
Returns:
- time.Time: The timestamp when the commit was created
type CommitFile ¶
type CommitFile struct { // Path of the file in the head commit Path string // Mode is the file mode in the head commit (e.g., 100644 for regular files) Mode uint32 // OldMode is the original file mode in the base commit (for modified files) OldMode uint32 // Hash is the file hash in the head commit Hash hash.Hash // OldHash is the original file hash in the base commit (for modified files) OldHash hash.Hash // Status indicates the type of file change (added, modified, deleted, etc.) Status protocol.FileStatus }
CommitFile represents a file change between two commits. It contains information about how a file was modified, including its path, mode, hash, and the type of change (added, modified, deleted, etc.).
type Committer ¶
type Committer struct { // Name is the full name of the committer (e.g., "Jane Smith") Name string // Email is the email address of the committer (e.g., "jane@example.com") Email string // Time is when the commit object was created Time time.Time }
Committer represents the person who created the commit object. This is often the same as the author, but can be different in cases where someone else commits changes on behalf of the author (e.g., via patches).
type FlatTree ¶
type FlatTree struct { // Entries contains all files and directories in the tree (recursive) Entries []FlatTreeEntry // Hash is the SHA-1 hash of the root tree object Hash hash.Hash }
FlatTree represents a recursive, flattened view of a Git tree structure. This provides a complete list of all files and directories in the tree, with each entry containing its full path from the repository root.
This is useful for operations that need to:
- List all files in a repository
- Search for specific files by path
- Compare entire directory structures
- Generate file listings for display
type FlatTreeEntry ¶
type FlatTreeEntry struct { // Name is the base filename (e.g., "file.txt") Name string // Path is the full path from repository root (e.g., "dir/subdir/file.txt") Path string // Mode is the file mode in octal (e.g., 0o100644 for regular files, 0o40000 for directories) Mode uint32 // Hash is the SHA-1 hash of the object Hash hash.Hash // Type is the type of Git object (blob for files, tree for directories) Type protocol.ObjectType }
FlatTreeEntry represents a single entry in a flattened Git tree structure. Unlike TreeEntry, this includes the full path from the repository root, making it suitable for operations that need to work with complete file paths.
A flattened tree contains all files and directories recursively, with each entry having its complete path from the repository root.
type ListCommitsOptions ¶
type ListCommitsOptions struct { // PerPage specifies the number of commits to return per page // If 0, defaults to 30. Maximum allowed is 100 PerPage int // Page specifies which page of results to return (1-based) // If 0, defaults to 1 Page int // Path filters commits to only those that affect the specified file or directory path // If empty, all commits are included Path string // Since filters commits to only those created after this time // If zero, no time filtering is applied Since time.Time // Until filters commits to only those created before this time // If zero, no time filtering is applied Until time.Time }
ListCommitsOptions provides filtering and pagination options for listing commits. Similar to GitHub's API, it allows limiting results, filtering by path, and pagination.
type ObjectAlreadyExistsError ¶
ObjectAlreadyExistsError provides structured information about a Git object that already exists.
func NewObjectAlreadyExistsError ¶
func NewObjectAlreadyExistsError(objectID hash.Hash) *ObjectAlreadyExistsError
NewObjectAlreadyExistsError creates a new ObjectAlreadyExistsError with the specified object ID.
func (*ObjectAlreadyExistsError) Error ¶
func (e *ObjectAlreadyExistsError) Error() string
func (*ObjectAlreadyExistsError) Unwrap ¶
func (e *ObjectAlreadyExistsError) Unwrap() error
Unwrap enables errors.Is() compatibility with ErrObjectAlreadyExists
type ObjectNotFoundError ¶
ObjectNotFoundError provides structured information about a Git object that was not found.
func NewObjectNotFoundError ¶
func NewObjectNotFoundError(objectID hash.Hash) *ObjectNotFoundError
NewObjectNotFoundError creates a new ObjectNotFoundError with the specified object ID.
func (*ObjectNotFoundError) Error ¶
func (e *ObjectNotFoundError) Error() string
func (*ObjectNotFoundError) Unwrap ¶
func (e *ObjectNotFoundError) Unwrap() error
Unwrap enables errors.Is() compatibility with ErrObjectNotFound
type PackfileStorageMode ¶
type PackfileStorageMode int
PackfileStorageMode defines how packfile objects are stored during staging.
const ( // PackfileStorageAuto automatically chooses between memory and disk based on object count. // Uses memory for small operations (<=10 objects) and disk for larger operations. PackfileStorageAuto PackfileStorageMode = iota // PackfileStorageMemory always stores objects in memory for maximum performance. // Best for small operations but can use significant memory for bulk operations. PackfileStorageMemory // PackfileStorageDisk always stores objects in temporary files on disk. // Best for bulk operations to minimize memory usage. PackfileStorageDisk )
type PathNotFoundError ¶
type PathNotFoundError struct {
Path string
}
PathNotFoundError provides structured information about a Git path that was not found.
func NewPathNotFoundError ¶
func NewPathNotFoundError(path string) *PathNotFoundError
NewPathNotFoundError creates a new PathNotFoundError with the specified path.
func (*PathNotFoundError) Error ¶
func (e *PathNotFoundError) Error() string
func (*PathNotFoundError) Unwrap ¶
func (e *PathNotFoundError) Unwrap() error
Unwrap enables errors.Is() compatibility with ErrPathNotFound
type Ref ¶
type Ref struct { // Name is the full reference name (e.g., "refs/heads/main", "refs/tags/v1.0") Name string // Hash is the commit hash that this reference points to Hash hash.Hash }
Ref represents a Git reference (ref) in the repository. A ref is a pointer to a specific commit in the repository's history. Common reference types include branches (refs/heads/*), tags (refs/tags/*), and remote tracking branches (refs/remotes/*).
type RefAlreadyExistsError ¶
type RefAlreadyExistsError struct {
RefName string
}
RefAlreadyExistsError provides structured information about a Git reference that already exists.
func NewRefAlreadyExistsError ¶
func NewRefAlreadyExistsError(refName string) *RefAlreadyExistsError
NewRefAlreadyExistsError creates a new RefAlreadyExistsError with the specified reference name.
func (*RefAlreadyExistsError) Error ¶
func (e *RefAlreadyExistsError) Error() string
func (*RefAlreadyExistsError) Unwrap ¶
func (e *RefAlreadyExistsError) Unwrap() error
Unwrap enables errors.Is() compatibility with ErrObjectAlreadyExists
type RefNotFoundError ¶
type RefNotFoundError struct {
RefName string
}
RefNotFoundError provides structured information about a Git reference that was not found.
func NewRefNotFoundError ¶
func NewRefNotFoundError(refName string) *RefNotFoundError
NewRefNotFoundError creates a new RefNotFoundError with the specified reference name.
func (*RefNotFoundError) Error ¶
func (e *RefNotFoundError) Error() string
func (*RefNotFoundError) Unwrap ¶
func (e *RefNotFoundError) Unwrap() error
Unwrap enables errors.Is() compatibility with ErrRefNotFound
type StagedWriter ¶
type StagedWriter interface { // BlobExists checks if a blob exists at the given path. BlobExists(ctx context.Context, path string) (bool, error) // CreateBlob stages a new file to be written at the given path. // Returns the hash of the created blob. CreateBlob(ctx context.Context, path string, content []byte) (hash.Hash, error) // UpdateBlob stages an update to an existing file at the given path. // Returns the hash of the updated blob. UpdateBlob(ctx context.Context, path string, content []byte) (hash.Hash, error) // DeleteBlob stages the deletion of a file at the given path. // Returns the hash of the tree after deletion. DeleteBlob(ctx context.Context, path string) (hash.Hash, error) // GetTree gets the tree object at the given path. GetTree(ctx context.Context, path string) (*Tree, error) // DeleteTree stages the deletion of a directory and all its contents at the given path. // Returns the hash of the deleted tree. DeleteTree(ctx context.Context, path string) (hash.Hash, error) // Commit creates a new commit with all staged changes. // Returns the hash of the created commit. Commit(ctx context.Context, message string, author Author, committer Committer) (*Commit, error) // Push sends all committed changes to the remote repository. // This is the final step that makes changes visible to others. // It will update the reference to point to the last commit. Push(ctx context.Context) error // Cleanup releases any resources held by the writer and clears all staged changes. // This should be called when the writer is no longer needed or to cancel all pending changes. // After calling Cleanup, the writer should not be used for further operations. Cleanup(ctx context.Context) error }
StagedWriter provides a transactional interface for writing changes to Git objects. It allows staging multiple changes (file writes, updates, deletes) before committing them together. Changes are staged in memory and only sent to the server when Push() is called. This can be used to write to any Git object: commits, tags, branches, or other references.
type Tree ¶
type Tree struct { // Entries contains the direct children of this tree (non-recursive) Entries []TreeEntry // Hash is the SHA-1 hash of this tree object Hash hash.Hash }
Tree represents a single Git tree object containing direct children only. This provides a non-recursive view of a directory, showing only the immediate files and subdirectories within it.
This is useful for operations that need to:
- Browse directory contents one level at a time
- Implement tree navigation interfaces
- Work with specific directory levels
- Minimize memory usage when not all files are needed
type TreeEntry ¶
type TreeEntry struct { // Name is the filename or directory name Name string // Mode is the file mode in octal (e.g., 0o100644 for files, 0o40000 for directories) Mode uint32 // Hash is the SHA-1 hash of the object Hash hash.Hash // Type is the type of Git object (blob for files, tree for directories) Type protocol.ObjectType }
TreeEntry represents a single entry in a Git tree object. This contains only direct children of the tree (non-recursive), similar to what you'd see with 'ls' in a directory.
type UnexpectedObjectCountError ¶
type UnexpectedObjectCountError struct { ExpectedCount int ActualCount int Objects []*protocol.PackfileObject }
UnexpectedObjectCountError provides structured information about a Git object with an unexpected count.
func NewUnexpectedObjectCountError ¶
func NewUnexpectedObjectCountError(expectedCount int, objects []*protocol.PackfileObject) *UnexpectedObjectCountError
NewUnexpectedObjectCountError creates a new UnexpectedObjectCountError with the specified details.
func (*UnexpectedObjectCountError) Error ¶
func (e *UnexpectedObjectCountError) Error() string
func (*UnexpectedObjectCountError) Unwrap ¶
func (e *UnexpectedObjectCountError) Unwrap() error
Unwrap enables errors.Is() compatibility with ErrUnexpectedObjectCount
type UnexpectedObjectTypeError ¶
type UnexpectedObjectTypeError struct { ObjectID hash.Hash ExpectedType protocol.ObjectType ActualType protocol.ObjectType }
UnexpectedObjectTypeError provides structured information about a Git object with an unexpected type.
func NewUnexpectedObjectTypeError ¶
func NewUnexpectedObjectTypeError(objectID hash.Hash, expectedType, actualType protocol.ObjectType) *UnexpectedObjectTypeError
NewUnexpectedObjectTypeError creates a new UnexpectedObjectTypeError with the specified details.
func (*UnexpectedObjectTypeError) Error ¶
func (e *UnexpectedObjectTypeError) Error() string
func (*UnexpectedObjectTypeError) Unwrap ¶
func (e *UnexpectedObjectTypeError) Unwrap() error
Unwrap enables errors.Is() compatibility with ErrUnexpectedObjectType
type WriterOption ¶
type WriterOption func(*WriterOptions) error
WriterOption is a function type for configuring WriterOptions.
func WithAutoStorage ¶
func WithAutoStorage() WriterOption
WithAutoStorage configures the writer to automatically choose between memory and disk based on the number of objects. This is the default behavior.
func WithDiskStorage ¶
func WithDiskStorage() WriterOption
WithDiskStorage configures the writer to always use disk storage for packfile objects. This minimizes memory usage but may be slightly slower due to disk I/O.
func WithMemoryStorage ¶
func WithMemoryStorage() WriterOption
WithMemoryStorage configures the writer to always use in-memory storage for packfile objects. This provides the best performance but can use significant memory for bulk operations.
type WriterOptions ¶
type WriterOptions struct { // StorageMode determines how packfile objects are stored during staging. // Default is PackfileStorageAuto. StorageMode PackfileStorageMode }
WriterOptions holds configuration options for StagedWriter.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
mocks
Code generated by counterfeiter.
|
Code generated by counterfeiter. |
Code generated by counterfeiter.
|
Code generated by counterfeiter. |
Package object defines the types of objects that can be stored in a Git repository.
|
Package object defines the types of objects that can be stored in a Git repository. |
hash
A Git-oriented hashing implementation.
|
A Git-oriented hashing implementation. |