MCPcopy Create free account
hub / github.com/go-git/go-git / validPath

Function validPath

worktree.go:428–457  ·  view source on GitHub ↗

validPath checks whether paths are valid. The rules around invalid paths could differ from upstream based on how filesystems are managed within go-git, but they are largely the same. For upstream rules: https://github.com/git/git/blob/564d0252ca632e0264ed670534a51d18a689ef5d/read-cache.c#L946 https

(paths ...string)

Source from the content-addressed store, hash-verified

426// https://github.com/git/git/blob/564d0252ca632e0264ed670534a51d18a689ef5d/read-cache.c#L946
427// https://github.com/git/git/blob/564d0252ca632e0264ed670534a51d18a689ef5d/path.c#L1383
428func validPath(paths ...string) error {
429 for _, p := range paths {
430 parts := strings.FieldsFunc(p, func(r rune) bool { return (r == '\\' || r == '/') })
431 if len(parts) == 0 {
432 return fmt.Errorf("invalid path: %q", p)
433 }
434
435 if _, denied := worktreeDeny[strings.ToLower(parts[0])]; denied {
436 return fmt.Errorf("invalid path prefix: %q", p)
437 }
438
439 if runtime.GOOS == "windows" {
440 // Volume names are not supported, in both formats: \\ and <DRIVE_LETTER>:.
441 if vol := filepath.VolumeName(p); vol != "" {
442 return fmt.Errorf("invalid path: %q", p)
443 }
444
445 if !windowsValidPath(parts[0]) {
446 return fmt.Errorf("invalid path: %q", p)
447 }
448 }
449
450 for _, part := range parts {
451 if part == ".." {
452 return fmt.Errorf("invalid path %q: cannot use '..'", p)
453 }
454 }
455 }
456 return nil
457}
458
459// windowsPathReplacer defines the chars that need to be replaced
460// as part of windowsValidPath.

Callers 2

validChangeMethod · 0.85
TestValidPathFunction · 0.85

Calls 1

windowsValidPathFunction · 0.85

Tested by 1

TestValidPathFunction · 0.68