Documentation
¶
Overview ¶
Package git provides Git operations for gitcode-cli
Index ¶
- Variables
- func Clone(repo *Repo, dir string, depth int) error
- func CloneWithProtocol(repo *Repo, dir string, protocol string, depth int) error
- func CurrentBranch() (string, error)
- func DefaultRemote() (string, error)
- func HasLocalChanges() (bool, error)
- func IsRepo() bool
- func RemoteURL(name string) (string, error)
- func Remotes() ([]string, error)
- func RootDir() (string, error)
- func Run(args ...string) (string, error)
- func RunInDir(dir string, args ...string) (string, error)
- func RunInDirWithEnv(dir string, env map[string]string, args ...string) (string, error)
- func RunWithEnv(env map[string]string, args ...string) (string, error)
- func SafeCheckout(branch string) error
- func SafeCheckoutWithOutput(stdout, stderr io.Writer, dir string, branch string) error
- func SafeFetch(remote, ref, localBranch string) error
- func SafeFetchFromURL(fetchURL, ref, localBranch string) error
- func SafeFetchFromURLWithOutput(stdout, stderr io.Writer, dir, fetchURL, ref, localBranch string) error
- func SafeFetchWithOutput(stdout, stderr io.Writer, dir, remote, ref, localBranch string) error
- func ValidateDir(dir string) error
- func ValidateFetchURL(rawURL string) error
- func ValidateRef(ref string) error
- type Repo
Constants ¶
This section is empty.
Variables ¶
ErrInvalidDir is returned when a directory argument fails validation.
ErrInvalidRef is returned when a git ref fails validation.
Functions ¶
func Clone ¶
Clone clones a repository to the specified directory
func CloneWithProtocol ¶
CloneWithProtocol clones a repository using the specified protocol
func CurrentBranch ¶
CurrentBranch returns the current branch name
func DefaultRemote ¶
DefaultRemote returns the default remote (origin or first available)
func HasLocalChanges ¶
HasLocalChanges returns true if there are uncommitted changes
func RootDir ¶
RootDir returns the root directory of the git repository
func Run ¶
Run executes a git command and returns the output
func RunInDir ¶
RunInDir executes a git command in a specific directory
func RunInDirWithEnv ¶ added in v0.3.9
RunInDirWithEnv executes a git command in a specific directory with extra environment variables.
func RunWithEnv ¶ added in v0.3.9
RunWithEnv executes a git command with extra environment variables.
func SafeCheckout ¶ added in v0.7.0
SafeCheckout runs "git checkout <branch>" after validating the branch name. This prevents option-injection attacks where a branch name starts with "-".
func SafeCheckoutWithOutput ¶ added in v0.7.0
SafeCheckoutWithOutput runs "git checkout <branch>" after validating the branch name, streaming stdout/stderr to the provided writers.
func SafeFetch ¶ added in v0.7.0
SafeFetch runs "git fetch <remote> -- <ref>:<localBranch>" after validating both the remote ref and the local branch name. All parameters including "remote" are validated to prevent option-injection.
func SafeFetchFromURL ¶ added in v0.7.0
SafeFetchFromURL runs "git fetch <fetchURL> -- <ref>:<localBranch>" after validating both the URL and the ref names. This is used when fetching from a fork or external repository.
func SafeFetchFromURLWithOutput ¶ added in v0.7.0
func SafeFetchFromURLWithOutput(stdout, stderr io.Writer, dir, fetchURL, ref, localBranch string) error
SafeFetchFromURLWithOutput runs a validated git fetch from a URL, streaming output.
func SafeFetchWithOutput ¶ added in v0.7.0
SafeFetchWithOutput runs a validated git fetch, streaming output. All parameters including "remote" are validated to prevent option-injection.
func ValidateDir ¶ added in v0.7.0
ValidateDir validates that a directory argument is safe for use as a git command argument (e.g. the target directory of "git clone"). It rejects:
- Empty strings
- Strings starting with "-" (prevent option injection)
- Strings containing control characters
func ValidateFetchURL ¶ added in v0.7.0
ValidateFetchURL validates a git fetch/push URL. It rejects:
- Empty strings
- URLs starting with "-" (prevent option injection via dash-prefixed host)
- URLs with invalid or unexpected schemes
func ValidateRef ¶ added in v0.7.0
ValidateRef validates that a git ref (branch, tag, or remote ref) is safe for use as a git command argument. It rejects:
- Empty strings
- Strings starting with "-" (prevent option injection)
- Strings with control characters, spaces, or shell metacharacters
- Strings that don't match the expected ref pattern
Types ¶
type Repo ¶
Repo represents a parsed repository reference
func CurrentRepo ¶
CurrentRepo returns the current repository from git remote
func ParseRepo ¶
ParseRepo parses a repository reference Supports formats: - owner/repo - https://gitcode.com/owner/repo - git@gitcode.com:owner/repo.git
func (*Repo) GitURL ¶
GitURL returns the git URL for the repository
func (*Repo) String ¶
String returns the full repository path (owner/name)
Source Files
¶
- git.go
- repo.go