gitutil

package
v0.78.0 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

gitutil package provides utility functions for working with git repositories. To execute git operations we use the go-git library. However the library does not support all git operations and in those cases we directly run git commands. The utility functions in this file directly run git commands.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrGitRemoteNotFound = errors.New("no git remotes found")
	ErrNotAGitRepository = errors.New("not a git repository")
)

Functions

func Clone added in v0.64.1

func Clone(ctx context.Context, path string, c *Config) (*git.Repository, error)

func CloneRepo

func CloneRepo(repoURL string) (string, error)

func CommitAndPush added in v0.78.0

func CommitAndPush(ctx context.Context, projectPath string, config *Config, commitMsg string, author *object.Signature) error

func GitFetch added in v0.78.0

func GitFetch(ctx context.Context, path string, config *Config) error

func InferGitRepoRoot added in v0.78.0

func InferGitRepoRoot(path string) (string, error)

func InferRepoRootAndSubpath added in v0.78.0

func InferRepoRootAndSubpath(path string) (string, string, error)

InferRepoRootAndSubpath infers the root of the Git repository and the subpath from the given path. Since the extraction stops at first .git directory it means that if a subpath in a github monorepo is deployed as a rill managed project it will prevent the subpath from being inferred. This means : - user will need to explicitly set the subpath if they want to connect this to Github. - When finding matching projects it will only list the rill managed projects for that subpath.

func IsGitRepo added in v0.78.0

func IsGitRepo(path string) bool

func NativeGitSignature added in v0.78.0

func NativeGitSignature(ctx context.Context, path string) (*object.Signature, error)

func NormalizeGithubRemote added in v0.78.0

func NormalizeGithubRemote(remote string) (string, error)

NormalizeGithubRemote validates and converts a Git remote to a normalized HTTPS Github URL ending in .git.

func RunGitFetch added in v0.78.0

func RunGitFetch(ctx context.Context, path, remote string) error

func RunGitPull added in v0.78.0

func RunGitPull(ctx context.Context, path string, discardLocal bool, remote, remoteName string) (string, error)

RunGitPull runs a git pull command in the specified path.

func RunGitPush added in v0.78.0

func RunGitPush(ctx context.Context, path, remoteName, branchName string) error

func RunUpstreamMerge added in v0.78.0

func RunUpstreamMerge(ctx context.Context, remote, path, branch string, favourLocal bool) error

func SetRemote added in v0.78.0

func SetRemote(path string, config *Config) error

SetRemote sets the remote by name Rill for the given repository to the provided remote URL.

func SplitGithubRemote added in v0.78.0

func SplitGithubRemote(remote string) (account, repo string, ok bool)

SplitGithubRemote splits a GitHub remote URL into a Github account and repository name.

Types

type Config added in v0.64.1

type Config struct {
	Remote            string
	Username          string
	Password          string
	PasswordExpiresAt time.Time
	DefaultBranch     string
	Subpath           string
	ManagedRepo       bool
}

func (*Config) FullyQualifiedRemote added in v0.78.0

func (g *Config) FullyQualifiedRemote() (string, error)

func (*Config) IsExpired added in v0.64.1

func (g *Config) IsExpired() bool

func (*Config) RemoteName added in v0.78.0

func (g *Config) RemoteName() string

type GitStatus added in v0.78.0

type GitStatus struct {
	Branch        string
	RemoteURL     string
	LocalChanges  bool // true if there are local changes (staged, unstaged, or untracked)
	LocalCommits  int32
	RemoteCommits int32
}

func RunGitStatus added in v0.78.0

func RunGitStatus(path, subpath, remoteName string) (GitStatus, error)

type Remote added in v0.22.0

type Remote struct {
	Name string
	URL  string
}

Remote represents a Git remote with its name and URL. The URL is normalized to a HTTPS URL with a .git suffix.

func ExtractGitRemote added in v0.24.0

func ExtractGitRemote(projectPath, remoteName string, detectDotGit bool) (Remote, error)

ExtractGitRemote extracts the first Git remote from the Git repository at projectPath. If remoteName is provided, it will return the remote with that name. If detectDotGit is true, it will look for a .git directory in parent directories.

func ExtractRemotes added in v0.22.0

func ExtractRemotes(projectPath string, detectDotGit bool) ([]Remote, error)

ExtractRemotes extracts all Git remotes from the Git repository at projectPath. The returned remotes are normalized with NormalizeGithubRemote. If detectDotGit is true, it will look for a .git directory in parent directories.

func (Remote) Github added in v0.78.0

func (r Remote) Github() (string, error)

Github returns a normalized HTTPS Github URL ending in .git for the remote.

Jump to

Keyboard shortcuts

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