Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FetchFile ¶
FetchFile fetches a single file from a remote Git repository based on a git-style URI.
It performs the following steps:
- Checks if the 'git' executable is available (RequireGit).
- Checks if the 'git' version meets the minimum requirement (v2.25 is required for modern sparse-checkout features) (RequireGitVersion).
- Parses the URI to extract the repo URL, ref, and resource path (ParseURI).
- Creates a temporary directory.
- Initializes a local git repository in the temporary directory.
- Adds the remote repository.
- Attempts to fetch the specified ref (branch, tag, or commit hash).
- 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.**
- 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 ¶
IsGitURI checks if a given URI string follows one of the recognized git-style URL formats that can be parsed by ParseURI.
func ParseURI ¶
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:
- https://github.com/org/repo/blob/main/path/to/file.yaml
- https://bitbucket.org/org/repo/src/commit-hash/path/to/file.yaml
- https://gitlab.com/org/repo/-/blob/v1.0.0/path/to/file.yaml
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:
- ssh://git@gitlab.com/org/repo/-/main/path/to/resource.yaml
- git@github.com:org/repo/-/v2.0/path/to/resource.yaml
- https://git.example.com/project/repo/-/feature/new-api#path/to/resource.yaml
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 ¶
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.