git

package
v1.2.0-beta Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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

func ExtractInfo(projectPath string) Info

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)
}

Jump to

Keyboard shortcuts

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