MCPcopy Index your code
hub / github.com/go-git/go-git / dotGitToOSFilesystems

Function dotGitToOSFilesystems

repository.go:341–399  ·  view source on GitHub ↗
(path string, detect bool)

Source from the content-addressed store, hash-verified

339}
340
341func dotGitToOSFilesystems(path string, detect bool) (dot, wt billy.Filesystem, err error) {
342 path, err = path_util.ReplaceTildeWithHome(path)
343 if err != nil {
344 return nil, nil, err
345 }
346
347 if path, err = filepath.Abs(path); err != nil {
348 return nil, nil, err
349 }
350
351 var fs billy.Filesystem
352 var fi os.FileInfo
353 for {
354 fs = osfs.New(path)
355
356 pathinfo, err := fs.Stat("/")
357 if !os.IsNotExist(err) {
358 if pathinfo == nil {
359 return nil, nil, err
360 }
361 if !pathinfo.IsDir() && detect {
362 fs = osfs.New(filepath.Dir(path))
363 }
364 }
365
366 fi, err = fs.Stat(GitDirName)
367 if err == nil {
368 // no error; stop
369 break
370 }
371 if !os.IsNotExist(err) {
372 // unknown error; stop
373 return nil, nil, err
374 }
375 if detect {
376 // try its parent as long as we haven't reached
377 // the root dir
378 if dir := filepath.Dir(path); dir != path {
379 path = dir
380 continue
381 }
382 }
383 // not detecting via parent dirs and the dir does not exist;
384 // stop
385 return fs, nil, nil
386 }
387
388 if fi.IsDir() {
389 dot, err = fs.Chroot(GitDirName)
390 return dot, fs, err
391 }
392
393 dot, err = dotGitFileToOSFilesystem(path, fs)
394 if err != nil {
395 return nil, nil, err
396 }
397
398 return dot, fs, nil

Callers 2

PlainOpenWithOptionsFunction · 0.85

Calls 5

ReplaceTildeWithHomeFunction · 0.92
dotGitFileToOSFilesystemFunction · 0.85
StatMethod · 0.65
IsDirMethod · 0.65
ChrootMethod · 0.45

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…