mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-12 12:55:47 +02:00
Use lazycore utils: Clamp and GetLazyRootDirectory
This commit is contained in:
parent
05089b9a9a
commit
39e84e13f4
11 changed files with 61 additions and 43 deletions
45
vendor/github.com/jesseduffield/lazycore/pkg/utils/utils.go
generated
vendored
45
vendor/github.com/jesseduffield/lazycore/pkg/utils/utils.go
generated
vendored
|
@ -1,5 +1,11 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// Min returns the minimum of two integers
|
||||
func Min(x, y int) int {
|
||||
if x < y {
|
||||
|
@ -8,9 +14,48 @@ func Min(x, y int) int {
|
|||
return y
|
||||
}
|
||||
|
||||
// Max returns the maximum of two integers
|
||||
func Max(x, y int) int {
|
||||
if x > y {
|
||||
return x
|
||||
}
|
||||
return y
|
||||
}
|
||||
|
||||
// Clamp returns a value x restricted between min and max
|
||||
func Clamp(x int, min int, max int) int {
|
||||
if x < min {
|
||||
return min
|
||||
} else if x > max {
|
||||
return max
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
// GetLazyRootDirectory finds a lazy project root directory.
|
||||
//
|
||||
// It's used for cheatsheet scripts and integration tests. Not to be confused with finding the
|
||||
// root directory of _any_ random repo.
|
||||
func GetLazyRootDirectory() 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 lazy project folder or child folder")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue