git

package
v0.16.2 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddAllAndCommit

func AddAllAndCommit(message string, timeoutSeconds int) error

AddAllAndCommit commits all staged changes with the provided message (non-interactive).

func AddAndCommitFile

func AddAndCommitFile(newFilename, message string) error

AddAndCommitFile stages the specified file and commits it with the given message.

func CheckStagedChanges

func CheckStagedChanges(dir string) error

CheckStagedChanges verifies if there are staged changes in the given directory. If dir is empty, it runs in the process CWD.

func CleanCommitMessage

func CleanCommitMessage(message string) string

CleanCommitMessage cleans up LLM-generated commit messages

func GetFileGitPath

func GetFileGitPath(filename string) (string, error)

GetFileGitPath returns the path of the given filename relative to the Git repository root.

func GetGitRemoteURL

func GetGitRemoteURL() (string, error)

GetGitRemoteURL returns the remote URL of the current Git repository.

func GetGitRootDir

func GetGitRootDir() (string, error)

GetGitRootDir returns the absolute path to the root directory of the current Git repository.

func GetGitStatus

func GetGitStatus() (currentBranch string, uncommittedChanges int, stagedChanges int, err error)

GetGitStatus returns the current branch, number of uncommitted changes, and number of staged changes.

func GetRecentFileLog

func GetRecentFileLog(filePath string, limit int) (string, error)

GetRecentFileLog returns a short summary of recent commits for a file

func GetRecentTouchedFiles

func GetRecentTouchedFiles(numCommits int) ([]string, error)

GetRecentTouchedFiles returns a de-duplicated list of files touched in the last N commits

func GetStagedChanges

func GetStagedChanges() (string, error)

GetStagedChanges returns detailed information about staged changes in the repository.

func GetStagedDiff

func GetStagedDiff(dir string) (string, error)

GetStagedDiff returns the diff of staged changes in the given directory. If dir is empty, it runs in the process CWD.

func GetUncommittedChanges

func GetUncommittedChanges() (string, error)

GetUncommittedChanges returns detailed information about uncommitted changes in the repository.

func NormalizeShortTitle

func NormalizeShortTitle(raw string) string

func ParseCommitMessage

func ParseCommitMessage(commitMessage string) (string, string, error)

ParseCommitMessage parses a commit message into note and description

func PerformGitCommit

func PerformGitCommit(message string) error

PerformGitCommit executes the git commit command safely using stdin

func TruncateRunes

func TruncateRunes(s string, max int) string

func WrapText

func WrapText(text string, lineLength int) string

Types

type CommitExecutor

type CommitExecutor struct {
	Client           api.ClientInterface
	UserMessage      string
	UserInstructions string
	// Dir is the working directory for git commands. If empty, the current directory is used.
	Dir string
	// contains filtered or unexported fields
}

CommitExecutor provides methods for executing git commits with message generation.

func NewCommitExecutor

func NewCommitExecutor(client api.ClientInterface, userMessage, userInstructions string) *CommitExecutor

NewCommitExecutor creates a new commit executor with the given configuration.

func NewCommitExecutorInDir

func NewCommitExecutorInDir(client api.ClientInterface, userMessage, userInstructions, dir string) *CommitExecutor

NewCommitExecutorInDir creates a new commit executor that runs git commands in the specified directory.

func NewCommitExecutorWithSecurityCheck

func NewCommitExecutorWithSecurityCheck(client api.ClientInterface, userMessage, userInstructions string, secretCheck SecretCheckHandler) *CommitExecutor

NewCommitExecutorWithSecurityCheck creates a CommitExecutor with a security check callback.

func (*CommitExecutor) ExecuteCommit

func (e *CommitExecutor) ExecuteCommit() (string, error)

ExecuteCommit performs the complete commit operation: 1. Gets staged files and validates there are changes 2. Gets the current branch name 3. Parses file changes into structured format 4. Gets the staged diff 5. Generates commit message (using provided message, LLM, or fallback) 6. Creates commit using a secure temp file 7. Returns the commit hash

This function is designed to be reusable by both the commit tool and commit flow.

type CommitFileChange

type CommitFileChange struct {
	Status string
	Path   string
}

CommitFileChange describes a staged file with git status code.

type CommitMessageOptions

type CommitMessageOptions struct {
	Diff             string
	Branch           string
	FileChanges      []CommitFileChange
	UserInstructions string
}

CommitMessageOptions configures commit message generation behavior.

type CommitMessageResult

type CommitMessageResult struct {
	Message      string
	ApproxTokens int
	Warnings     []string
}

CommitMessageResult contains generated message and diagnostics.

func GenerateCommitMessageFromStagedDiff

func GenerateCommitMessageFromStagedDiff(client api.ClientInterface, opts CommitMessageOptions) (*CommitMessageResult, error)

GenerateCommitMessageFromStagedDiff generates commit text using the same two-pass title+description algorithm used by /commit.

type CommitOptions

type CommitOptions struct {
	SkipPrompt   bool
	AllowSecrets bool
	Model        string
}

CommitOptions contains options for commit operations

type CommitSecurityResult

type CommitSecurityResult struct {
	HasConcerns bool
	Concerns    []security.DetectedSecret
}

CommitSecurityResult holds the result of security checking staged files.

func CheckStagedFilesForSecurityCredentials

func CheckStagedFilesForSecurityCredentials(logger *utils.Logger, dir string) CommitSecurityResult

CheckStagedFilesForSecurityCredentials checks staged files for security credentials and returns a detailed result with the specific concerns found.

type SecretCheckHandler

type SecretCheckHandler func(securityResult CommitSecurityResult) bool

SecretCheckHandler is a callback for handling detected secrets in commit flow. It receives the security result and returns whether to proceed with the commit. Return true to proceed, false to abort.

Jump to

Keyboard shortcuts

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