MCPcopy
hub / github.com/go-git/go-git / checkoutFileSymlink

Method checkoutFileSymlink

worktree.go:658–694  ·  view source on GitHub ↗
(f *object.File)

Source from the content-addressed store, hash-verified

656}
657
658func (w *Worktree) checkoutFileSymlink(f *object.File) (err error) {
659 // .gitmodules symlink rejection (and its NTFS / HFS variants) is
660 // enforced by the worktreeFilesystem wrapper's Symlink method via
661 // validSymlinkName. See https://github.com/git/git/commit/10ecfa7
662 // for the upstream rationale.
663
664 from, err := f.Reader()
665 if err != nil {
666 return
667 }
668
669 defer ioutil.CheckClose(from, &err)
670
671 bytes, err := io.ReadAll(from)
672 if err != nil {
673 return
674 }
675
676 err = w.Filesystem.Symlink(string(bytes), f.Name)
677
678 // On windows, this might fail.
679 // Follow Git on Windows behavior by writing the link as it is.
680 if err != nil && isSymlinkWindowsNonAdmin(err) {
681 mode, _ := f.Mode.ToOSFileMode()
682
683 to, err := w.Filesystem.OpenFile(f.Name, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, mode.Perm())
684 if err != nil {
685 return err
686 }
687
688 defer ioutil.CheckClose(to, &err)
689
690 _, err = to.Write(bytes)
691 return err
692 }
693 return
694}
695
696func (w *Worktree) addIndexFromTreeEntry(name string, f *object.TreeEntry, idx *indexBuilder) error {
697 idx.Remove(name)

Callers 1

checkoutFileMethod · 0.95

Calls 7

CheckCloseFunction · 0.92
ToOSFileModeMethod · 0.80
isSymlinkWindowsNonAdminFunction · 0.70
ReaderMethod · 0.65
SymlinkMethod · 0.45
OpenFileMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected