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 ¶
- func FindRepositoryRoot() (string, error)
- type FileClassifier
- func (fc *FileClassifier) ClassifyFiles(ctx context.Context, files []string) ([]FileInfo, error)
- func (fc *FileClassifier) ExcludeByPatterns(files, patterns []string) []string
- func (fc *FileClassifier) FilterGoFiles(ctx context.Context, files []string, excludeTests bool) ([]string, error)
- func (fc *FileClassifier) FilterTextFiles(ctx context.Context, files []string) ([]string, error)
- func (fc *FileClassifier) GetFileStats(ctx context.Context, files []string) (map[string]int, error)
- type FileInfo
- type InstallationStatus
- type Installer
- func (i *Installer) GenerateHookScript() string
- func (i *Installer) GetInstallationStatus(hookType string) (*InstallationStatus, error)
- func (i *Installer) InstallHook(hookType string, force bool) error
- func (i *Installer) IsHookInstalled(hookType string) bool
- func (i *Installer) UninstallHook(hookType string) (bool, error)
- type Repository
- func (r *Repository) GetAllFiles() ([]string, error)
- func (r *Repository) GetFileContent(path string) ([]byte, error)
- func (r *Repository) GetModifiedFiles() ([]string, error)
- func (r *Repository) GetRoot() string
- func (r *Repository) GetStagedFiles() ([]string, error)
- func (r *Repository) IsFileTracked(path string) bool
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FindRepositoryRoot ¶
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 ¶
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 ¶
FilterTextFiles returns only text files that are not excluded
func (*FileClassifier) GetFileStats ¶
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 ¶
NewInstaller creates a new hook installer
func NewInstallerWithConfig ¶
NewInstallerWithConfig creates a new hook installer with configuration
func (*Installer) GenerateHookScript ¶
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 ¶
InstallHook installs a git hook with enhanced validation and conflict resolution
func (*Installer) IsHookInstalled ¶
IsHookInstalled checks if a hook is installed
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