git

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package git provides a Git repository scan source.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SafeDisplayURL

func SafeDisplayURL(raw string) string

SafeDisplayURL returns a credential-stripped form of raw that is safe to put in logs, output metadata, error messages, and the scan summary. Any user-info portion (the "user:password@" part of a URL) is removed so no secret is ever surfaced.

The returned value is the clean URL with no noisy suffix, so it can be stored verbatim in a metadata field. When the URL cannot be parsed, the credential between "://" and "@" is masked on a best-effort basis; non-URL targets (for example local paths) are returned unchanged.

Types

type GitSource

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

GitSource is a Git repository-based scan source.

func New

func New(target string, opts ...Option) *GitSource

New creates a new GitSource.

func (*GitSource) Chunks

func (s *GitSource) Chunks(ctx context.Context) <-chan source.Chunk

Chunks sends Git commit history files as chunks over a channel.

func (*GitSource) Close

func (s *GitSource) Close() error

Close cleans up temporary resources. For cloned repositories, it removes the temporary directory.

func (*GitSource) Err added in v1.7.0

func (s *GitSource) Err() error

Err returns the first terminal error that aborted Git history production, or nil if it completed normally. Any error stored here has been run through sanitizeCloneError, so it can never carry raw clone credentials. It must only be called after the channel returned by Chunks has been fully drained (closed).

func (*GitSource) Type

func (s *GitSource) Type() string

Type returns the source type.

func (*GitSource) Validate

func (s *GitSource) Validate() error

Validate checks that the Git repository is accessible and opens/clones it. When --branch is set on a local target it verifies the branch exists, and when --since-commit is set it verifies the given commit is an ancestor of the walk's starting point; otherwise the diff-based walk would silently fall back to scanning the entire history or an unintended branch.

type Option

type Option func(*GitSource)

Option configures a GitSource.

func WithBranch

func WithBranch(branch string) Option

WithBranch scans only the specified branch.

func WithBufferSize

func WithBufferSize(size int) Option

WithBufferSize sets the chunk channel buffer size.

func WithDepth

func WithDepth(depth int) Option

WithDepth sets the clone depth (remote repositories only).

func WithExcludePaths

func WithExcludePaths(patterns []string) Option

WithExcludePaths sets glob patterns for file paths to exclude from scanning. Patterns are matched against each file's path within the repository, mirroring filesystem.WithExcludePaths semantics.

func WithMaxFileSize

func WithMaxFileSize(size int64) Option

WithMaxFileSize sets the maximum file size to scan.

func WithSince

func WithSince(t time.Time) Option

WithSince scans only commits after the specified date.

func WithSinceCommit

func WithSinceCommit(hash string) Option

WithSinceCommit scans only changes from the specified commit to HEAD.

Jump to

Keyboard shortcuts

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