git

package
v1.0.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 13, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package git provides intelligent file filtering and classification for the pre-commit system

Package git provides Git repository operations for the pre-commit system

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindRepositoryRoot

func FindRepositoryRoot() (string, error)

FindRepositoryRoot finds the root directory of the Git repository

Types

type FileClassifier

type FileClassifier struct {
	// contains filtered or unexported fields
}

FileClassifier provides intelligent file classification and filtering

func NewFileClassifier

func NewFileClassifier(cfg *config.Config) *FileClassifier

NewFileClassifier creates a new file classifier

func (*FileClassifier) ClassifyFiles

func (fc *FileClassifier) ClassifyFiles(ctx context.Context, files []string) ([]FileInfo, error)

ClassifyFiles analyzes and classifies a list of files

Example

Example usage demonstration

// Create a file classifier
fc := NewFileClassifier(&config.Config{
	MaxFileSize: 10 * 1024 * 1024, // 10MB limit
})

// Classify some files
files := []string{
	"main.go",
	"README.md",
	"vendor/package/file.go",
	"generated.pb.go",
}

results, err := fc.ClassifyFiles(context.Background(), files)
if err != nil {
	panic(err)
}

// Process results
for _, info := range results {
	if info.IsGoFile && !info.Generated && !info.Excluded {
		fmt.Printf("Go source file: %s\n", info.Path)
	}
}

func (*FileClassifier) ExcludeByPatterns

func (fc *FileClassifier) ExcludeByPatterns(files, patterns []string) []string

ExcludeByPatterns filters out files matching exclude patterns

func (*FileClassifier) FilterGoFiles

func (fc *FileClassifier) FilterGoFiles(ctx context.Context, files []string, excludeTests bool) ([]string, error)

FilterGoFiles returns only Go source files, excluding generated and test files if specified

func (*FileClassifier) FilterTextFiles

func (fc *FileClassifier) FilterTextFiles(ctx context.Context, files []string) ([]string, error)

FilterTextFiles returns only text files that are not excluded

func (*FileClassifier) GetFileStats

func (fc *FileClassifier) GetFileStats(ctx context.Context, files []string) (map[string]int, error)

GetFileStats returns statistics about the classified files

type FileInfo

type FileInfo struct {
	Path      string
	IsText    bool
	IsBinary  bool
	Language  string
	Size      int64
	IsGoFile  bool
	Generated bool
	Excluded  bool
}

FileInfo contains information about a file

type InstallationStatus

type InstallationStatus struct {
	HookType        string
	HookPath        string
	Installed       bool
	IsOurHook       bool
	Executable      bool
	ConflictingHook bool
	FileMode        os.FileMode
	ModTime         time.Time
	Message         string
}

InstallationStatus provides detailed information about hook installation

type Installer

type Installer struct {
	// contains filtered or unexported fields
}

Installer handles git hook installation

func NewInstaller

func NewInstaller(repoRoot, preCommitDir string) *Installer

NewInstaller creates a new hook installer

func NewInstallerWithConfig

func NewInstallerWithConfig(repoRoot, preCommitDir string, cfg *config.Config) *Installer

NewInstallerWithConfig creates a new hook installer with configuration

func (*Installer) GenerateHookScript

func (i *Installer) GenerateHookScript() string

GenerateHookScript creates a dynamic hook script based on current environment

func (*Installer) GetInstallationStatus

func (i *Installer) GetInstallationStatus(hookType string) (*InstallationStatus, error)

GetInstallationStatus returns detailed information about hook installation status

func (*Installer) InstallHook

func (i *Installer) InstallHook(hookType string, force bool) error

InstallHook installs a git hook with enhanced validation and conflict resolution

func (*Installer) IsHookInstalled

func (i *Installer) IsHookInstalled(hookType string) bool

IsHookInstalled checks if a hook is installed

func (*Installer) UninstallHook

func (i *Installer) UninstallHook(hookType string) (bool, error)

UninstallHook removes a git hook if it was installed by us

type Repository

type Repository struct {
	// contains filtered or unexported fields
}

Repository represents a Git repository

func NewRepository

func NewRepository(root string) *Repository

NewRepository creates a new Repository instance

func (*Repository) GetAllFiles

func (r *Repository) GetAllFiles() ([]string, error)

GetAllFiles returns all tracked files in the repository

func (*Repository) GetFileContent

func (r *Repository) GetFileContent(path string) ([]byte, error)

GetFileContent returns the content of a file from the index (staged version)

func (*Repository) GetModifiedFiles

func (r *Repository) GetModifiedFiles() ([]string, error)

GetModifiedFiles returns all modified files (staged and unstaged)

func (*Repository) GetRoot

func (r *Repository) GetRoot() string

GetRoot returns the repository root directory

func (*Repository) GetStagedFiles

func (r *Repository) GetStagedFiles() ([]string, error)

GetStagedFiles returns all files staged for commit

func (*Repository) IsFileTracked

func (r *Repository) IsFileTracked(path string) bool

IsFileTracked checks if a file is tracked by git

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL