MCPcopy
hub / github.com/mislav/hub / HasFile

Function HasFile

git/git.go:79–105  ·  view source on GitHub ↗
(segments ...string)

Source from the content-addressed store, hash-verified

77}
78
79func HasFile(segments ...string) bool {
80 // The blessed way to resolve paths within git dir since Git 2.5.0
81 pathCmd := gitCmd("rev-parse", "-q", "--git-path", filepath.Join(segments...))
82 pathCmd.Stderr = nil
83 if output, err := pathCmd.Output(); err == nil {
84 if lines := outputLines(output); len(lines) == 1 {
85 if _, err := os.Stat(lines[0]); err == nil {
86 return true
87 }
88 }
89 }
90
91 // Fallback for older git versions
92 dir, err := Dir()
93 if err != nil {
94 return false
95 }
96
97 s := []string{dir}
98 s = append(s, segments...)
99 path := filepath.Join(s...)
100 if _, err := os.Stat(path); err == nil {
101 return true
102 }
103
104 return false
105}
106
107func Editor() (string, error) {
108 varCmd := gitCmd("var", "GIT_EDITOR")

Callers 4

syncFunction · 0.92
transformCheckoutArgsFunction · 0.92
RemoteForBranchMethod · 0.92

Calls 4

gitCmdFunction · 0.85
outputLinesFunction · 0.85
DirFunction · 0.85
OutputMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…