gitcmd

package
v0.6.8 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2025 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildCmdOption

func BuildCmdOption(o *CloneOption) []string

BuildCmdOption constructs the full set of command-line arguments for the Git clone command Follows Git's argument order convention: options → repository URI → target directory

func CloneCmd

func CloneCmd(o *CloneOption) error

CloneCmd executes the Git clone command with the specified options Integrates pterm progress bar for visual progress tracking when Progress is enabled Captures and parses Git's progress output to update the progress bar in real-time

func FormatOption

func FormatOption(o *CloneOption) string

FormatOption formats the Git clone command as a string for debugging purposes

Types

type CloneOption

type CloneOption struct {
	// Uri is the remote or local repository URL/path
	Uri string
	// Target is the local directory to clone the repository into
	Target string
	// Branch is the name of the branch to checkout after cloning
	Branch string
	// Depth specifies the shallow clone depth (0 means full history)
	Depth int
	// Progress enables progress reporting during the clone operation
	Progress bool
	// SingleBranch enables cloning only the specified branch
	SingleBranch bool
	// Recursive enables recursive initialization of submodules
	Recursive bool
	// Bare creates a bare repository (no working directory)
	Bare bool
	// Mirror creates a mirror repository (bare + mirrors all refs)
	Mirror bool
	// Local enables local cloning (uses hardlinks for efficiency)
	Local bool
	// Verbose enables verbose output from the Git command
	Verbose bool
	// Config contains additional Git configuration options (key-value pairs)
	Config map[string]string
}

CloneOption defines the parameters and options for Git clone operations. It configures repository cloning behavior such as branch selection, shallow clone depth, progress display, and repository type (bare/mirror).

func DefaultCloneOption

func DefaultCloneOption() CloneOption

DefaultCloneOption returns a CloneOption with sensible default values

func (*CloneOption) WithBranch

func (opt *CloneOption) WithBranch(branch string) *CloneOption

WithBranch sets the branch to checkout and returns the modified CloneOption

func (*CloneOption) WithDepth

func (opt *CloneOption) WithDepth(depth int) *CloneOption

WithDepth sets the shallow clone depth and returns the modified CloneOption A depth > 0 enables shallow cloning (only fetches the specified number of recent commits)

func (*CloneOption) WithProgress

func (opt *CloneOption) WithProgress(progress bool) *CloneOption

WithProgress enables or disables progress reporting and returns the modified CloneOption

func (*CloneOption) WithSingleBranch

func (opt *CloneOption) WithSingleBranch(singleBranch bool) *CloneOption

WithSingleBranch enables or disables single-branch cloning and returns the modified CloneOption

type SystemGitInfo

type SystemGitInfo struct {
	Found    bool   // Indicates if a valid Git executable was found on the system
	Location string // Absolute path to the Git executable (empty if not found)
	Version  string // Clean parsed Git version (e.g., "2.25.1", empty if detection fails)
	Error    error  // Error encountered during detection (nil if successful)
}

SystemGitInfo holds metadata about the system's Git installation status and details.

func DetectSystemGit

func DetectSystemGit() SystemGitInfo

DetectSystemGit checks for a valid Git installation on the host system. Core functionality: 1. Locates the Git executable using cross-platform commands (which/where) 2. Verifies the executable is functional by retrieving version info 3. Parses the raw version output into a clean, usable string 4. Returns a SystemGitInfo struct with comprehensive detection results

Jump to

Keyboard shortcuts

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