(world, in string)
| 84 | } |
| 85 | |
| 86 | func gitWorkDir(world, in string) (string, error) { |
| 87 | if in == "" { |
| 88 | in = "." |
| 89 | } |
| 90 | if !filepath.IsLocal(in) { |
| 91 | return "", fmt.Errorf("--in must be a relative path inside the Git workspace") |
| 92 | } |
| 93 | root, err := filepath.EvalSymlinks(filepath.Join(world, "work")) |
| 94 | if err != nil { |
| 95 | return "", err |
| 96 | } |
| 97 | dir, err := filepath.EvalSymlinks(filepath.Join(root, in)) |
| 98 | if err != nil { |
| 99 | return "", fmt.Errorf("Git workspace %q: %w", in, err) |
| 100 | } |
| 101 | if !pathWithin(root, dir) { |
| 102 | return "", fmt.Errorf("Git workspace %q points outside the fixture", in) |
| 103 | } |
| 104 | info, err := os.Stat(dir) |
| 105 | if err != nil { |
| 106 | return "", err |
| 107 | } |
| 108 | if !info.IsDir() { |
| 109 | return "", fmt.Errorf("Git workspace %q is not a directory", in) |
| 110 | } |
| 111 | return dir, nil |
| 112 | } |
| 113 | |
| 114 | func pathWithin(root, path string) bool { |
| 115 | rel, err := filepath.Rel(root, path) |
no test coverage detected