Use ignore directive to ignore test files not to be passes to gofumpt (#4936)

### Motivation
To replace the workaround introduced in
https://github.com/jesseduffield/lazygit/pull/4809 with `ignore`
directive to make the code simpler.

### Overview
This is a follow-up PR to
https://github.com/jesseduffield/lazygit/pull/4809.
I have added 4 changes due to updating gofumpt to remove `git ls-files`
workaround.

Please take a look at each commit messages for details.
This commit is contained in:
Stefan Haller 2025-10-20 07:59:40 +02:00 committed by GitHub
commit 32a701cb9c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 27 additions and 25 deletions

View file

@ -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:

3
go.mod
View file

@ -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

View file

@ -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
}

View file

@ -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,