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

Function dotGitFileToOSFilesystem

repository.go:394–419  ·  view source on GitHub ↗
(path string, fs billy.Filesystem)

Source from the content-addressed store, hash-verified

392}
393
394func dotGitFileToOSFilesystem(path string, fs billy.Filesystem) (bfs billy.Filesystem, err error) {
395 f, err := fs.Open(GitDirName)
396 if err != nil {
397 return nil, err
398 }
399 defer ioutil.CheckClose(f, &err)
400
401 b, err := io.ReadAll(f)
402 if err != nil {
403 return nil, err
404 }
405
406 line := string(b)
407 const prefix = "gitdir: "
408 if !strings.HasPrefix(line, prefix) {
409 return nil, fmt.Errorf(".git file has no %s prefix", prefix)
410 }
411
412 gitdir := strings.Split(line[len(prefix):], "\n")[0]
413 gitdir = strings.TrimSpace(gitdir)
414 if filepath.IsAbs(gitdir) {
415 return osfs.New(gitdir), nil
416 }
417
418 return osfs.New(fs.Join(path, gitdir)), nil
419}
420
421func dotGitCommonDirectory(fs billy.Filesystem) (commonDir billy.Filesystem, err error) {
422 f, err := fs.Open("commondir")

Callers 1

dotGitToOSFilesystemsFunction · 0.85

Calls 3

CheckCloseFunction · 0.92
JoinMethod · 0.80
OpenMethod · 0.45

Tested by

no test coverage detected