Documentation
¶
Index ¶
- func AddFile(filePath string) error
- func CloneRepo(url string, clonePath string, auth transport.AuthMethod) (*git.Repository, error)
- func Commit(repo *git.Repository, msg string) error
- func CreateTag(repo *git.Repository, tag string) error
- func DeletePushedTag(repo *git.Repository, tag string, auth transport.AuthMethod) error
- func DeleteTag(repo *git.Repository, tag string) error
- func GetTags(repo *git.Repository) ([]string, error)
- func PullRepos(dirs ...string) error
- func Push(repo *git.Repository, auth transport.AuthMethod) error
- func PushTag(repo *git.Repository, tag string, auth transport.AuthMethod) error
- func RepoRoot() (string, error)
- type ConfigUserInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddFile ¶
AddFile stages the file at the given file path in its associated Git repository. Returns an error if one occurs.
Parameters:
filePath: A string representing the path to the file to be staged.
Returns:
error: An error if one occurs during the staging process.
Example:
filePath := "/path/to/your/file" err := AddFile(filePath)
if err != nil {
log.Fatalf("failed to stage file: %v", err)
}
log.Printf("Staged file: %s", filePath)
func CloneRepo ¶
func CloneRepo(url string, clonePath string, auth transport.AuthMethod) ( *git.Repository, error)
CloneRepo clones the repo specified with the input url to provided clonePath.
func Commit ¶
func Commit(repo *git.Repository, msg string) error
Commit creates a new commit in the given repository with the provided message. The author of the commit is retrieved from the global Git user settings.
Parameters:
repo: A pointer to the Repository struct representing the repository where the commit should be created.
msg: A string representing the commit message.
Returns:
error: An error if the commit cannot be created.
Example:
repo, err := git.PlainOpen("/path/to/repo")
if err != nil {
log.Fatalf("failed to open repository: %v", err)
}
msg := "Commit message" err = Commit(repo, msg)
if err != nil {
log.Fatalf("failed to create commit: %v", err)
}
func CreateTag ¶
func CreateTag(repo *git.Repository, tag string) error
CreateTag is used to create an input tag in the specified repo if it doesn't already exist. Resource: https://github.com/go-git/go-git/blob/bf3471db54b0255ab5b159005069f37528a151b7/_examples/tag-create-push/main.go
func DeletePushedTag ¶
func DeletePushedTag(repo *git.Repository, tag string, auth transport.AuthMethod) error
DeletePushedTag deletes a tag from a given repository that has been pushed remote. The tag is deleted from both the local repository and the remote repository.
Parameters:
repo: A pointer to the Repository struct representing the repository where the tag should be deleted.
tag: A string representing the tag that should be deleted.
auth: An AuthMethod representing the method used to authenticate with the remote repository.
Returns:
error: An error if the tag cannot be deleted.
Example:
repo, err := git.PlainOpen("/path/to/repo")
if err != nil {
log.Fatalf("failed to open repository: %v", err)
}
tag := "v1.0.0" auth, err := ssh.NewSSHAgentAuth("git")
if err != nil {
log.Fatalf("failed to create authentication method: %v", err)
}
err = DeletePushedTag(repo, tag, auth)
if err != nil {
log.Fatalf("failed to delete pushed tag: %v", err)
}
func DeleteTag ¶
func DeleteTag(repo *git.Repository, tag string) error
DeleteTag deletes the local input tag from the specified repo.
Parameters:
repo: A pointer to the Repository struct representing the repository where the tag should be deleted.
tag: A string representing the tag that should be deleted.
auth: An AuthMethod representing the method used to authenticate with the remote repository.
Returns:
error: An error if the tag cannot be deleted.
Example:
repo, err := git.PlainOpen("/path/to/repo")
if err != nil {
log.Fatalf("failed to open repository: %v", err)
}
tag := "v1.0.0" auth, err := ssh.NewSSHAgentAuth("git")
if err != nil {
log.Fatalf("failed to create authentication method: %v", err)
}
err = DeletePushedTag(repo, tag, auth)
if err != nil {
log.Fatalf("failed to delete pushed tag: %v", err)
}
func GetTags ¶
func GetTags(repo *git.Repository) ([]string, error)
GetTags returns the tags for an input repo.
func PullRepos ¶
PullRepos updates all git repositories found in the given directories by pulling changes from the upstream branch. It looks for repositories by finding directories with a ".git" subdirectory. If a repository is not on the default branch, it will switch to the default branch before pulling changes. Returns an error if any step of the process fails.
func Push ¶
func Push(repo *git.Repository, auth transport.AuthMethod) error
Push pushes the contents of the input repo to the default remote (origin).
func PushTag ¶
func PushTag(repo *git.Repository, tag string, auth transport.AuthMethod) error
PushTag is used to push a tag to remote.
Types ¶
type ConfigUserInfo ¶
ConfigUserInfo holds a username and email to use for user.name and user.email.
func GetGlobalUserCfg ¶
func GetGlobalUserCfg() (ConfigUserInfo, error)
GetGlobalUserCfg returns the username and email from the global git user settings.