Documentation
¶
Overview ¶
Package git wraps os/exec calls to the git binary. All functions shell out to git plumbing commands and return structured results.
Index ¶
- Variables
- func AddFile(ctx context.Context, indexPath, filePath string) error
- func CommitMessage(ctx context.Context, rev string) (string, error)
- func CommitTree(ctx context.Context, treeSHA, parentSHA, message string) (string, error)
- func CommonGitDir(ctx context.Context) (string, error)
- func GitDir(ctx context.Context) (string, error)
- func HeadRef(ctx context.Context) (string, error)
- func IsIgnored(ctx context.Context, filePath string) (bool, error)
- func IsTracked(ctx context.Context, filePath string) (bool, error)
- func ReadTree(ctx context.Context, indexPath, treeish string) error
- func RepoRoot(ctx context.Context) (string, error)
- func RevParse(ctx context.Context, rev string) (string, error)
- func RmCached(ctx context.Context, indexPath, filePath string) error
- func Run(ctx context.Context, args ...string) (stdout, stderr string, err error)
- func RunPassthrough(ctx context.Context, args ...string) error
- func RunWithEnv(ctx context.Context, env []string, args ...string) (stdout, stderr string, err error)
- func RunWithEnvStdin(ctx context.Context, env []string, stdin []byte, args ...string) (stdout, stderr string, err error)
- func SyncMainIndex(ctx context.Context, treeish string) error
- func UpdateRef(ctx context.Context, ref, newSHA, oldSHA string) error
- func WriteTree(ctx context.Context, indexPath string) (string, error)
Constants ¶
This section is empty.
Variables ¶
var ErrDetachedHead = fmt.Errorf("HEAD is detached (not on a branch); check out a branch first or use --branch")
ErrDetachedHead is returned when HEAD is not on a branch.
Functions ¶
func CommitMessage ¶
CommitMessage returns the full commit message of the given revision.
func CommitTree ¶
CommitTree creates a commit object from a tree SHA and parent, returns commit SHA. If parentSHA is empty, creates a root commit.
func CommonGitDir ¶ added in v0.1.1
CommonGitDir returns the path to the shared .git directory. For normal repos this equals GitDir(); for worktrees it returns the main .git dir that is shared across all worktrees. Lock files should live here so that worktrees committing to the same branch serialize correctly.
func HeadRef ¶
HeadRef returns the current branch ref (e.g. "refs/heads/main"). Returns ErrDetachedHead if HEAD is not on a branch.
func IsTracked ¶
IsTracked checks whether a file is tracked by git (present in HEAD tree). Uses cat-file instead of ls-files because safegit never writes to the main index -- files committed via safegit exist in HEAD but not in .git/index.
func RunPassthrough ¶ added in v0.1.1
RunPassthrough executes a git command with stdin/stdout/stderr wired to the terminal (os.Stdin, os.Stdout, os.Stderr). It prepends --no-optional-locks like Run, but does not capture output -- suitable for interactive/pager commands.
func RunWithEnv ¶
func RunWithEnv(ctx context.Context, env []string, args ...string) (stdout, stderr string, err error)
RunWithEnv executes a git command with additional environment variables.
func RunWithEnvStdin ¶
func RunWithEnvStdin(ctx context.Context, env []string, stdin []byte, args ...string) (stdout, stderr string, err error)
RunWithEnvStdin executes a git command with environment variables and stdin data.
func SyncMainIndex ¶
SyncMainIndex updates the main .git/index to match the given treeish. This makes git status/diff reflect the committed state after safegit commits.
Types ¶
This section is empty.