gitutil

package
v3.40.2 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2022 License: Apache-2.0 Imports: 15 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetGitReferenceNameOrHashAndSubDirectory

func GetGitReferenceNameOrHashAndSubDirectory(url string, urlPath string) (
	plumbing.ReferenceName, plumbing.Hash, string, error,
)

GetGitReferenceNameOrHashAndSubDirectory returns the reference name or hash, and sub directory path. The sub directory path always uses "/" as the separator.

func GetGitRemoteURL

func GetGitRemoteURL(repo *git.Repository, remoteName string) (string, error)

GetGitRemoteURL returns the remote URL for the given remoteName in the repo.

func GetGitRepository

func GetGitRepository(dir string) (*git.Repository, error)

GetGitRepository returns the git repository by walking up from the provided directory. If no repository is found, will return (nil, nil).

func GitCloneAndCheckoutCommit

func GitCloneAndCheckoutCommit(url string, commit plumbing.Hash, path string) error

GitCloneAndCheckoutCommit clones the Git repository and checkouts the specified commit.

func GitCloneOrPull

func GitCloneOrPull(rawurl string, referenceName plumbing.ReferenceName, path string, shallow bool) error

func GitListBranchesAndTags

func GitListBranchesAndTags(url string) ([]plumbing.ReferenceName, error)

GitListBranchesAndTags fetches a remote Git repository's branch and tag references (including HEAD), sorted by the length of the short name descending.

func IsGitOriginURLGitHub

func IsGitOriginURLGitHub(remoteURL string) bool

IsGitOriginURLGitHub returns true if the provided remoteURL is detected as GitHub.

func ParseGitRepoURL

func ParseGitRepoURL(rawurl string) (string, string, error)

ParseGitRepoURL returns the URL to the Git repository and path from a raw URL. For example, an input of "https://github.com/pulumi/templates/templates/javascript" returns "https://github.com/pulumi/templates.git" and "templates/javascript". Additionally, it supports nested git projects, as used by GitLab. For example, "https://github.com/pulumi/platform-team/templates.git/templates/javascript" returns "https://github.com/pulumi/platform-team/templates.git" and "templates/javascript"

Note: URL with a hostname of `dev.azure.com`, are currently treated as a raw git clone url and currently do not support subpaths.

Types

type VCSInfo

type VCSInfo struct {
	Owner string
	Repo  string
	Kind  VCSKind
}

VCSInfo describes a cloud-hosted version control system. Cloud hosted VCS' typically have an owner (could be an organization), to whom the repo belongs.

func GetGitHubProjectForOrigin

func GetGitHubProjectForOrigin(dir string) (*VCSInfo, error)

GetGitHubProjectForOrigin returns the GitHub login, and GitHub repo name if the "origin" remote is a GitHub URL.

func TryGetVCSInfo

func TryGetVCSInfo(remoteURL string) (*VCSInfo, error)

TryGetVCSInfo attempts to detect whether the provided remoteURL is an SSH or an HTTPS remote URL. It then extracts the repo, owner name, and the type (kind) of VCS from it.

type VCSKind

type VCSKind = string

VCSKind represents the hostname of a specific type of VCS. For eg., github.com, gitlab.com etc.

const (

	// The host name for GitLab.
	GitLabHostName VCSKind = "gitlab.com"
	// The host name for GitHub.
	GitHubHostName VCSKind = "github.com"
	// The host name for Azure DevOps
	AzureDevOpsHostName VCSKind = "dev.azure.com"
	// The host name for Bitbucket
	BitbucketHostName VCSKind = "bitbucket.org"
)

Constants related to detecting the right type of source control provider for git.

Jump to

Keyboard shortcuts

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