summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorGustavo Andrioli <gusaandrioli@gmail.com>2022-10-15 13:47:55 -0300
committerGustavo Andrioli <gusaandrioli@gmail.com>2022-10-15 13:55:44 -0300
commit39e84e13f4ed80ff94b2a1fc6e66685c24fa6d1e (patch)
treef640b2a2e78f8485dbc9a6d504c1366e19c67224 /pkg
parent05089b9a9a26502c2c4b92f20e60979ce02bca67 (diff)
Use lazycore utils: Clamp and GetLazyRootDirectory
Diffstat (limited to 'pkg')
-rw-r--r--pkg/cheatsheet/check.go2
-rw-r--r--pkg/cheatsheet/generate.go8
-rw-r--r--pkg/integration/clients/tui.go4
-rw-r--r--pkg/integration/components/runner.go4
-rw-r--r--pkg/integration/tests/tests.go4
-rw-r--r--pkg/utils/utils.go27
6 files changed, 11 insertions, 38 deletions
diff --git a/pkg/cheatsheet/check.go b/pkg/cheatsheet/check.go
index 6123e4aa5..5c4df97ef 100644
--- a/pkg/cheatsheet/check.go
+++ b/pkg/cheatsheet/check.go
@@ -12,7 +12,7 @@ import (
)
func Check() {
- dir := GetDir()
+ dir := GetKeybindingsDir()
tmpDir := filepath.Join(os.TempDir(), "lazygit_cheatsheet")
err := os.RemoveAll(tmpDir)
if err != nil {
diff --git a/pkg/cheatsheet/generate.go b/pkg/cheatsheet/generate.go
index 3b9d9c2d1..437db154d 100644
--- a/pkg/cheatsheet/generate.go
+++ b/pkg/cheatsheet/generate.go
@@ -15,12 +15,12 @@ import (
"github.com/jesseduffield/generics/maps"
"github.com/jesseduffield/generics/slices"
+ "github.com/jesseduffield/lazycore/pkg/utils"
"github.com/jesseduffield/lazygit/pkg/app"
"github.com/jesseduffield/lazygit/pkg/config"
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/i18n"
- "github.com/jesseduffield/lazygit/pkg/utils"
"github.com/samber/lo"
)
@@ -44,8 +44,8 @@ func CommandToRun() string {
return "go run scripts/cheatsheet/main.go generate"
}
-func GetDir() string {
- return utils.GetLazygitRootDirectory() + "/docs/keybindings"
+func GetKeybindingsDir() string {
+ return utils.GetLazyRootDirectory() + "/docs/keybindings"
}
func generateAtDir(cheatsheetDir string) {
@@ -75,7 +75,7 @@ func generateAtDir(cheatsheetDir string) {
}
func Generate() {
- generateAtDir(GetDir())
+ generateAtDir(GetKeybindingsDir())
}
func writeString(file *os.File, str string) {
diff --git a/pkg/integration/clients/tui.go b/pkg/integration/clients/tui.go
index 656d16877..7a1ebf615 100644
--- a/pkg/integration/clients/tui.go
+++ b/pkg/integration/clients/tui.go
@@ -9,12 +9,12 @@ import (
"github.com/jesseduffield/generics/slices"
"github.com/jesseduffield/gocui"
+ "github.com/jesseduffield/lazycore/pkg/utils"
"github.com/jesseduffield/lazygit/pkg/gui"
"github.com/jesseduffield/lazygit/pkg/gui/style"
"github.com/jesseduffield/lazygit/pkg/integration/components"
"github.com/jesseduffield/lazygit/pkg/integration/tests"
"github.com/jesseduffield/lazygit/pkg/secureexec"
- "github.com/jesseduffield/lazygit/pkg/utils"
)
// This program lets you run integration tests from a TUI. See pkg/integration/README.md for more info.
@@ -22,7 +22,7 @@ import (
var SLOW_KEY_PRESS_DELAY = 300
func RunTUI() {
- rootDir := utils.GetLazygitRootDirectory()
+ rootDir := utils.GetLazyRootDirectory()
testDir := filepath.Join(rootDir, "test", "integration")
app := newApp(testDir)
diff --git a/pkg/integration/components/runner.go b/pkg/integration/components/runner.go
index 26ac57875..d25f3795c 100644
--- a/pkg/integration/components/runner.go
+++ b/pkg/integration/components/runner.go
@@ -7,8 +7,8 @@ import (
"os/exec"
"path/filepath"
+ "github.com/jesseduffield/lazycore/pkg/utils"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
- "github.com/jesseduffield/lazygit/pkg/utils"
)
// this is the integration runner for the new and improved integration interface
@@ -44,7 +44,7 @@ func RunTests(
keyPressDelay int,
maxAttempts int,
) error {
- projectRootDir := utils.GetLazygitRootDirectory()
+ projectRootDir := utils.GetLazyRootDirectory()
err := os.Chdir(projectRootDir)
if err != nil {
return err
diff --git a/pkg/integration/tests/tests.go b/pkg/integration/tests/tests.go
index d59177c7e..21f06a376 100644
--- a/pkg/integration/tests/tests.go
+++ b/pkg/integration/tests/tests.go
@@ -8,6 +8,7 @@ import (
"github.com/jesseduffield/generics/set"
"github.com/jesseduffield/generics/slices"
+ "github.com/jesseduffield/lazycore/pkg/utils"
"github.com/jesseduffield/lazygit/pkg/integration/components"
"github.com/jesseduffield/lazygit/pkg/integration/tests/bisect"
"github.com/jesseduffield/lazygit/pkg/integration/tests/branch"
@@ -15,7 +16,6 @@ import (
"github.com/jesseduffield/lazygit/pkg/integration/tests/commit"
"github.com/jesseduffield/lazygit/pkg/integration/tests/custom_commands"
"github.com/jesseduffield/lazygit/pkg/integration/tests/interactive_rebase"
- "github.com/jesseduffield/lazygit/pkg/utils"
)
// Here is where we lists the actual tests that will run. When you create a new test,
@@ -53,7 +53,7 @@ func GetTests() []*components.IntegrationTest {
missingTestNames := []string{}
- if err := filepath.Walk(filepath.Join(utils.GetLazygitRootDirectory(), "pkg/integration/tests"), func(path string, info os.FileInfo, err error) error {
+ if err := filepath.Walk(filepath.Join(utils.GetLazyRootDirectory(), "pkg/integration/tests"), func(path string, info os.FileInfo, err error) error {
if !info.IsDir() && strings.HasSuffix(path, ".go") {
// ignoring this current file
if filepath.Base(path) == "tests.go" {
diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go
index 9d6213c1d..2f33862e8 100644
--- a/pkg/utils/utils.go
+++ b/pkg/utils/utils.go
@@ -135,30 +135,3 @@ func FilePath(skip int) string {
_, path, _, _ := runtime.Caller(skip)
return path
}
-
-// for our cheatsheet script and integration tests. Not to be confused with finding the
-// root directory of _any_ random repo.
-func GetLazygitRootDirectory() string {
- path, err := os.Getwd()
- if err != nil {
- panic(err)
- }
-
- for {
- _, err := os.Stat(filepath.Join(path, ".git"))
-
- if err == nil {
- return path
- }
-
- if !os.IsNotExist(err) {
- panic(err)
- }
-
- path = filepath.Dir(path)
-
- if path == "/" {
- log.Fatal("must run in lazygit folder or child folder")
- }
- }
-}