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
1 change: 1 addition & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ linters:
- revive
- wrapcheck
- wsl
- gomodguard
exclusions:
generated: lax
presets:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
5 changes: 2 additions & 3 deletions cmd/gogit/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
27 changes: 17 additions & 10 deletions cmd/gogit/checkout_pathspec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions cmd/gogit/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion cmd/gogit/indexversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
Expand Down
12 changes: 7 additions & 5 deletions cmd/gogit/indexversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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},
Expand All @@ -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 {
Expand Down
Loading