2018-08-19 06:48:39 +02:00
|
|
|
package test
|
|
|
|
|
|
|
|
import (
|
2019-02-11 12:30:27 +02:00
|
|
|
"github.com/go-errors/errors"
|
2018-08-19 06:48:39 +02:00
|
|
|
"os"
|
|
|
|
"os/exec"
|
2018-08-20 15:21:05 +02:00
|
|
|
"path/filepath"
|
2018-08-19 06:48:39 +02:00
|
|
|
|
|
|
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GenerateRepo generates a repo from test/repos and changes the directory to be
|
|
|
|
// inside the newly made repo
|
|
|
|
func GenerateRepo(filename string) error {
|
2018-08-20 15:21:05 +02:00
|
|
|
reposDir := "/test/repos/"
|
|
|
|
testPath := utils.GetProjectRoot() + reposDir
|
|
|
|
|
|
|
|
// workaround for debian packaging
|
|
|
|
if _, err := os.Stat(testPath); os.IsNotExist(err) {
|
|
|
|
cwd, _ := os.Getwd()
|
|
|
|
testPath = filepath.Dir(filepath.Dir(cwd)) + reposDir
|
|
|
|
}
|
2018-08-19 06:48:39 +02:00
|
|
|
if err := os.Chdir(testPath); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if output, err := exec.Command("bash", filename).CombinedOutput(); err != nil {
|
|
|
|
return errors.New(string(output))
|
|
|
|
}
|
2018-08-21 08:41:31 +02:00
|
|
|
|
|
|
|
return os.Chdir(testPath + "repo")
|
2018-08-19 06:48:39 +02:00
|
|
|
}
|