{"record":{"id":"c835f04c6524701d","repo":"GoogleContainerTools/skaffold","slug":"failed-to-clone-repo-s-trouble-creating-cache-di","errorCode":null,"errorMessage":"failed to clone repo %s: trouble creating cache directory: %w","messagePattern":"failed to clone repo (.+?): trouble creating cache directory: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/git/gitutil.go","lineNumber":106,"sourceCode":"func getRepoDir(g Config) (string, error) {\n\tinputs := []string{g.Repo, g.Ref}\n\thasher := sha256.New()\n\tenc := json.NewEncoder(hasher)\n\tif err := enc.Encode(inputs); err != nil {\n\t\treturn \"\", err\n\t}\n\n\treturn base64.URLEncoding.EncodeToString(hasher.Sum(nil))[:32], nil\n}\n\nfunc syncRepo(ctx context.Context, g Config, opts config.SkaffoldOptions) (string, error) {\n\tskaffoldCacheDir, err := config.GetRemoteCacheDir(opts)\n\tr := gitCmd{Dir: skaffoldCacheDir}\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to clone repo %s: %w\", g.Repo, err)\n\t}\n\tif err := os.MkdirAll(skaffoldCacheDir, 0700); err != nil {\n\t\treturn \"\", fmt.Errorf(\n\t\t\t\"failed to clone repo %s: trouble creating cache directory: %w\", g.Repo, err)\n\t}\n\n\tref := g.Ref\n\tif ref == \"\" {\n\t\tref, err = defaultRef(ctx, g.RepoCloneURI, g.Repo)\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"failed to clone repo %s: trouble getting default branch: %w\", g.Repo, err)\n\t\t}\n\t}\n\n\thash, err := getRepoDir(g)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to clone git repo: unable to create directory name: %w\", err)\n\t}\n\trepoCacheDir := filepath.Join(skaffoldCacheDir, hash)\n\tif _, err := os.Stat(repoCacheDir); os.IsNotExist(err) {\n\t\tif opts.SyncRemoteCache.CloneDisabled() {","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/git/gitutil.go#L88-L124","documentation":"Thrown by syncRepo in pkg/skaffold/git when os.MkdirAll fails to create the local git cache directory (from config.GetRemoteCacheDir). syncRepo clones remote git repos into a shared cache dir before using them in builds; without a writable cache dir the clone cannot proceed. The underlying os error is wrapped via %w.","triggerScenarios":"os.MkdirAll(skaffoldCacheDir, 0700) returns an error: path not writable, parent missing and uncreatable, path exists as a file, or disk full.","commonSituations":"Running skaffold in a container/CI as a non-root user whose HOME is not writable; SKAFFOLD_REMOTE_CACHE_DIR or --remote-cache-dir pointing at a read-only mount or an existing regular file; read-only root filesystem in Kubernetes pods running skaffold.","solutions":["Fix permissions or choose a writable location: run as a user that owns the cache dir, or set --remote-cache-dir/SKAFFOLD_REMOTE_CACHE_DIR to a writable path.","Check whether the path exists as a regular file and remove it so a directory can be created.","Verify disk space (df -h) and that the parent directory exists and is writable.","If running in a container, mount an emptyDir/PV at the cache dir path with 0700 permissions."],"exampleFix":"// before\nskaffold run --remote-cache-dir /var/cache/skaffold   # read-only volume\n// after\nskaffold run --remote-cache-dir /tmp/skaffold-cache   # writable path","handlingStrategy":"validation","validationCode":"const cacheDir = process.env.SKAFFOLD_REMOTE_CACHE_DIR || path.join(os.homedir(), '.skaffold', 'gitcache');\nconst st = fs.statSync(path.dirname(cacheDir));\nif (!st.isDirectory()) throw new Error(`cache parent ${path.dirname(cacheDir)} is not a directory`);\nfs.accessSync(cacheDir in st ? cacheDir : path.dirname(cacheDir), fs.constants.W_OK); // will throw if not writable","typeGuard":"function isWritableDir(p) {\n  try { return fs.statSync(p).isDirectory() && (fs.accessSync(p, fs.constants.W_OK), true); }\n  catch { return false; }\n}","tryCatchPattern":"try {\n  await syncRepo(g, ctx, opts);\n} catch (err) {\n  if (/trouble creating cache directory/.test(err.message)) {\n    // fall back to a temp writable dir or abort with a clear message\n    console.error('Git cache dir not writable:', err.cause ?? err);\n  }\n  throw err;\n}","preventionTips":["Point SKAFFOLD_REMOTE_CACHE_DIR/--remote-cache-dir at a path guaranteed writable for the runtime user.","In containers, mount an RW volume (emptyDir) at the cache path instead of relying on HOME.","Never point the cache dir at an existing regular file.","Check df -h / permissions in CI before running skaffold pipelines."],"tags":["git","filesystem","permissions"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"a1189de023efc32d4b8e11f395acc678aa555011","analyzedAt":"2026-09-05T12:09:27.064Z","contentChangedAt":"2026-09-05T12:09:27.064Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}