GoogleContainerTools/skaffold · error
failed to clone git repo: unable to create directory name: %
Error message
failed to clone git repo: unable to create directory name: %w
What it means
Thrown by syncRepo when getRepoDir(g) fails to compute the hashed cache directory name for the repo. getRepoDir hashes the repo URL/ref into a directory name, so failure indicates an internal hashing or configuration problem rather than a git issue. This is rare and usually points at malformed GitInfo input.
Source
Thrown at pkg/skaffold/git/gitutil.go:120
if err != nil {
return "", fmt.Errorf("failed to clone repo %s: %w", g.Repo, err)
}
if err := os.MkdirAll(skaffoldCacheDir, 0700); err != nil {
return "", fmt.Errorf(
"failed to clone repo %s: trouble creating cache directory: %w", g.Repo, err)
}
ref := g.Ref
if ref == "" {
ref, err = defaultRef(ctx, g.RepoCloneURI, g.Repo)
if err != nil {
return "", fmt.Errorf("failed to clone repo %s: trouble getting default branch: %w", g.Repo, err)
}
}
hash, err := getRepoDir(g)
if err != nil {
return "", fmt.Errorf("failed to clone git repo: unable to create directory name: %w", err)
}
repoCacheDir := filepath.Join(skaffoldCacheDir, hash)
if _, err := os.Stat(repoCacheDir); os.IsNotExist(err) {
if opts.SyncRemoteCache.CloneDisabled() {
return "", SyncDisabledErr(g, repoCacheDir)
}
if _, err := r.Run(ctx, "clone", g.RepoCloneURI, fmt.Sprintf("./%s", hash), "--branch", ref, "--depth", "1"); err != nil {
if strings.Contains(err.Error(), "Could not find remote branch") {
if _, err := r.Run(ctx, "clone", g.RepoCloneURI, fmt.Sprintf("./%s", hash), "--depth", "1"); err != nil {
return "", fmt.Errorf("failed to clone repo: %w", err)
}
r.Dir = repoCacheDir
if _, err := r.Run(ctx, "checkout", ref); err != nil {
if rmErr := os.RemoveAll(repoCacheDir); rmErr != nil {
err = fmt.Errorf("failed to remove repo cache dir: %w", rmErr)
}
View on GitHub (pinned to a1189de023)
Solutions
- Inspect the git sync config values (repo URL, ref, subDir) for typos, empty strings, or unexpected characters and correct them.
- Reproduce with a canonical repo URL to confirm whether the URL format is the problem.
- If inputs look valid, file/report a skaffold bug with the exact GitInfo values; this path is normally unreachable with well-formed config.
- Pin/upgrade to a skaffold version where getRepoDir handles your input correctly.
Example fix
// before
git.Sync{Repo: "", Ref: ""} // malformed GitInfo
// after
git.Sync{Repo: "https://github.com/org/repo", Ref: "main"} Defensive patterns
Strategy: validation
Validate before calling
function validateGitInfo(g) {
const errs = [];
if (!g || typeof g.repo !== 'string' || g.repo.length === 0) errs.push('repo required');
if (g.ref != null && typeof g.ref !== 'string') errs.push('ref must be string');
if (errs.length) throw new Error('invalid git config: ' + errs.join('; '));
} Type guard
function isValidGitInfo(g) {
return !!g && typeof g.repo === 'string' && g.repo.trim().length > 0 &&
(g.ref === undefined || typeof g.ref === 'string');
} Try / catch
try {
await syncRepo(g, ctx, opts);
} catch (err) {
if (/unable to create directory name/.test(err.message)) {
// log full GitInfo for bug report; not user-fixable at runtime
console.error('getRepoDir failed for GitInfo:', JSON.stringify(g));
}
throw err;
} Prevention
- Only pass well-formed repo URLs (https:// or git@host:path) into git sync config.
- Avoid exotic characters/control chars in repo and ref fields.
- Pin skaffold versions tested against your repo naming scheme.
- Validate config with skaffold config linting before runs.
When it happens
Trigger: getRepoDir(g) returns an error while computing the hash for the given GitInfo (unexpected repo/ref values fed to the hashing routine).
Common situations: Programmatic use of the skaffold git package with a malformed or empty GitInfo; unusual characters in the repo URL breaking the path derivation; upstream bug in getRepoDir's hashing of a specific repo/ref combination.
Related errors
- CONFIG_REMOTE_REPO_CACHE_NOT_FOUND_ERR
- failed to get default branch for repo %s
- failed to clone repo %s: %w
- %q is not a valid git tagger variant
- value must be one of `always`, `missing`, or `never`
AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05).
Data as JSON: /api/errors/6e9095e35e48c438.
Report an issue: GitHub.