2022-07-16 15:46:09 +00:00
|
|
|
package dependencies
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os/exec"
|
|
|
|
|
2022-08-03 11:17:15 +00:00
|
|
|
"git.home.m-and-m.ovh/mderasse/gouick/helpers/models"
|
2022-07-16 15:46:09 +00:00
|
|
|
"github.com/juju/errors"
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
2022-08-03 11:17:15 +00:00
|
|
|
// Git represent an empty struct respecting the DependencyInterface.
|
2022-07-16 15:46:09 +00:00
|
|
|
type Git struct{}
|
|
|
|
|
|
|
|
// regroup all git dependencies function
|
|
|
|
|
2022-08-03 11:17:15 +00:00
|
|
|
// GetName return the name of the dependency using DependencyName enum.
|
|
|
|
func (g Git) GetName() models.DependencyName {
|
|
|
|
return models.DependencyName_GIT
|
2022-07-16 15:46:09 +00:00
|
|
|
}
|
|
|
|
|
2022-08-03 11:17:15 +00:00
|
|
|
// GetMinimumVersion return the minimum version required for that dependency.
|
2022-07-16 15:46:09 +00:00
|
|
|
func (g Git) GetMinimumVersion() string {
|
|
|
|
return "0.0.0"
|
|
|
|
}
|
|
|
|
|
2022-08-03 11:17:15 +00:00
|
|
|
// IsInstalled check if the dependency is installed on the system.
|
2022-07-16 15:46:09 +00:00
|
|
|
func (g Git) IsInstalled() (bool, error) {
|
|
|
|
_, err := g.GetBinaryPath()
|
|
|
|
if err != nil && !errors.Is(err, exec.ErrNotFound) {
|
|
|
|
return false, errors.Trace(err)
|
|
|
|
} else if err != nil && errors.Is(err, exec.ErrNotFound) {
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
2022-08-03 11:17:15 +00:00
|
|
|
// GetBinaryPath will search for the binary and return the path if found.
|
2022-07-16 15:46:09 +00:00
|
|
|
func (g Git) GetBinaryPath() (string, error) {
|
|
|
|
log.Debug("looking for git binary")
|
|
|
|
|
|
|
|
path, err := exec.LookPath("git")
|
|
|
|
if err != nil {
|
|
|
|
return "", errors.Trace(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Debug("found git binary in", path)
|
|
|
|
|
|
|
|
return path, nil
|
|
|
|
}
|
|
|
|
|
2022-08-03 11:17:15 +00:00
|
|
|
// GetVersion will find the current version of the dependency.
|
2022-07-16 15:46:09 +00:00
|
|
|
func (g Git) GetVersion() (string, error) {
|
|
|
|
isInstalled, err := g.IsInstalled()
|
|
|
|
if err != nil {
|
|
|
|
return "", errors.Trace(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !isInstalled {
|
|
|
|
return "", errors.NotFoundf("git is not installed on the system")
|
|
|
|
}
|
|
|
|
|
|
|
|
return "0.0.0", nil
|
|
|
|
}
|
|
|
|
|
2022-08-03 11:17:15 +00:00
|
|
|
// IsVersionSupported will compare the current version with the minimum expected version.
|
2022-07-16 15:46:09 +00:00
|
|
|
func (g Git) IsVersionSupported() (bool, error) {
|
|
|
|
isInstalled, err := g.IsInstalled()
|
|
|
|
if err != nil {
|
|
|
|
return false, errors.Trace(err)
|
|
|
|
}
|
|
|
|
if !isInstalled {
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
2022-08-03 11:17:15 +00:00
|
|
|
// CanBeInstalled define if the dependency installation is handled by the app.
|
2022-07-16 15:46:09 +00:00
|
|
|
func (g Git) CanBeInstalled() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2022-08-03 11:17:15 +00:00
|
|
|
// DescribeInstall will do nothing for that dependency.
|
2022-07-16 15:46:09 +00:00
|
|
|
func (g Git) DescribeInstall(path string) string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2022-08-03 11:17:15 +00:00
|
|
|
// Install will do nothing for that dependency.
|
2022-07-16 15:46:09 +00:00
|
|
|
func (g Git) Install(path string) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-08-03 11:17:15 +00:00
|
|
|
// DescribePostInstall will do nothing for that dependency.
|
2022-07-16 15:46:09 +00:00
|
|
|
func (g Git) DescribePostInstall(path string) string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2022-08-03 11:17:15 +00:00
|
|
|
// PostInstall will do nothing for that dependency.
|
2022-07-16 15:46:09 +00:00
|
|
|
func (g Git) PostInstall(path string) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-08-03 11:17:15 +00:00
|
|
|
// GetInstallDirectory will do nothing for that dependency.
|
2022-07-16 15:46:09 +00:00
|
|
|
func (g Git) GetInstallDirectory() (string, error) {
|
|
|
|
return "", nil
|
|
|
|
}
|