{"record":{"id":"cf3860406b77fda1","repo":"plandex-ai/plandex","slug":"error-initializing-git-repo-v","errorCode":null,"errorMessage":"error initializing git repo: %v","messagePattern":"error initializing git repo: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/server/db/diff_helpers.go","lineNumber":40,"sourceCode":"\t\treturn \"\", fmt.Errorf(\"error getting current plan state: %v\", err)\n\t}\n\n\t// create temp directory\n\ttempDirPath, err := os.MkdirTemp(getOrgDir(orgId), \"tmp-diffs-*\")\n\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"error creating temp dir: %v\", err)\n\t}\n\n\tdefer func() {\n\t\tgo os.RemoveAll(tempDirPath)\n\t}()\n\n\t// init a git repo in the temp dir\n\terr = initGitRepo(tempDirPath)\n\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"error initializing git repo: %v\", err)\n\t}\n\n\tfiles := planState.CurrentPlanFiles.Files\n\tremoved := planState.CurrentPlanFiles.Removed\n\n\t// write the original files to the temp dir\n\terrCh := make(chan error, len(planState.ContextsByPath))\n\thasAnyOriginal := false\n\n\tfor path, context := range planState.ContextsByPath {\n\t\tgo func(path string, context *shared.Context) {\n\t\t\tdefer func() {\n\t\t\t\tif r := recover(); r != nil {\n\t\t\t\t\tlog.Printf(\"panic in GetPlanDiffs: %v\\n%s\", r, debug.Stack())\n\t\t\t\t\terrCh <- fmt.Errorf(\"panic in GetPlanDiffs: %v\\n%s\", r, debug.Stack())\n\t\t\t\t\truntime.Goexit() // don't allow outer function to continue and double-send to channel\n\t\t\t\t}\n\t\t\t}()","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/db/diff_helpers.go#L22-L58","documentation":"This error wraps a failure from initGitRepo(tempDirPath), which runs `git init` in a freshly created temp directory while building plan diffs. GetPlanDiffs needs a scratch git repo to stage and commit the original file versions before writing the current versions and computing a diff. If `git init` (or any setup step inside initGitRepo) fails, the whole diff computation cannot proceed.","triggerScenarios":"GetPlanDiffs is called and initGitRepo fails: the git binary is missing from PATH, the temp dir (os.MkdirTemp result) was removed or is not writable, disk is full, or the underlying exec of `git init` returns non-zero for another reason.","commonSituations":"Server host without git installed or with a broken git install; org data directory (getOrgDir) on a read-only or full filesystem; misconfigured TMPDIR/permissions preventing directory use; restricted containers that strip git or /tmp space.","solutions":["Install git on the server host or fix PATH so `git init` is executable (verify with `git --version` as the server user).","Check filesystem permissions and free space on the org directory / temp dir; ensure the process user can write there.","Run `initGitRepo` logic manually against a scratch dir to see the underlying wrapped message and fix that root cause.","If the org dir is read-only, correct the getOrgDir configuration to a writable location."],"exampleFix":"// before (host missing git, fails at runtime)\nerr = initGitRepo(tempDirPath)\n// after (fail fast with a clear message at startup)\nif _, err := exec.LookPath(\"git\"); err != nil {\n    log.Fatalf(\"git binary not found in PATH: %v\", err)\n}","handlingStrategy":"validation","validationCode":"if _, err := exec.LookPath(\"git\"); err != nil {\n    return fmt.Errorf(\"git binary required but not found in PATH\")\n}\nif err := isWritableDir(getOrgDir(orgId)); err != nil {\n    return fmt.Errorf(\"org dir not writable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"out, err := someDiffCall()\nif err != nil && strings.Contains(err.Error(), \"error initializing git repo\") {\n    // check git availability / disk, then retry once\n    log.Printf(\"git init failed, checking environment: %v\", err)\n}","preventionTips":["Verify `git` is installed in every deployment image and reachable via PATH for the service user.","Monitor free disk space and inode usage on the volume hosting org data and temp dirs.","Run the service with a user that owns (or can write to) the org directory.","Smoke-test `git init` in a temp dir at service startup and fail fast."],"tags":["git","filesystem","environment"],"backgroundTag":"git-init-failed","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}