git

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package git provides utilities for interacting with the git command-line tool. It wraps common git operations such as diff, identity lookup, hook management, fetch, and CI environment detection.

Index

Constants

View Source
const HookMarker = "# GUARDIAN-MANAGED-HOOK"

HookMarker is the comment marker used to identify guardian-managed hooks.

Variables

This section is empty.

Functions

func Fetch

func Fetch() error

Fetch runs git fetch to update remote-tracking branches.

func GetDiffNameOnly

func GetDiffNameOnly(diffRange string) ([]string, error)

GetDiffNameOnly runs git diff --name-only for the given range and returns the list of changed file paths.

func GetUserEmail

func GetUserEmail() (string, error)

GetUserEmail returns the current git user.email by running git config user.email.

func InstallHooks

func InstallHooks() error

InstallHooks creates post-merge and post-checkout hooks that run guardian inbox in the background. Existing hooks that are not guardian-managed are left untouched and an error is returned.

func IsHookInstalled

func IsHookInstalled(hookName string) (bool, error)

IsHookInstalled checks if a guardian-managed hook exists for the given hook name.

func UninstallHooks

func UninstallHooks() error

UninstallHooks removes only guardian-managed hooks identified by the HookMarker comment. Non-guardian hooks are left untouched.

Types

type CIInfo

type CIInfo struct {
	Detected bool
	System   string // "github", "gitlab", ""
	BaseRef  string
	HeadRef  string
}

CIInfo holds detected CI environment information.

func DetectCI

func DetectCI() *CIInfo

DetectCI reads CI environment variables to determine if the tool is running inside a CI system. It supports GitHub Actions and GitLab CI.

type DiffResult

type DiffResult struct {
	ChangedFiles []string
	DiffContent  string
}

DiffResult holds the result of a git diff operation.

func GetDiff

func GetDiff(diffRange string) (*DiffResult, error)

GetDiff runs git diff for the given range and returns changed files along with the full unified diff content. The diffRange should be in the form "base..head".

Jump to

Keyboard shortcuts

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