Documentation
¶
Overview ¶
Package git provides a wrapper around common git commands.
Index ¶
- Variables
- type Branch
- type BranchOptions
- type CommitLog
- type CommitOptions
- type DiffOptions
- type GitCommands
- func (g *GitCommands) AddFiles(paths []string) (string, error)
- func (g *GitCommands) BlameFile(filePath string) (string, error)
- func (g *GitCommands) Checkout(branchName string) (string, error)
- func (g *GitCommands) CloneRepository(repoURL, directory string) (string, error)
- func (g *GitCommands) Commit(options CommitOptions) (string, error)
- func (g *GitCommands) Fetch(remote string, branch string) (string, error)
- func (g *GitCommands) GetBranches() ([]*Branch, error)
- func (g *GitCommands) GetCommitLogsGraph() ([]CommitLog, error)
- func (g *GitCommands) GetGitRepoPath() (repoPath string, err error)
- func (g *GitCommands) GetRepoInfo() (repoName string, branchName string, err error)
- func (g *GitCommands) GetStashes() ([]*Stash, error)
- func (g *GitCommands) GetStatus(options StatusOptions) (string, error)
- func (g *GitCommands) GetUserName() (string, error)
- func (g *GitCommands) InitRepository(path string) (string, error)
- func (g *GitCommands) ListFiles() (string, error)
- func (g *GitCommands) ManageBranch(options BranchOptions) (string, error)
- func (g *GitCommands) ManageRemote(options RemoteOptions) (string, error)
- func (g *GitCommands) ManageTag(options TagOptions) (string, error)
- func (g *GitCommands) Merge(options MergeOptions) (string, error)
- func (g *GitCommands) MoveFile(source, destination string) (string, error)
- func (g *GitCommands) Pull(options PullOptions) (string, error)
- func (g *GitCommands) Push(options PushOptions) (string, error)
- func (g *GitCommands) Rebase(options RebaseOptions) (string, error)
- func (g *GitCommands) RemoveFiles(paths []string, cached bool) (string, error)
- func (g *GitCommands) RenameBranch(oldName, newName string) (string, error)
- func (g *GitCommands) ResetFiles(paths []string) (string, error)
- func (g *GitCommands) Restore(options RestoreOptions) (string, error)
- func (g *GitCommands) Revert(commitHash string) (string, error)
- func (g *GitCommands) ShowCommit(commitHash string) (string, error)
- func (g *GitCommands) ShowDiff(options DiffOptions) (string, error)
- func (g *GitCommands) ShowLog(options LogOptions) (string, error)
- func (g *GitCommands) Stash(options StashOptions) (string, error)
- func (g *GitCommands) Switch(branchName string) (string, error)
- type LogOptions
- type MergeOptions
- type PullOptions
- type PushOptions
- type RebaseOptions
- type RemoteOptions
- type RestoreOptions
- type Stash
- type StashOptions
- type StatusOptions
- type TagOptions
Constants ¶
This section is empty.
Variables ¶
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 BranchOptions ¶
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 ¶
CommitOptions specifies the options for the git commit command.
type DiffOptions ¶
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.
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 ¶
MergeOptions specifies the options for the git merge command.
type PullOptions ¶
PullOptions specifies the options for the git pull command.
type PushOptions ¶
PushOptions specifies the options for the git push command.
type RebaseOptions ¶
RebaseOptions specifies the options for the git rebase command.
type RemoteOptions ¶
RemoteOptions specifies the options for managing remotes.
type RestoreOptions ¶
RestoreOptions specifies the options for the git restore command.
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.