1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-02-01 13:17:53 +02:00

Stop worktrees view from stealing the window (#2863)

This commit is contained in:
Jesse Duffield 2023-08-02 09:24:51 +10:00 committed by GitHub
commit f7bf125037
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 24 additions and 22 deletions

View File

@ -26,4 +26,5 @@ linters-settings:
max-func-lines: 0 max-func-lines: 0
run: run:
go: 1.20 go: '1.20'
timeout: 10m

View File

@ -3,7 +3,6 @@ package oscommands
import ( import (
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
) )
@ -106,7 +105,7 @@ func CopyDir(src string, dst string) (err error) {
return //nolint: nakedret return //nolint: nakedret
} }
entries, err := ioutil.ReadDir(src) entries, err := os.ReadDir(src)
if err != nil { if err != nil {
return //nolint: nakedret return //nolint: nakedret
} }
@ -121,8 +120,14 @@ func CopyDir(src string, dst string) (err error) {
return //nolint: nakedret return //nolint: nakedret
} }
} else { } else {
var info os.FileInfo
info, err = entry.Info()
if err != nil {
return //nolint: nakedret
}
// Skip symlinks. // Skip symlinks.
if entry.Mode()&os.ModeSymlink != 0 { if info.Mode()&os.ModeSymlink != 0 {
continue continue
} }

View File

@ -1,18 +1,17 @@
package config package config
import ( import (
"io/ioutil"
"os" "os"
"strings" "strings"
) )
func isWSL() bool { func isWSL() bool {
data, err := ioutil.ReadFile("/proc/sys/kernel/osrelease") data, err := os.ReadFile("/proc/sys/kernel/osrelease")
return err == nil && strings.Contains(string(data), "microsoft") return err == nil && strings.Contains(string(data), "microsoft")
} }
func isContainer() bool { func isContainer() bool {
data, err := ioutil.ReadFile("/proc/1/cgroup") data, err := os.ReadFile("/proc/1/cgroup")
if strings.Contains(string(data), "docker") || if strings.Contains(string(data), "docker") ||
strings.Contains(string(data), "/lxc/") || strings.Contains(string(data), "/lxc/") ||

View File

@ -195,7 +195,7 @@ func getExplodeImage(width int, height int, frame int, max int) string {
var buf bytes.Buffer var buf bytes.Buffer
// Initialize RNG seed // Initialize RNG seed
rand.Seed(time.Now().UnixNano()) random := rand.New(rand.NewSource(time.Now().UnixNano()))
// calculate the center of explosion // calculate the center of explosion
centerX, centerY := width/2, height/2 centerX, centerY := width/2, height/2
@ -223,9 +223,9 @@ func getExplodeImage(width int, height int, frame int, max int) string {
// if distance is less than radius and greater than innerRadius, draw explosion char // if distance is less than radius and greater than innerRadius, draw explosion char
if distance <= radius && distance >= innerRadius { if distance <= radius && distance >= innerRadius {
// Make placement random and less likely as explosion progresses // Make placement random and less likely as explosion progresses
if rand.Float64() > progress { if random.Float64() > progress {
// Pick a random explosion char // Pick a random explosion char
char := explosionChars[rand.Intn(len(explosionChars))] char := explosionChars[random.Intn(len(explosionChars))]
buf.WriteRune(char) buf.WriteRune(char)
} else { } else {
buf.WriteRune(' ') buf.WriteRune(' ')

View File

@ -26,10 +26,10 @@ func (gui *Gui) orderedViewNameMappings() []viewNameMapping {
{viewPtr: &gui.Views.Status, name: "status"}, {viewPtr: &gui.Views.Status, name: "status"},
{viewPtr: &gui.Views.Snake, name: "snake"}, {viewPtr: &gui.Views.Snake, name: "snake"},
{viewPtr: &gui.Views.Submodules, name: "submodules"}, {viewPtr: &gui.Views.Submodules, name: "submodules"},
{viewPtr: &gui.Views.Worktrees, name: "worktrees"},
{viewPtr: &gui.Views.Files, name: "files"}, {viewPtr: &gui.Views.Files, name: "files"},
{viewPtr: &gui.Views.Tags, name: "tags"}, {viewPtr: &gui.Views.Tags, name: "tags"},
{viewPtr: &gui.Views.Remotes, name: "remotes"}, {viewPtr: &gui.Views.Remotes, name: "remotes"},
{viewPtr: &gui.Views.Worktrees, name: "worktrees"},
{viewPtr: &gui.Views.Branches, name: "localBranches"}, {viewPtr: &gui.Views.Branches, name: "localBranches"},
{viewPtr: &gui.Views.RemoteBranches, name: "remoteBranches"}, {viewPtr: &gui.Views.RemoteBranches, name: "remoteBranches"},
{viewPtr: &gui.Views.ReflogCommits, name: "reflogCommits"}, {viewPtr: &gui.Views.ReflogCommits, name: "reflogCommits"},

View File

@ -10,7 +10,6 @@ import (
"bytes" "bytes"
"errors" "errors"
"io" "io"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"testing" "testing"
@ -82,7 +81,7 @@ func runCmdHeadless(cmd *exec.Cmd) error {
return err return err
} }
_, _ = io.Copy(ioutil.Discard, f) _, _ = io.Copy(io.Discard, f)
if cmd.Wait() != nil { if cmd.Wait() != nil {
// return an error with the stderr output // return an error with the stderr output

View File

@ -2,7 +2,6 @@ package components
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@ -222,7 +221,7 @@ func findOrCreateDir(path string) {
func deleteAndRecreateEmptyDir(path string) { func deleteAndRecreateEmptyDir(path string) {
// remove contents of integration test directory // remove contents of integration test directory
dir, err := ioutil.ReadDir(path) dir, err := os.ReadDir(path)
if err != nil { if err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
err = os.Mkdir(path, 0o777) err = os.Mkdir(path, 0o777)

View File

@ -12,7 +12,6 @@ import (
"fmt" "fmt"
"go/format" "go/format"
"io/fs" "io/fs"
"io/ioutil"
"os" "os"
"strings" "strings"
@ -26,19 +25,19 @@ func main() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
if err := ioutil.WriteFile("test_list.go", formattedCode, 0o644); err != nil { if err := os.WriteFile("test_list.go", formattedCode, 0o644); err != nil {
panic(err) panic(err)
} }
} }
func generateCode() []byte { func generateCode() []byte {
// traverse parent directory to get all subling directories // traverse parent directory to get all subling directories
directories, err := ioutil.ReadDir("../tests") directories, err := os.ReadDir("../tests")
if err != nil { if err != nil {
panic(err) panic(err)
} }
directories = lo.Filter(directories, func(file os.FileInfo, _ int) bool { directories = lo.Filter(directories, func(file fs.DirEntry, _ int) bool {
// 'shared' is a special folder containing shared test code so we // 'shared' is a special folder containing shared test code so we
// ignore it here // ignore it here
return file.IsDir() && file.Name() != "shared" return file.IsDir() && file.Name() != "shared"
@ -62,8 +61,8 @@ func generateCode() []byte {
return buf.Bytes() return buf.Bytes()
} }
func appendDirTests(dir fs.FileInfo, buf *bytes.Buffer) { func appendDirTests(dir fs.DirEntry, buf *bytes.Buffer) {
files, err := ioutil.ReadDir(fmt.Sprintf("../tests/%s", dir.Name())) files, err := os.ReadDir(fmt.Sprintf("../tests/%s", dir.Name()))
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -77,7 +76,7 @@ func appendDirTests(dir fs.FileInfo, buf *bytes.Buffer) {
strings.TrimSuffix(file.Name(), ".go"), strings.TrimSuffix(file.Name(), ".go"),
) )
fileContents, err := ioutil.ReadFile(fmt.Sprintf("../tests/%s/%s", dir.Name(), file.Name())) fileContents, err := os.ReadFile(fmt.Sprintf("../tests/%s/%s", dir.Name(), file.Name()))
if err != nil { if err != nil {
panic(err) panic(err)
} }