git

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package git provides a wrapper around common git commands.

Index

Constants

This section is empty.

Variables

View Source
var ExecCommand = exec.Command

ExecCommand is a variable that holds the exec.Command function This allows it to be mocked in tests

Functions

This section is empty.

Types

type Branch

type Branch struct {
	Name       string
	IsCurrent  bool
	LastCommit string
}

Branch represents a git branch with its metadata.

type BranchOptions

type BranchOptions struct {
	Create bool
	Delete bool
	Name   string
}

BranchOptions specifies the options for managing branches.

type CommitLog

type CommitLog struct {
	Graph          string // The graph structure string.
	SHA            string // The abbreviated commit hash.
	AuthorInitials string // The initials of the commit author.
	Subject        string // The subject line of the commit message.
}

CommitLog represents a single entry in the git log graph. It can be a commit or a line representing the graph structure.

type CommitOptions

type CommitOptions struct {
	Message string
	Amend   bool
}

CommitOptions specifies the options for the git commit command.

type DiffOptions

type DiffOptions struct {
	Commit1 string
	Commit2 string
	Cached  bool
	Stat    bool
	Color   bool
}

DiffOptions specifies the options for the git diff command.

type GitCommands

type GitCommands struct{}

GitCommands provides an interface to execute Git commands.

func NewGitCommands

func NewGitCommands() *GitCommands

NewGitCommands creates a new instance of GitCommands.

func (*GitCommands) AddFiles

func (g *GitCommands) AddFiles(paths []string) (string, error)

AddFiles adds file contents to the index (staging area).

func (*GitCommands) BlameFile

func (g *GitCommands) BlameFile(filePath string) (string, error)

BlameFile shows what revision and author last modified each line of a file.

func (*GitCommands) Checkout

func (g *GitCommands) Checkout(branchName string) (string, error)

Checkout switches branches or restores working tree files.

func (*GitCommands) CloneRepository

func (g *GitCommands) CloneRepository(repoURL, directory string) (string, error)

CloneRepository clones a repository from a given URL into a specified directory.

func (*GitCommands) Commit

func (g *GitCommands) Commit(options CommitOptions) (string, error)

Commit records changes to the repository.

func (*GitCommands) Fetch

func (g *GitCommands) Fetch(remote string, branch string) (string, error)

Fetch downloads objects and refs from another repository.

func (*GitCommands) GetBranches

func (g *GitCommands) GetBranches() ([]*Branch, error)

GetBranches fetches all local branches, their last commit time, and sorts them.

func (*GitCommands) GetCommitLogsGraph

func (g *GitCommands) GetCommitLogsGraph() ([]CommitLog, error)

GetCommitLogsGraph fetches the git log with a graph format and returns it as a slice of CommitLog structs.

func (*GitCommands) GetGitRepoPath

func (g *GitCommands) GetGitRepoPath() (repoPath string, err error)

func (*GitCommands) GetRepoInfo

func (g *GitCommands) GetRepoInfo() (repoName string, branchName string, err error)

GetRepoInfo returns the current repository and active branch name.

func (*GitCommands) GetStashes

func (g *GitCommands) GetStashes() ([]*Stash, error)

GetStashes fetches all stashes and returns them as a slice of Stash structs.

func (*GitCommands) GetStatus

func (g *GitCommands) GetStatus(options StatusOptions) (string, error)

GetStatus retrieves the git status and returns it as a string.

func (*GitCommands) GetUserName

func (g *GitCommands) GetUserName() (string, error)

GetUserName returns the user's name from the git config.

func (*GitCommands) InitRepository

func (g *GitCommands) InitRepository(path string) (string, error)

InitRepository initializes a new Git repository in the specified path.

func (*GitCommands) ListFiles

func (g *GitCommands) ListFiles() (string, error)

ListFiles shows information about files in the index and the working tree.

func (*GitCommands) ManageBranch

func (g *GitCommands) ManageBranch(options BranchOptions) (string, error)

ManageBranch creates or deletes branches.

func (*GitCommands) ManageRemote

func (g *GitCommands) ManageRemote(options RemoteOptions) (string, error)

ManageRemote manages the set of repositories ("remotes") whose branches you track.

func (*GitCommands) ManageTag

func (g *GitCommands) ManageTag(options TagOptions) (string, error)

ManageTag creates, lists, deletes or verifies a tag object signed with GPG.

