MCPcopy Create free account
hub / github.com/cli/cli / gitWorkDir

Function gitWorkDir

script/ghmock/gitfixture.go:86–112  ·  view source on GitHub ↗
(world, in string)

Source from the content-addressed store, hash-verified

84}
85
86func 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
114func pathWithin(root, path string) bool {
115 rel, err := filepath.Rel(root, path)

Callers 3

runBinaryFunction · 0.85
snapshotGitMethod · 0.85
cmdGitFunction · 0.85

Calls 5

pathWithinFunction · 0.85
JoinMethod · 0.80
IsDirMethod · 0.80
IsLocalMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected