Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrGitNotFound = errors.New("diff mode requires git, which was not found in PATH") ErrNotARepo = errors.New("not a git repository") ErrUnknownRef = errors.New("unknown ref") ErrNoMergeBase = errors.New("no merge-base") )
Sentinel errors for diff-mode failures; match with errors.Is.
Functions ¶
Types ¶
type ChangeSet ¶ added in v1.5.0
type ChangeSet struct {
// Files changed (added, copied, modified, renamed), relative to the
// directory passed to ChangedFiles, sorted. Deleted files are omitted.
Files []string
// Base is the resolved commit the working tree is compared against
// (ModeSince: the ref; ModeBranch: the merge-base; ModeStaged: empty).
Base string
// PartiallyStaged lists staged files that also have unstaged changes
// (ModeStaged only).
PartiallyStaged []string
}
ChangeSet is the result of ChangedFiles.
func ChangedFiles ¶ added in v1.5.0
ChangedFiles lists the files changed according to spec, relative to dir.
All git commands run inside dir with --relative, so when dir is a subdirectory of the repository, only changes under it are returned. Untracked files never appear (git diff does not list them).
type Info ¶
type Info struct {
// Current commit hash (full SHA)
Commit string
// Current branch name
Branch string
}
Info contains Git repository metadata.
This type holds Git information extracted from a repository at the time of analysis. Both fields are optional - if the directory is not a Git repository or Git is not available, both will be empty strings.
Used to correlate analysis reports with specific code versions and improve comparison accuracy across runs.
func ExtractInfo ¶
ExtractInfo attempts to extract Git metadata from a directory.
This function runs git commands to get the current commit hash and branch name. It gracefully handles non-Git directories and missing git installations by returning empty strings rather than errors.
The function executes:
- `git rev-parse HEAD` for the commit hash
- `git rev-parse --abbrev-ref HEAD` for the branch name
Both commands are run in the specified directory. If either fails (not a git repo, git not installed, etc.), that field will be empty.
Parameters:
- projectPath: The directory to extract Git info from
Returns:
- Info struct with commit and branch (may be empty if not a Git repo)
Example:
info := git.ExtractInfo("/path/to/project")
if info.Commit != "" {
fmt.Printf("Analyzed commit: %s on branch %s\n", info.Commit, info.Branch)
}