From c78f79b9b116ae69ecf62b8e948f3d71480eadab Mon Sep 17 00:00:00 2001 From: "go-git-renovate[bot]" <245267575+go-git-renovate[bot]@users.noreply.github.com> Date: Fri, 24 Jul 2026 09:08:17 +0000 Subject: [PATCH 1/2] build: Update dependency golangci/golangci-lint to v2.12.2 Signed-off-by: go-git-renovate[bot] <245267575+go-git-renovate[bot]@users.noreply.github.com> --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index c2accc2..8748f19 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ # renovate: datasource=github-tags depName=golangci/golangci-lint -GOLANGCI_VERSION ?= v2.11.4 +GOLANGCI_VERSION ?= v2.12.2 TOOLS_BIN := $(shell mkdir -p build/tools && realpath build/tools) GOLANGCI = $(TOOLS_BIN)/golangci-lint-$(GOLANGCI_VERSION) From cce8bf0e72571aa5dda8b0bd744778d54bd76f59 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 24 Jul 2026 09:16:57 +0000 Subject: [PATCH 2/2] fix: resolve goconst lint errors and deprecate gomodguard linter --- .golangci.yaml | 1 + cmd/gogit/add_test.go | 5 ++--- cmd/gogit/checkout_pathspec_test.go | 27 +++++++++++++++++---------- cmd/gogit/config_test.go | 4 ++-- cmd/gogit/indexversion.go | 3 ++- cmd/gogit/indexversion_test.go | 12 +++++++----- 6 files changed, 31 insertions(+), 21 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index 820b7e4..747aaf5 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -24,6 +24,7 @@ linters: - revive - wrapcheck - wsl + - gomodguard exclusions: generated: lax presets: diff --git a/cmd/gogit/add_test.go b/cmd/gogit/add_test.go index 8e7c190..c708734 100644 --- a/cmd/gogit/add_test.go +++ b/cmd/gogit/add_test.go @@ -68,9 +68,8 @@ func TestAddWarnsBogusEnvVersion(t *testing.T) { t.Fatalf("add: %v\nstderr: %s", err, stderr) } - wantPrefix := "warning: GIT_INDEX_VERSION set, but the value is invalid.\nUsing version 2\n" - if !strings.HasPrefix(stderr, wantPrefix) { - t.Fatalf("stderr = %q; want prefix %q", stderr, wantPrefix) + if !strings.HasPrefix(stderr, warnEnvVersionInvalid) { + t.Fatalf("stderr = %q; want prefix %q", stderr, warnEnvVersionInvalid) } } diff --git a/cmd/gogit/checkout_pathspec_test.go b/cmd/gogit/checkout_pathspec_test.go index 7ba78cf..0c361f9 100644 --- a/cmd/gogit/checkout_pathspec_test.go +++ b/cmd/gogit/checkout_pathspec_test.go @@ -5,10 +5,17 @@ import ( "testing" ) +const ( + testRepoRoot = "/repo" + testFile0 = "file0" + testDirFile1 = "dir1/file1" + testSubDir1 = "/repo/dir1" +) + func TestResolvePathspec(t *testing.T) { t.Parallel() - root := "/repo" + root := testRepoRoot tests := []struct { name string @@ -17,15 +24,15 @@ func TestResolvePathspec(t *testing.T) { want string wantErr bool }{ - {name: "file at root from root", cwd: "/repo", spec: "file0", want: "file0"}, - {name: "subdir file from root", cwd: "/repo", spec: "dir1/file1", want: "dir1/file1"}, - {name: "dotdot back to root from subdir", cwd: "/repo/dir1", spec: "../file0", want: "file0"}, - {name: "sibling via dotdot", cwd: "/repo/dir1", spec: "../dir2/file2", want: "dir2/file2"}, - {name: "complex relative", cwd: "/repo/dir1", spec: "../dir1/../dir1/file1", want: "dir1/file1"}, - {name: "directory pathspec", cwd: "/repo", spec: "dir1", want: "dir1"}, - {name: "parent escape from root", cwd: "/repo", spec: "../Makefile", wantErr: true}, - {name: "parent file from subdir", cwd: "/repo/dir1", spec: "../file0", want: "file0"}, - {name: "escape from subdir", cwd: "/repo/dir1", spec: "../../file0", wantErr: true}, + {name: "file at root from root", cwd: testRepoRoot, spec: testFile0, want: testFile0}, + {name: "subdir file from root", cwd: testRepoRoot, spec: testDirFile1, want: testDirFile1}, + {name: "dotdot back to root from subdir", cwd: testSubDir1, spec: "../file0", want: testFile0}, + {name: "sibling via dotdot", cwd: testSubDir1, spec: "../dir2/file2", want: "dir2/file2"}, + {name: "complex relative", cwd: testSubDir1, spec: "../dir1/../dir1/file1", want: testDirFile1}, + {name: "directory pathspec", cwd: testRepoRoot, spec: "dir1", want: "dir1"}, + {name: "parent escape from root", cwd: testRepoRoot, spec: "../Makefile", wantErr: true}, + {name: "parent file from subdir", cwd: testSubDir1, spec: "../file0", want: testFile0}, + {name: "escape from subdir", cwd: testSubDir1, spec: "../../file0", wantErr: true}, } for _, tc := range tests { diff --git a/cmd/gogit/config_test.go b/cmd/gogit/config_test.go index 7423070..2d354dd 100644 --- a/cmd/gogit/config_test.go +++ b/cmd/gogit/config_test.go @@ -12,7 +12,7 @@ func TestSplitKV(t *testing.T) { k, v string ok bool }{ - {in: "pack.writeReverseIndex=true", k: "pack.writeReverseIndex", v: "true", ok: true}, + {in: "pack.writeReverseIndex=true", k: "pack.writeReverseIndex", v: gitConfigTrue, ok: true}, {in: "pack.writeReverseIndex=", k: "pack.writeReverseIndex", v: "", ok: true}, {in: "noequals", ok: false}, {in: "", ok: false}, @@ -40,7 +40,7 @@ func TestConfigBoolOverridesRepoConfig(t *testing.T) { t.Fatalf("default false: got %v", got) } - applyConfigOverride("pack.writeReverseIndex", "true") + applyConfigOverride("pack.writeReverseIndex", gitConfigTrue) if got := configBool("pack.writeReverseIndex", nil, false); got != true { t.Fatalf("override true: got %v", got) diff --git a/cmd/gogit/indexversion.go b/cmd/gogit/indexversion.go index 0d3ebd6..eca6c3b 100644 --- a/cmd/gogit/indexversion.go +++ b/cmd/gogit/indexversion.go @@ -11,6 +11,7 @@ import ( const ( defaultIndexVersion uint32 = 2 manyFilesIndexVersion uint32 = 4 + gitConfigTrue = "true" ) // envLookup mirrors os.LookupEnv. Injected so tests can run without touching @@ -58,7 +59,7 @@ func pickIndexVersion(cfg *config.Config, env envLookup, hadExistingIndex bool, } } - if mf := cfg.Raw.Section("feature").Option("manyFiles"); mf == "true" { + if mf := cfg.Raw.Section("feature").Option("manyFiles"); mf == gitConfigTrue { return manyFilesIndexVersion } } diff --git a/cmd/gogit/indexversion_test.go b/cmd/gogit/indexversion_test.go index 57bd112..007c937 100644 --- a/cmd/gogit/indexversion_test.go +++ b/cmd/gogit/indexversion_test.go @@ -8,6 +8,8 @@ import ( gogitconfig "github.com/go-git/go-git/v6/config" ) +const warnEnvVersionInvalid = "warning: GIT_INDEX_VERSION set, but the value is invalid.\nUsing version 2\n" + func TestPickIndexVersion(t *testing.T) { t.Parallel() @@ -26,11 +28,11 @@ func TestPickIndexVersion(t *testing.T) { {name: "env=4", envSet: true, envValue: "4", wantVersion: 4}, { name: "env=2bogus", envSet: true, envValue: "2bogus", wantVersion: 2, - wantWarnPrefix: "warning: GIT_INDEX_VERSION set, but the value is invalid.\nUsing version 2\n", + wantWarnPrefix: warnEnvVersionInvalid, }, { name: "env=1 out of bounds", envSet: true, envValue: "1", wantVersion: 2, - wantWarnPrefix: "warning: GIT_INDEX_VERSION set, but the value is invalid.\nUsing version 2\n", + wantWarnPrefix: warnEnvVersionInvalid, }, {name: "env bogus but existing index", envSet: true, envValue: "1", hadExistingIndex: true, wantVersion: 2}, {name: "config=3 silently demotes to 2", configVersion: "3", wantVersion: 2}, @@ -39,10 +41,10 @@ func TestPickIndexVersion(t *testing.T) { wantWarnPrefix: "warning: index.version set, but the value is invalid.\nUsing version 2\n", }, {name: "config invalid but existing index", configVersion: "5", hadExistingIndex: true, wantVersion: 2}, - {name: "manyFiles default 4", manyFiles: "true", wantVersion: 4}, - {name: "manyFiles overridden by config=2", configVersion: "2", manyFiles: "true", wantVersion: 2}, + {name: "manyFiles default 4", manyFiles: gitConfigTrue, wantVersion: 4}, + {name: "manyFiles overridden by config=2", configVersion: "2", manyFiles: gitConfigTrue, wantVersion: 2}, {name: "env wins over config", envSet: true, envValue: "4", configVersion: "2", wantVersion: 4}, - {name: "env wins over manyFiles", envSet: true, envValue: "2", manyFiles: "true", wantVersion: 2}, + {name: "env wins over manyFiles", envSet: true, envValue: "2", manyFiles: gitConfigTrue, wantVersion: 2}, } for _, tc := range tests {