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

Function dotGitToOSFilesystems

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

Source from the content-addressed store, hash-verified

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

Callers 2

PlainOpenWithOptionsFunction · 0.85

Calls 5

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

Tested by 1