func (*GitCommands) Merge

func (g *GitCommands) Merge(options MergeOptions) (string, error)

Merge joins two or more development histories together.

func (*GitCommands) MoveFile

func (g *GitCommands) MoveFile(source, destination string) (string, error)

MoveFile moves or renames a file, a directory, or a symlink.

func (*GitCommands) Pull

func (g *GitCommands) Pull(options PullOptions) (string, error)

Pull fetches from and integrates with another repository or a local branch.

func (*GitCommands) Push

func (g *GitCommands) Push(options PushOptions) (string, error)

Push updates remote refs along with associated objects.

func (*GitCommands) Rebase

func (g *GitCommands) Rebase(options RebaseOptions) (string, error)

Rebase integrates changes from another branch.

func (*GitCommands) RemoveFiles

func (g *GitCommands) RemoveFiles(paths []string, cached bool) (string, error)

RemoveFiles removes files from the working tree and from the index.

func (*GitCommands) RenameBranch

func (g *GitCommands) RenameBranch(oldName, newName string) (string, error)

RenameBranch renames a branch.

func (*GitCommands) ResetFiles

func (g *GitCommands) ResetFiles(paths []string) (string, error)

ResetFiles resets the current HEAD to the specified state, unstaging files.

func (*GitCommands) Restore

func (g *GitCommands) Restore(options RestoreOptions) (string, error)

Restore restores working tree files.

func (*GitCommands) Revert

func (g *GitCommands) Revert(commitHash string) (string, error)

Revert is used to record some new commits to reverse the effect of some earlier commits.

func (*GitCommands) ShowCommit

func (g *GitCommands) ShowCommit(commitHash string) (string, error)

ShowCommit shows the details of a specific commit.

func (*GitCommands) ShowDiff

func (g *GitCommands) ShowDiff(options DiffOptions) (string, error)

ShowDiff shows changes between commits, commit and working tree, etc.

func (*GitCommands) ShowLog

func (g *GitCommands) ShowLog(options LogOptions) (string, error)

ShowLog executes the `git log` command with the given options and returns the raw output.

func (*GitCommands) Stash

func (g *GitCommands) Stash(options StashOptions) (string, error)

Stash saves your local modifications away and reverts the working directory to match the HEAD commit.

func (*GitCommands) Switch

func (g *GitCommands) Switch(branchName string) (string, error)

Switch switches to a specified branch.

type LogOptions

type LogOptions struct {
	Oneline  bool
	Graph    bool
	All      bool
	MaxCount int
	Format   string
	Color    string
	Branch   string
}

LogOptions specifies the options for the git log command.

type MergeOptions

type MergeOptions struct {
	BranchName    string
	NoFastForward bool
	Message       string
}

MergeOptions specifies the options for the git merge command.

type PullOptions

type PullOptions struct {
	Remote string
	Branch string
	Rebase bool
}

PullOptions specifies the options for the git pull command.

type PushOptions

type PushOptions struct {
	Remote      string
	Branch      string
	Force       bool
	SetUpstream bool
	Tags        bool
}

PushOptions specifies the options for the git push command.

type RebaseOptions

type RebaseOptions struct {
	BranchName  string
	Interactive bool
	Abort       bool
	Continue    bool
}

RebaseOptions specifies the options for the git rebase command.

type RemoteOptions

type RemoteOptions struct {
	Add     bool
	Remove  bool
	Name    string
	URL     string
	Verbose bool
}

RemoteOptions specifies the options for managing remotes.

type RestoreOptions

type RestoreOptions struct {
	Paths      []string
	Source     string
	Staged     bool
	WorkingDir bool
}

RestoreOptions specifies the options for the git restore command.

type Stash

type Stash struct {
	Name    string
	Branch  string
	Message string
}

Stash represents a single entry in the git stash list.

type StashOptions

type StashOptions struct {
	Push    bool
	Pop     bool
	Apply   bool
	List    bool
	Show    bool
	Drop    bool
	Message string
	StashID string
}

StashOptions specifies the options for the git stash command.

type StatusOptions

type StatusOptions struct {
	Porcelain bool
}

StatusOptions specifies arguments for git status command.

type TagOptions

type TagOptions struct {
	Create  bool
	Delete  bool
	Name    string
	Message string
	Commit  string
}

TagOptions specifies the options for managing tags.

Jump to

Keyboard shortcuts

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