Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 16 additions & 16 deletions pkg/commands/oscommands/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit does not change actual behavior of this functions because err is returned originally because this function uses "named return value".

}
defer in.Close()

out, err := os.Create(dst)
if err != nil {
return //nolint: nakedret
return err
}
defer func() {
if e := out.Close(); e != nil {
Expand All @@ -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)

Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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.
Expand All @@ -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
}
13 changes: 7 additions & 6 deletions pkg/gui/presentation/branches_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down