gitutil

package
v1.23.3 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package gitutil provides shared Git repository helpers used across multiple internal packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CommitsSince added in v1.20.0

func CommitsSince(ctx context.Context, root string, since time.Duration) map[string]int

CommitsSince returns the number of commits touching each file under root since the given duration ago. Uses `git log --since=<dur> --name-only --pretty=format:` and counts file occurrences. Returns empty map on any error (best-effort — no error returned). Timeout: 5s.

func FileDiffSince added in v1.20.0

func FileDiffSince(ctx context.Context, root, file string, since time.Duration, maxLines int) string

FileDiffSince returns a unified diff of file (relative to root) between the commit at HEAD and the commit just before the since-duration window. Caps output at maxLines diff lines (excluding git diff header). Returns "" on any error or if file unchanged. Timeout: 10s.

func IsGitRepo

func IsGitRepo(root string) bool

IsGitRepo reports whether root is the root of a git repository.

It accepts both forms of the .git entry:

  • a directory: standard single-worktree repository
  • a regular file: linked worktree created by "git worktree add" (the file contains a "gitdir: ..." pointer to the main repo)

Anything other than a stat error at <root>/.git is treated as a valid git repo — downstream git commands will surface a more precise error if the entry is malformed.

func OriginURL added in v1.21.0

func OriginURL(ctx context.Context, root string) string

OriginURL returns the configured origin remote URL for the repo at root, or "" when there is no origin remote or git fails for any reason (best-effort, matching CommitsSince's degraded-mode convention — callers treat "" as "no shared identity").

Types

This section is empty.

Jump to

Keyboard shortcuts

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