From 280b0429c3892efe7ff656c7e868828c5793979c Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Wed, 2 Aug 2023 07:37:40 +1000 Subject: [PATCH 1/3] Fix focus issue When opening lazygit with `lazygit log` the worktrees view was appearing in front of the files view. This is because it had higher precedence than the files view in the ordered view mapping, and that was because it originally was in the branches window so it was further down the list. The reason this didn't cause issues on typical startup is that the files context is activated at the start so it is brought to the front. --- pkg/gui/views.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/gui/views.go b/pkg/gui/views.go index 9527e4392..d9cf15ffe 100644 --- a/pkg/gui/views.go +++ b/pkg/gui/views.go @@ -26,10 +26,10 @@ func (gui *Gui) orderedViewNameMappings() []viewNameMapping { {viewPtr: &gui.Views.Status, name: "status"}, {viewPtr: &gui.Views.Snake, name: "snake"}, {viewPtr: &gui.Views.Submodules, name: "submodules"}, + {viewPtr: &gui.Views.Worktrees, name: "worktrees"}, {viewPtr: &gui.Views.Files, name: "files"}, {viewPtr: &gui.Views.Tags, name: "tags"}, {viewPtr: &gui.Views.Remotes, name: "remotes"}, - {viewPtr: &gui.Views.Worktrees, name: "worktrees"}, {viewPtr: &gui.Views.Branches, name: "localBranches"}, {viewPtr: &gui.Views.RemoteBranches, name: "remoteBranches"}, {viewPtr: &gui.Views.ReflogCommits, name: "reflogCommits"}, From df0c3b3ea877dd56b2c33e54fafd9aeb3b087c24 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Wed, 2 Aug 2023 08:10:23 +1000 Subject: [PATCH 2/3] Increase timeout for linter we've had a timeout issue in CI --- .golangci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index c458277ed..d9c67792e 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -26,4 +26,5 @@ linters-settings: max-func-lines: 0 run: - go: 1.20 + go: '1.20' + timeout: 10m From c92ed07082b4f888eec0c9d5e31d44499bcf5b44 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Wed, 2 Aug 2023 08:21:55 +1000 Subject: [PATCH 3/3] Appease linter --- pkg/commands/oscommands/copy.go | 11 ++++++++--- pkg/config/config_linux.go | 5 ++--- pkg/gui/controllers/workspace_reset_controller.go | 6 +++--- pkg/integration/clients/go_test.go | 3 +-- pkg/integration/components/runner.go | 3 +-- pkg/integration/tests/test_list_generator.go | 13 ++++++------- 6 files changed, 21 insertions(+), 20 deletions(-) diff --git a/pkg/commands/oscommands/copy.go b/pkg/commands/oscommands/copy.go index e68d0cfce..aab460e47 100644 --- a/pkg/commands/oscommands/copy.go +++ b/pkg/commands/oscommands/copy.go @@ -3,7 +3,6 @@ package oscommands import ( "fmt" "io" - "io/ioutil" "os" "path/filepath" ) @@ -106,7 +105,7 @@ func CopyDir(src string, dst string) (err error) { return //nolint: nakedret } - entries, err := ioutil.ReadDir(src) + entries, err := os.ReadDir(src) if err != nil { return //nolint: nakedret } @@ -121,8 +120,14 @@ func CopyDir(src string, dst string) (err error) { return //nolint: nakedret } } else { + var info os.FileInfo + info, err = entry.Info() + if err != nil { + return //nolint: nakedret + } + // Skip symlinks. - if entry.Mode()&os.ModeSymlink != 0 { + if info.Mode()&os.ModeSymlink != 0 { continue } diff --git a/pkg/config/config_linux.go b/pkg/config/config_linux.go index 7f6187ee3..892e58de3 100644 --- a/pkg/config/config_linux.go +++ b/pkg/config/config_linux.go @@ -1,18 +1,17 @@ package config import ( - "io/ioutil" "os" "strings" ) 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") } func isContainer() bool { - data, err := ioutil.ReadFile("/proc/1/cgroup") + data, err := os.ReadFile("/proc/1/cgroup") if strings.Contains(string(data), "docker") || strings.Contains(string(data), "/lxc/") || diff --git a/pkg/gui/controllers/workspace_reset_controller.go b/pkg/gui/controllers/workspace_reset_controller.go index 195a9699e..6b78c6ac9 100644 --- a/pkg/gui/controllers/workspace_reset_controller.go +++ b/pkg/gui/controllers/workspace_reset_controller.go @@ -195,7 +195,7 @@ func getExplodeImage(width int, height int, frame int, max int) string { var buf bytes.Buffer // Initialize RNG seed - rand.Seed(time.Now().UnixNano()) + random := rand.New(rand.NewSource(time.Now().UnixNano())) // calculate the center of explosion 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 <= radius && distance >= innerRadius { // Make placement random and less likely as explosion progresses - if rand.Float64() > progress { + if random.Float64() > progress { // Pick a random explosion char - char := explosionChars[rand.Intn(len(explosionChars))] + char := explosionChars[random.Intn(len(explosionChars))] buf.WriteRune(char) } else { buf.WriteRune(' ') diff --git a/pkg/integration/clients/go_test.go b/pkg/integration/clients/go_test.go index 851059e15..18d8569bd 100644 --- a/pkg/integration/clients/go_test.go +++ b/pkg/integration/clients/go_test.go @@ -10,7 +10,6 @@ import ( "bytes" "errors" "io" - "io/ioutil" "os" "os/exec" "testing" @@ -82,7 +81,7 @@ func runCmdHeadless(cmd *exec.Cmd) error { return err } - _, _ = io.Copy(ioutil.Discard, f) + _, _ = io.Copy(io.Discard, f) if cmd.Wait() != nil { // return an error with the stderr output diff --git a/pkg/integration/components/runner.go b/pkg/integration/components/runner.go index 40921fee9..32acdf25f 100644 --- a/pkg/integration/components/runner.go +++ b/pkg/integration/components/runner.go @@ -2,7 +2,6 @@ package components import ( "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -222,7 +221,7 @@ func findOrCreateDir(path string) { func deleteAndRecreateEmptyDir(path string) { // remove contents of integration test directory - dir, err := ioutil.ReadDir(path) + dir, err := os.ReadDir(path) if err != nil { if os.IsNotExist(err) { err = os.Mkdir(path, 0o777) diff --git a/pkg/integration/tests/test_list_generator.go b/pkg/integration/tests/test_list_generator.go index 294165cca..f616f90a3 100644 --- a/pkg/integration/tests/test_list_generator.go +++ b/pkg/integration/tests/test_list_generator.go @@ -12,7 +12,6 @@ import ( "fmt" "go/format" "io/fs" - "io/ioutil" "os" "strings" @@ -26,19 +25,19 @@ func main() { if err != nil { 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) } } func generateCode() []byte { // traverse parent directory to get all subling directories - directories, err := ioutil.ReadDir("../tests") + directories, err := os.ReadDir("../tests") if err != nil { 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 // ignore it here return file.IsDir() && file.Name() != "shared" @@ -62,8 +61,8 @@ func generateCode() []byte { return buf.Bytes() } -func appendDirTests(dir fs.FileInfo, buf *bytes.Buffer) { - files, err := ioutil.ReadDir(fmt.Sprintf("../tests/%s", dir.Name())) +func appendDirTests(dir fs.DirEntry, buf *bytes.Buffer) { + files, err := os.ReadDir(fmt.Sprintf("../tests/%s", dir.Name())) if err != nil { panic(err) } @@ -77,7 +76,7 @@ func appendDirTests(dir fs.FileInfo, buf *bytes.Buffer) { 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 { panic(err) }