in plugin.go [66:121]
func downloadPluginTasksFromRepo(repo string) error {
isNameValid, repoName := checkGitRepo(repo)
if !isNameValid {
return fmt.Errorf("plugin repository must be a https url and plugin must start with 'olaris-'")
}
pluginDir, err := homedir.Expand("~/.ops/" + repoName)
if err != nil {
return err
}
if isDir(pluginDir) {
fmt.Println("Updating plugin", repoName)
r, err := git.PlainOpen(pluginDir)
if err != nil {
return err
}
// Get the working directory for the repository
w, err := r.Worktree()
if err != nil {
return err
}
// Pull the latest changes from the origin remote and merge into the current branch
err = w.Pull(&git.PullOptions{RemoteName: "origin"})
if err != nil {
if err.Error() == "already up-to-date" {
fmt.Println("The plugin repo is already up to date!")
return nil
}
return err
}
return nil
}
if err := os.MkdirAll(pluginDir, 0755); err != nil {
return err
}
// if not, clone
cloneOpts := &git.CloneOptions{
URL: repo,
Progress: os.Stderr,
ReferenceName: plumbing.NewBranchReferenceName("main"),
}
fmt.Println("Downloading plugins:", repoName)
_, err = git.PlainClone(pluginDir, false, cloneOpts)
if err != nil {
return err
}
return nil
}