From 76452a0bcc3978acda1166ae5e40e598db55ca9c Mon Sep 17 00:00:00 2001 From: kyu08 <49891479+kyu08@users.noreply.github.com> Date: Mon, 22 Sep 2025 22:36:53 +0900 Subject: [PATCH 1/4] Add `ignore` directive in go.mod This can be used by go tools such as gofumpt. --- go.mod | 3 +++ 1 file changed, 3 insertions(+) diff --git a/go.mod b/go.mod index a425a279731..81f7d8df325 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,9 @@ module github.com/jesseduffield/lazygit go 1.25.0 +// This is necessary to ignore test files when executing gofumpt. +ignore ./test + require ( dario.cat/mergo v1.0.1 github.com/adrg/xdg v0.4.0 From 65c27dd8ce965338447dcde06ac8d0565bff1e4a Mon Sep 17 00:00:00 2001 From: kyu08 <49891479+kyu08@users.noreply.github.com> Date: Sun, 19 Oct 2025 19:23:02 +0200 Subject: [PATCH 2/4] Remove workaround for "make format" When a new enough gofumpt version is used (v0.9.0 or later), it suports the `ignore` directive that we just added, so the workaround is no longer needed. Co-authored-by: Stefan Haller --- Makefile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 5132211298c..38dc118cb82 100644 --- a/Makefile +++ b/Makefile @@ -34,11 +34,9 @@ test: unit-test integration-test-all generate: go generate ./... -# If you execute `gofumpt -l -w .`, it will format all Go files in the current directory, including `test/_results/*` files. -# We pass only Git-tracked Go files to gofumpt because we don't want to format the test results or get errors from it. .PHONY: format format: - git ls-files '*.go' ':!vendor' | xargs gofumpt -l -w + gofumpt -l -w . .PHONY: lint lint: From beb05d4a61d2374b4b41551f354c3d46644d9c15 Mon Sep 17 00:00:00 2001 From: kyu08 <49891479+kyu08@users.noreply.github.com> Date: Sun, 19 Oct 2025 19:16:23 +0200 Subject: [PATCH 3/4] Fix makeAtomic in branches_test When replacing the naked return with a `return result`, the linter starts to complain about "return copies lock value: sync/atomic.Int32 contains sync/atomic.noCopy". I suspect this is also a problem when using a naked return, and the linter just doesn't catch it in that case. Either way, it's better to use a pointer to ensure that the atomic is not copied. Co-authored-by: Stefan Haller --- pkg/gui/presentation/branches_test.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pkg/gui/presentation/branches_test.go b/pkg/gui/presentation/branches_test.go index 347802a6ee5..a73c7aa56dc 100644 --- a/pkg/gui/presentation/branches_test.go +++ b/pkg/gui/presentation/branches_test.go @@ -16,9 +16,10 @@ import ( "github.com/xo/terminfo" ) -func makeAtomic(v int32) (result atomic.Int32) { +func makeAtomic(v int32) *atomic.Int32 { + var result atomic.Int32 result.Store(v) - return //nolint: nakedret + return &result } func Test_getBranchDisplayStrings(t *testing.T) { @@ -109,7 +110,7 @@ func Test_getBranchDisplayStrings(t *testing.T) { branch: &models.Branch{ Name: "branch_name", Recency: "1m", - BehindBaseBranch: makeAtomic(2), + BehindBaseBranch: *makeAtomic(2), }, itemOperation: types.ItemOperationNone, fullDescription: false, @@ -126,7 +127,7 @@ func Test_getBranchDisplayStrings(t *testing.T) { UpstreamRemote: "origin", AheadForPull: "0", BehindForPull: "0", - BehindBaseBranch: makeAtomic(2), + BehindBaseBranch: *makeAtomic(2), }, itemOperation: types.ItemOperationNone, fullDescription: false, @@ -143,7 +144,7 @@ func Test_getBranchDisplayStrings(t *testing.T) { UpstreamRemote: "origin", AheadForPull: "3", BehindForPull: "5", - BehindBaseBranch: makeAtomic(2), + BehindBaseBranch: *makeAtomic(2), }, itemOperation: types.ItemOperationNone, fullDescription: false, @@ -247,7 +248,7 @@ func Test_getBranchDisplayStrings(t *testing.T) { UpstreamRemote: "origin", AheadForPull: "3", BehindForPull: "5", - BehindBaseBranch: makeAtomic(4), + BehindBaseBranch: *makeAtomic(4), }, itemOperation: types.ItemOperationNone, fullDescription: false, From 64bcc72e458123e301637912c9e631061fb3799d Mon Sep 17 00:00:00 2001 From: kyu08 <49891479+kyu08@users.noreply.github.com> Date: Mon, 22 Sep 2025 22:42:58 +0900 Subject: [PATCH 4/4] Specify return value where named return value is used After [v0.9.0](https://github.com/mvdan/gofumpt/releases/tag/v0.9.0), gofumpt prohibits "naked return" for the sake of clarity. This makes more readable when "named return value" is used. For more infomation for "prohibition of naked return": https://github.com/mvdan/gofumpt/issues/285. --- pkg/commands/oscommands/copy.go | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/pkg/commands/oscommands/copy.go b/pkg/commands/oscommands/copy.go index c6d83e23b00..2df96d05729 100644 --- a/pkg/commands/oscommands/copy.go +++ b/pkg/commands/oscommands/copy.go @@ -35,16 +35,16 @@ import ( // destination file exists, all it's contents will be replaced by the contents // of the source file. The file mode will be copied from the source and // the copied data is synced/flushed to stable storage. -func CopyFile(src, dst string) (err error) { +func CopyFile(src, dst string) error { in, err := os.Open(src) if err != nil { - return //nolint: nakedret + return err } defer in.Close() out, err := os.Create(dst) if err != nil { - return //nolint: nakedret + return err } defer func() { if e := out.Close(); e != nil { @@ -54,30 +54,30 @@ func CopyFile(src, dst string) (err error) { _, err = io.Copy(out, in) if err != nil { - return //nolint: nakedret + return err } err = out.Sync() if err != nil { - return //nolint: nakedret + return err } si, err := os.Stat(src) if err != nil { - return //nolint: nakedret + return err } err = os.Chmod(dst, si.Mode()) if err != nil { - return //nolint: nakedret + return err } - return //nolint: nakedret + return err } // CopyDir recursively copies a directory tree, attempting to preserve permissions. // Source directory must exist. If destination already exists we'll clobber it. // Symlinks are ignored and skipped. -func CopyDir(src string, dst string) (err error) { +func CopyDir(src string, dst string) error { src = filepath.Clean(src) dst = filepath.Clean(dst) @@ -91,7 +91,7 @@ func CopyDir(src string, dst string) (err error) { _, err = os.Stat(dst) if err != nil && !os.IsNotExist(err) { - return //nolint: nakedret + return err } if err == nil { // it exists so let's remove it @@ -102,12 +102,12 @@ func CopyDir(src string, dst string) (err error) { err = os.MkdirAll(dst, si.Mode()) if err != nil { - return //nolint: nakedret + return err } entries, err := os.ReadDir(src) if err != nil { - return //nolint: nakedret + return err } for _, entry := range entries { @@ -117,13 +117,13 @@ func CopyDir(src string, dst string) (err error) { if entry.IsDir() { err = CopyDir(srcPath, dstPath) if err != nil { - return //nolint: nakedret + return err } } else { var info os.FileInfo info, err = entry.Info() if err != nil { - return //nolint: nakedret + return err } // Skip symlinks. @@ -133,10 +133,10 @@ func CopyDir(src string, dst string) (err error) { err = CopyFile(srcPath, dstPath) if err != nil { - return //nolint: nakedret + return err } } } - return //nolint: nakedret + return err }