{"record":{"id":"445be243b3680754","repo":"golangci/golangci-lint","slug":"get-git-root-w","errorCode":null,"errorMessage":"get git root: %w","messagePattern":"get git root: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/fsutils/basepath.go","lineNumber":51,"sourceCode":"\tcase RelativePathModeCfg:\n\t\tif cfgDir == \"\" {\n\t\t\treturn GetBasePath(ctx, RelativePathModeWd, cfgDir)\n\t\t}\n\n\t\treturn cfgDir, nil\n\n\tcase RelativePathModeGoMod:\n\t\tgoMod, err := goenv.GetOne(ctx, goenv.GOMOD)\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"get go.mod path: %w\", err)\n\t\t}\n\n\t\treturn filepath.Dir(goMod), nil\n\n\tcase RelativePathModeGitRoot:\n\t\troot, err := gitRoot(ctx)\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"get git root: %w\", err)\n\t\t}\n\n\t\treturn root, nil\n\n\tcase RelativePathModeWd:\n\t\twd, err := Getwd()\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"get wd: %w\", err)\n\t\t}\n\n\t\treturn wd, nil\n\n\tdefault:\n\t\treturn \"\", fmt.Errorf(\"unknown relative path mode: %s\", mode)\n\t}\n}\n\nfunc gitRoot(ctx context.Context) (string, error) {","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/fsutils/basepath.go#L33-L69","documentation":"GetBasePath returns this wrapped error when the relative path mode is RelativePathModeGitRoot and gitRoot(ctx) fails. gitRoot runs `git rev-parse --show-toplevel`; any failure (not a git repository, git not installed, command error) is preserved via %w. golangci-lint uses the repo root to make reported file paths relative.","triggerScenarios":"Running golangci-lint with run.relative-path-mode: git-root outside a git work tree, in a repository with ownership/safe.directory problems, or where the git binary is missing.","commonSituations":"Downloading a project as a zip (no .git) and running the linter in it; CI checkouts with dubious-ownership errors; Docker images that strip the git binary.","solutions":["Run golangci-lint inside a git repository (git clone instead of downloading archives)","Fix git environment issues shown in the wrapped error, e.g. `git config --global --add safe.directory <path>` for ownership errors, or install git","Change run.relative-path-mode to 'gomod' or 'wd' when a git root is unavailable"],"exampleFix":"// before (config)\nrun:\n  relative-path-mode: git-root\n// after\nrun:\n  relative-path-mode: wd","handlingStrategy":"try-catch","validationCode":"cmd := exec.Command(\"git\", \"rev-parse\", \"--show-toplevel\")\nif err := cmd.Run(); err != nil {\n  return fmt.Errorf(\"not inside a git work tree; git-root path mode will fail\")\n}","typeGuard":null,"tryCatchPattern":"basePath, err := fsutils.GetBasePath(ctx, fsutils.RelativePathModeGitRoot)\nif err != nil {\n  // fall back to wd mode or fix git env per wrapped error\n  basePath, err = fsutils.GetBasePath(ctx, fsutils.RelativePathModeWd)\n}","preventionTips":["git clone repositories rather than downloading archives","Add safe.directory config for ownership-sensitive CI containers","Keep the git binary installed in lint containers","Fall back to wd/gomod mode when no git root exists"],"tags":["git","filesystem","path-resolution"],"backgroundTag":"git-root-not-found","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}