Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsGitRepository ¶
IsGitRepository checks if the given path is a Git repository
Types ¶
type GitInfo ¶
type GitInfo struct {
VCS string `json:"VCS,omitempty"`
URL string `json:"URL,omitempty"`
Ref string `json:"Ref,omitempty"`
Hash string `json:"Hash,omitempty"`
}
GitInfo represents Git repository metadata
type GitRepository ¶
type GitRepository struct {
// contains filtered or unexported fields
}
GitRepository represents a Git repository
func NewGitRepository ¶
func NewGitRepository(path string) *GitRepository
NewGitRepository creates a new GitRepository instance. It validates that the provided path points to a valid Git repository. Returns a GitRepository instance or nil if validation fails.
func (*GitRepository) GetCommitHash ¶
func (g *GitRepository) GetCommitHash() (string, error)
GetCommitHash returns the current commit hash
func (*GitRepository) GetCurrentBranch ¶
func (g *GitRepository) GetCurrentBranch() (string, error)
GetCurrentBranch returns the current branch name. If HEAD points to a branch, returns the branch name. If HEAD is detached, returns an empty string.
Returns an error if:
- The repository is invalid or inaccessible
- HEAD file cannot be read
- HEAD content is invalid
func (*GitRepository) GetInfo ¶
func (g *GitRepository) GetInfo() (*GitInfo, error)
GetInfo returns Git repository information. It validates the repository state and extracts information about the current HEAD, remote URL, and commit hash.
The returned GitInfo includes:
- VCS: the version control system type (always "git")
- URL: the remote repository URL
- Ref: the current branch or reference
- Hash: the full commit hash
Returns an error if:
- The repository is invalid or inaccessible
- Required Git files cannot be read
- Repository state is inconsistent
func (*GitRepository) GetRemoteURL ¶
func (g *GitRepository) GetRemoteURL() (string, error)
GetRemoteURL returns the remote URL of the repository. It reads the repository's config file and extracts the URL of the 'origin' remote.
Returns an error if:
- The repository is invalid or inaccessible
- Config file cannot be read or parsed
- Remote 'origin' is not configured