git

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FetchFile

func FetchFile(file string) (string, string, error)

FetchFile fetches a single file from a remote Git repository based on a git-style URI.

It performs the following steps:

  1. Checks if the 'git' executable is available (RequireGit).
  2. Checks if the 'git' version meets the minimum requirement (v2.25 is required for modern sparse-checkout features) (RequireGitVersion).
  3. Parses the URI to extract the repo URL, ref, and resource path (ParseURI).
  4. Creates a temporary directory.
  5. Initializes a local git repository in the temporary directory.
  6. Adds the remote repository.
  7. Attempts to fetch the specified ref (branch, tag, or commit hash).
  8. Initializes and sets up a **sparse-checkout** to fetch only the directory containing the resource (to minimize fetch size and time). **This means the contents of the directory where the resource resides are also downloaded.**
  9. Checks out the fetched 'local' branch.

It returns the full local path to the fetched file, the path to the temporary directory, and an error if the operation fails at any step. The caller is responsible for cleaning up the returned temporary directory.

func IsGitURI

func IsGitURI(uri string) bool

IsGitURI checks if a given URI string follows one of the recognized git-style URL formats that can be parsed by ParseURI.

func ParseURI

func ParseURI(uri string) (string, string, string, error)

ParseURI attempts to split a git-style URI into its three core components: the Repository URL, the Revision Reference (ref), and the Resource Path within the repository.

1. The function primarily recognizes common web-view formats:

a. GitHub web-view: <GIT_REPO>/blob/<REF>/<RESOURCE>
b. BitBucket web-view: <GIT_REPO>/src/<REF>/<RESOURCE>
c. GitLab web-view: <GIT_REPO>/-/blob/<REF>/<RESOURCE>

Web-view URI Examples:

2. The function also accepts more generic style formats:

a. <GIT_REPO>/-/<REF>/<RESOURCE>
b. <GIT_REPO>/-/<REF>#<RESOURCE> (Use '#' when REF contains a forward slash '/')

Generic Style URI Examples:

It returns: (repoURL, ref, resourcePath, error)

func RequireGit

func RequireGit() error

RequireGit checks for the presence of the 'git' executable in the system's PATH. It returns an error if the command is not found.

func RequireGitVersion

func RequireGitVersion(requiredMajor int, requiredMinor int) error

RequireGitVersion checks that the installed Git client meets or exceeds the specified major and minor version numbers. This is critical for ensuring features like sparse-checkout are available.

Types

This section is empty.

Jump to

Keyboard shortcuts

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